From 8719c2991e1874d43f167d829540af4a96ffcec1 Mon Sep 17 00:00:00 2001 From: Stefan Seeland <168659+stesee@users.noreply.github.com> Date: Tue, 17 Nov 2026 19:12:48 +0100 Subject: [PATCH] Use matrix builds and NuGet trusted publishing Build and test independently on Linux, macOS, and Windows. Publish the Linux-built package using OIDC for NuGet and NuGet Test, and create GitHub releases targeting the triggering commit. --- .github/workflows/dotnet.yml | 159 +++++++++++++++++------------------ 1 file changed, 77 insertions(+), 82 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index e430717..29b0e48 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -6,101 +6,96 @@ env: on: push: paths-ignore: - - '*.md' + - '**.md' jobs: build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7 - - name: Setup .NET - uses: actions/setup-dotnet@v6 - with: - dotnet-version: | - 10.0.x - - name: Check formatting - run: dotnet format --verify-no-changes - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore - - name: Test on Ubuntu (no build) - run: dotnet test --no-build --verbosity normal --configuration Release - - name: Upload build artifacts - uses: actions/upload-artifact@v7 - with: - name: release-artifacts - path: SanitizeFilename/bin/Release/ - retention-days: 1 - - name: Upload test artifacts - uses: actions/upload-artifact@v7 - with: - name: test-artifacts - path: SanitizeFilenameTests/bin/Release/ - retention-days: 1 - - test: - needs: build runs-on: ${{ matrix.os }} strategy: - fail-fast: false matrix: - os: - - windows-latest - - macos-latest + os: [ubuntu-latest, macos-latest, windows-latest] steps: - - uses: actions/checkout@v7 - - name: Setup .NET - uses: actions/setup-dotnet@v6 - with: - dotnet-version: | - 10.0.x - - name: Restore dependencies - run: dotnet restore - - name: Download build artifacts - uses: actions/download-artifact@v8 - with: - name: test-artifacts - path: SanitizeFilenameTests/bin/Release/ - - name: Test (no build) - run: dotnet test --no-build --verbosity normal --configuration Release + - uses: actions/checkout@v7 + - name: Setup .NET + uses: actions/setup-dotnet@v6 + with: + dotnet-version: | + 10.0.x + - name: Check formatting + run: dotnet format --verify-no-changes + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal --configuration Release + + - name: Upload NuGet package + if: runner.os == 'Linux' + uses: actions/upload-artifact@v7 + with: + name: nuget-package + path: ./SanitizeFilename/bin/Release/*.*nupkg + if-no-files-found: error + retention-days: 7 deployRelease: if: startsWith(github.ref, 'refs/heads/release') + needs: build runs-on: ubuntu-latest - needs: [build, test] + permissions: + contents: write # gh release create + id-token: write # NuGet Trusted Publishing (OIDC) steps: - - uses: actions/download-artifact@v8 - with: - name: release-artifacts - path: SanitizeFilename/bin/Release/ - - name: NugetPush - env: - NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TOKEN }} - if: env.NUGET_TOKEN_EXISTS != '' - run: | - dotnet nuget push ./SanitizeFilename/bin/Release/*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_TOKEN}} --source https://api.nuget.org/v3/index.json - - name: Github release - shell: bash - env: - GITHUB_TOKEN: ${{ github.TOKEN }} - if: env.GITHUB_TOKEN != '' - run: | - gh release create ${{env.CURRENT_VERSION}} ./SanitizeFilename/bin/Release/*.*nupkg --generate-notes + - name: Setup .NET + uses: actions/setup-dotnet@v6 + with: + dotnet-version: | + 10.0.x + - name: Download NuGet package + uses: actions/download-artifact@v8 + with: + name: nuget-package + path: ./nuget + - name: NuGet login (Trusted Publishing) + uses: NuGet/login@v1 + id: nugetLogin + with: + user: ${{ secrets.NUGET_USER }} + - name: NugetPush + run: | + dotnet nuget push ./nuget/*.nupkg --skip-duplicate --api-key ${{ steps.nugetLogin.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json + - name: Github release + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create ${{ env.CURRENT_VERSION }} ./nuget/*.*nupkg --repo ${{ github.repository }} --target ${{ github.sha }} --generate-notes deployTest: - if: github.ref == 'refs/heads/main' + if: ${{ github.ref == 'refs/heads/main' }} + needs: build runs-on: ubuntu-latest - needs: [build, test] + permissions: + id-token: write # NuGet Trusted Publishing (OIDC) steps: - - uses: actions/download-artifact@v8 - with: - name: release-artifacts - path: SanitizeFilename/bin/Release/ - - name: NugetPush - env: - NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TEST_TOKEN }} - if: env.NUGET_TOKEN_EXISTS != '' - run: | - ls ./SanitizeFilename/bin/Release - dotnet nuget push ./SanitizeFilename/bin/Release/*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_TEST_TOKEN}} --source https://apiint.nugettest.org/v3/index.json + - name: Setup .NET + uses: actions/setup-dotnet@v6 + with: + dotnet-version: | + 10.0.x + - name: Download NuGet package + uses: actions/download-artifact@v8 + with: + name: nuget-package + path: ./nuget + - name: NuGet login (Trusted Publishing) + uses: NuGet/login@v1 + id: nugetLogin + with: + user: ${{ secrets.NUGET_TEST_USER }} + token-service-url: https://int.nugettest.org/api/v2/token + audience: https://int.nugettest.org + - name: NugetPush + run: | + dotnet nuget push ./nuget/*.nupkg --skip-duplicate --api-key ${{ steps.nugetLogin.outputs.NUGET_API_KEY }} --source https://apiint.nugettest.org/v3/index.json