From 1a16ed1683dbc70fdb91238c2742837d9d3a372d Mon Sep 17 00:00:00 2001 From: Bruno Brito Date: Tue, 17 Nov 2026 21:41:03 -0300 Subject: [PATCH] ci: publish to NuGet with trusted publishing nuget.org API keys expire and the org key already did, which made the last releases fail with 403. Publish with NuGet/login (OIDC) instead: the job gets a short-lived key from the trusted publishing policy for this repository and workflow file. Also adds a workflow_dispatch input to publish an existing release tag again, since re-running the job skips the push once the release exists. --- .github/workflows/dotnet.yml | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 700d431..1bc1638 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -2,11 +2,22 @@ name: NetDevPack Brasil - MASTER Deploy on: push: branches: [ master ] + workflow_dispatch: + inputs: + version: + description: Existing release to publish again (e.g. 2.0.0). Builds tag v and pushes it to nuget.org. + required: true env: REPOSITORY_URL: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json CURRENT_REPO_URL: https://github.com/${{ github.repository }} +permissions: + contents: write + issues: write + pull-requests: write + id-token: write # NuGet trusted publishing (OIDC) + jobs: publish: runs-on: ubuntu-latest @@ -14,6 +25,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + ref: ${{ inputs.version && format('v{0}', inputs.version) || github.sha }} - name: Setup .NET 8 uses: actions/setup-dotnet@v4 @@ -41,6 +54,7 @@ jobs: - name: Semantic Release id: semantic + if: github.event_name == 'push' uses: cycjimmy/semantic-release-action@v4 with: extra_plugins: | @@ -49,8 +63,26 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Resolve version + id: version + if: github.event_name == 'workflow_dispatch' || steps.semantic.outputs.new_release_published == 'true' + env: + VERSION: ${{ inputs.version || steps.semantic.outputs.new_release_version }} + run: | + [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]] || { echo "::error::Invalid version '$VERSION'"; exit 1; } + echo "value=$VERSION" >> "$GITHUB_OUTPUT" + - name: Generate Package - run: dotnet pack -c Release -o out -p:PackageVersion=${{ steps.semantic.outputs.new_release_version }} -p:RepositoryUrl=${{env.CURRENT_REPO_URL}} + if: steps.version.outputs.value != '' + run: dotnet pack -c Release -o out -p:PackageVersion=${{ steps.version.outputs.value }} -p:RepositoryUrl=${{env.CURRENT_REPO_URL}} + + - name: NuGet login (trusted publishing) + id: nuget + if: steps.version.outputs.value != '' + uses: NuGet/login@v1 + with: + user: ${{ vars.NUGET_USER }} - name: Publish the package to nuget.org - run: dotnet nuget push ./out/*.nupkg -n -d -k ${{ secrets.NUGET_AUTH_TOKEN}} -s https://api.nuget.org/v3/index.json + if: steps.version.outputs.value != '' + run: dotnet nuget push ./out/*.nupkg --skip-duplicate -n -d -k ${{ steps.nuget.outputs.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json