From e3e8cac6dfc64bdcbc0a52bf99ca521e229db782 Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Wed, 11 Nov 2026 13:28:28 -0800 Subject: [PATCH] ci(nuget): port trusted publishing to main The main workflow still uses the stored NuGet API key. Port the v5-dev workflow to use a temporary credential from GitHub OIDC. Allow manual publishing from an existing release tag. Verify its package version, stop on failures, and skip packages already uploaded. Port 914f88b24, which published both v5.3.9 packages successfully. --- .github/workflows/publish-nuget.yml | 55 +++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-nuget.yml b/.github/workflows/publish-nuget.yml index 2ea6e532d0..96acfe3c2a 100644 --- a/.github/workflows/publish-nuget.yml +++ b/.github/workflows/publish-nuget.yml @@ -3,32 +3,75 @@ name: Publish NuGet Packages on: release: types: [published] + workflow_dispatch: + inputs: + tag: + description: Existing release tag to publish (for example, v5.3.9) + required: true + type: string permissions: contents: read +concurrency: + group: publish-nuget-${{ inputs.tag || github.event.release.tag_name }} + cancel-in-progress: false + jobs: package-nuget: runs-on: windows-latest - if: ${{ github.repository == 'twbs/bootstrap' && startsWith(github.event.release.tag_name, 'v') }} + if: ${{ github.repository == 'twbs/bootstrap' && startsWith(inputs.tag || github.event.release.tag_name, 'v') }} + permissions: + contents: read + id-token: write env: - GITHUB_REF_NAME: ${{ github.ref_name }} + RELEASE_TAG: ${{ inputs.tag || github.event.release.tag_name }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: + ref: refs/tags/${{ env.RELEASE_TAG }} persist-credentials: false + - name: Verify release version + id: package + shell: pwsh + run: | + $package = Get-Content package.json -Raw | ConvertFrom-Json + if ($package.name -ne 'bootstrap' -or $env:RELEASE_TAG -cne "v$($package.version)") { + throw "Release $env:RELEASE_TAG does not match $($package.name)@$($package.version)" + } + "version=$($package.version)" >> $env:GITHUB_OUTPUT + - name: Set up NuGet uses: nuget/setup-nuget@fd55a6f3b34392fa83fde1454582407d8c714123 # v4.0 with: - nuget-api-key: ${{ secrets.NuGetAPIKey }} nuget-version: '5.x' - name: Pack NuGet packages shell: pwsh + env: + PACKAGE_VERSION: ${{ steps.package.outputs.version }} run: | - $bsversion = $env:GITHUB_REF_NAME.Substring(1) + $bsversion = $env:PACKAGE_VERSION nuget pack "nuget\bootstrap.nuspec" -Verbosity detailed -NonInteractive -BasePath . -Version $bsversion + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } nuget pack "nuget\bootstrap.sass.nuspec" -Verbosity detailed -NonInteractive -BasePath . -Version $bsversion - nuget push "bootstrap.$bsversion.nupkg" -Verbosity detailed -NonInteractive -Source "https://api.nuget.org/v3/index.json" - nuget push "bootstrap.sass.$bsversion.nupkg" -Verbosity detailed -NonInteractive -Source "https://api.nuget.org/v3/index.json" + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + - name: Log in to NuGet with trusted publishing + id: login + uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1 + with: + user: mdo + + - name: Publish NuGet packages + shell: pwsh + env: + PACKAGE_VERSION: ${{ steps.package.outputs.version }} + NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }} + run: | + $bsversion = $env:PACKAGE_VERSION + nuget push "bootstrap.$bsversion.nupkg" -Verbosity detailed -NonInteractive -Source "https://api.nuget.org/v3/index.json" -ApiKey $env:NUGET_API_KEY -SkipDuplicate + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + nuget push "bootstrap.sass.$bsversion.nupkg" -Verbosity detailed -NonInteractive -Source "https://api.nuget.org/v3/index.json" -ApiKey $env:NUGET_API_KEY -SkipDuplicate + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }