|
| 1 | +# Publish on a version tag: |
| 2 | +# 1. NuGet.org via Trusted Publishing (OIDC) — no stored API key. |
| 3 | +# 2. GitHub Packages (uses the built-in GITHUB_TOKEN). |
| 4 | +# 3. A GitHub Release with the .nupkg file attached and auto-generated, |
| 5 | +# label-categorized release notes (see .github/release.yml). |
| 6 | +# |
| 7 | +# HAND-WRITTEN, documented exception: Fallout owns .github/workflows/build.yml |
| 8 | +# (generated from the [GitHubActions] attribute — never hand-edit it), but the |
| 9 | +# publish flow (OIDC trusted publishing + GitHub Packages + Release) is not |
| 10 | +# expressible via the pinned Fallout 10.3.49 attribute API, so this workflow is |
| 11 | +# maintained by hand. See CLAUDE.md. |
| 12 | +# |
| 13 | +# One-time nuget.org setup: a Trusted Publisher policy for the package |
| 14 | +# (Scrutor.Extensions.HttpClient): owner Chrison-dev, repo |
| 15 | +# Scrutor.Extensions.HttpClient, workflow publish.yml, environment nuget.org. |
| 16 | +# Repo variable NUGET_USER = your nuget.org username. |
| 17 | +# |
| 18 | +# Triggered by pushing a version tag, e.g. `git tag v5.1.0 && git push origin v5.1.0`. |
| 19 | +name: publish |
| 20 | + |
| 21 | +on: |
| 22 | + push: |
| 23 | + tags: ['v*'] |
| 24 | + workflow_dispatch: |
| 25 | + |
| 26 | +permissions: |
| 27 | + id-token: write # OIDC trusted publishing (nuget.org) |
| 28 | + contents: write # create the GitHub Release |
| 29 | + packages: write # push to GitHub Packages |
| 30 | + |
| 31 | +jobs: |
| 32 | + publish: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + environment: nuget.org |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v4 |
| 37 | + with: |
| 38 | + fetch-depth: 0 # GitVersion needs full history |
| 39 | + |
| 40 | + - uses: actions/setup-dotnet@v4 |
| 41 | + with: |
| 42 | + global-json-file: global.json |
| 43 | + |
| 44 | + - name: 'Restore: dotnet tools' |
| 45 | + run: dotnet tool restore |
| 46 | + |
| 47 | + - name: 'Pack' |
| 48 | + run: dotnet run --project build/_build.csproj -- Pack |
| 49 | + |
| 50 | + - name: 'NuGet.org: trusted-publishing login (OIDC → short-lived key)' |
| 51 | + uses: NuGet/login@v1 |
| 52 | + id: login |
| 53 | + with: |
| 54 | + user: ${{ vars.NUGET_USER }} |
| 55 | + |
| 56 | + - name: 'NuGet.org: push' |
| 57 | + run: > |
| 58 | + dotnet nuget push "artifacts/packages/*.nupkg" |
| 59 | + --source https://api.nuget.org/v3/index.json |
| 60 | + --api-key ${{ steps.login.outputs.NUGET_API_KEY }} |
| 61 | + --skip-duplicate |
| 62 | +
|
| 63 | + - name: 'GitHub Packages: push' |
| 64 | + run: > |
| 65 | + dotnet nuget push "artifacts/packages/*.nupkg" |
| 66 | + --source https://nuget.pkg.github.com/Chrison-dev/index.json |
| 67 | + --api-key ${{ secrets.GITHUB_TOKEN }} |
| 68 | + --skip-duplicate |
| 69 | +
|
| 70 | + - name: 'GitHub Release: create with packages + generated notes' |
| 71 | + if: startsWith(github.ref, 'refs/tags/') |
| 72 | + uses: softprops/action-gh-release@v2 |
| 73 | + with: |
| 74 | + files: artifacts/packages/*.nupkg |
| 75 | + generate_release_notes: true |
0 commit comments