ci: add Publish NuGet Package workflow (mirrors framework) #190
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [ main, release/v** ] | |
| pull_request: | |
| branches: [ main ] | |
| permissions: | |
| contents: read | |
| checks: write | |
| pull-requests: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: '10.0.x' | |
| - name: Cache NuGet packages | |
| uses: actions/cache@v5 | |
| with: | |
| path: ~/.nuget/packages | |
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/Directory.Packages.props') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nuget- | |
| - name: Setup versioning | |
| run: | | |
| dotnet tool install --global nbgv | |
| nbgv cloud | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build | |
| run: dotnet build --no-restore -c Release | |
| - name: Test with Coverage | |
| # --coverage: Native MTP coverage (requires Microsoft.Testing.Extensions.CodeCoverage) | |
| # --report-trx: Native MTP TRX generation (requires Microsoft.Testing.Extensions.TrxReport) | |
| # --results-directory is a VSTest-only flag that forces the VSTest code path, breaking MTP flags. | |
| # MTP writes TRX to TestResults/ relative to each test project directory; coverage path is set explicitly via --coverage-output. | |
| run: | | |
| dotnet test --no-build -c Release \ | |
| --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml \ | |
| --report-trx | |
| - name: Publish Test Results | |
| uses: EnricoMi/publish-unit-test-result-action@v2 | |
| if: always() | |
| with: | |
| files: | | |
| **/TestResults/**/*.trx | |
| - name: Upload Coverage to Codecov | |
| uses: codecov/codecov-action@v5 | |
| if: always() | |
| with: | |
| # MTP writes coverage relative to each test project; search recursively | |
| files: ./**/*.cobertura.xml | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| fail_ci_if_error: false | |
| - name: Pack | |
| if: ${{ success() && !github.base_ref }} | |
| run: dotnet pack --no-build --verbosity normal -c Release -o artifacts/ | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v6 | |
| if: ${{ success() && !github.base_ref }} | |
| with: | |
| name: artifact | |
| path: artifacts/ |