# Test changes locally with https://github.com/nektos/act
name: dotnet-release

# TODO
# - Allow workflows to be driven by the project(s)

on:
  push:
    branches: [main, develop]
    paths-ignore:
      - '.github/**/*.*'
      - '**/*.md'
      - '**/*.txt'

jobs:
  ci:
    name: CI # run test.yml. If it fails, this job fails.
    uses: ./dotnet/.github/workflows/ci.yml # <- your CI workflow here. Example: 'file://./ci.yml'
  release:
    needs: [ci] # start 'release' if 'ci' completes successfully
    runs-on: ubuntu-latest
    permissions:
      contents: write
      issues: write
      pull-requests: write
    steps:
      ################
      # SETUP
      ################
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0 # Required by GitVersion, Semantic Release
          submodules: 'recursive' # submodule fetch depth unknown
      - uses: actions/setup-dotnet@v6.0.0

      - run: corepack enable # enable corepack before setup-node
      - name: Setup Node
        uses: actions/setup-node@v7
        with:
          node-version-file: .nvmrc
      - run: corepack enable # enable corepack AFTER setup-node
      - name: Setup Node Cache
        uses: actions/setup-node@v7
        with:
          node-version-file: .nvmrc
          cache: yarn
      - run: corepack enable # Assure it's enabled

      - run: yarn install --immutable # Required by Semantic Release

      ################
      # RELEASE
      # @semantic-release/exec should be configured to execute
      # `dotnet publish`, `dotnet pack`, and `dotnet nuget push`
      # You can use this package's semanticReleaseConfigDotnet exports to do so.
      ################
      # https://github.com/semantic-release/semantic-release
      - name: Semantic Release
        run: yarn exec semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NUGET_TOKEN: ${{ secrets.NUGET_TOKEN }}
