|
| 1 | +# Publish LabEquipmentController to nuget.org using Trusted Publishing. |
| 2 | +# |
| 3 | +# No API key is stored anywhere. GitHub issues a short-lived, signed OIDC token describing |
| 4 | +# this repository and this workflow file; nuget.org validates it against a policy you |
| 5 | +# registered, and hands back an API key that lives for one hour. Nothing to rotate, nothing |
| 6 | +# to leak. |
| 7 | +# |
| 8 | +# ─── One-time setup on nuget.org ──────────────────────────────────────────────────────── |
| 9 | +# Sign in → your username → Trusted Publishing → add a policy: |
| 10 | +# Repository Owner : EECSB |
| 11 | +# Repository : LabEquipmentController |
| 12 | +# Workflow File : publish-nuget.yml (file name only, no path) |
| 13 | +# Environment : (leave empty — this workflow declares none) |
| 14 | +# |
| 15 | +# ─── One-time setup on GitHub ─────────────────────────────────────────────────────────── |
| 16 | +# Settings → Secrets and variables → Actions → New repository secret: |
| 17 | +# NUGET_USER = your nuget.org username (the profile name, NOT your email address) |
| 18 | +# |
| 19 | +# The policy is keyed to this file's NAME. Renaming this file breaks publishing until the |
| 20 | +# policy is updated to match. |
| 21 | +# |
| 22 | +# A policy on a private repository starts out "temporarily active" for 7 days and becomes |
| 23 | +# permanent on the first successful publish — nuget.org needs the repository and owner IDs, |
| 24 | +# which only arrive inside a real token, to pin the policy against someone deleting the |
| 25 | +# repo and recreating it under the same name. |
| 26 | +name: Publish to NuGet |
| 27 | + |
| 28 | +# Manual only, on purpose. There is deliberately NO `release:` trigger: this library and |
| 29 | +# the desktop app version independently, so a GitHub release tagged v1.1.0 for the app |
| 30 | +# would otherwise publish version 1.1.0 of the library — permanently, since a version on |
| 31 | +# nuget.org can never be reused or deleted — without anyone having decided to. |
| 32 | +# |
| 33 | +# An approval gate via a GitHub Environment would be the alternative, but required |
| 34 | +# reviewers are a paid feature on private repositories and this one is private. Typing the |
| 35 | +# version by hand is the gate. |
| 36 | +on: |
| 37 | + workflow_dispatch: |
| 38 | + inputs: |
| 39 | + version: |
| 40 | + description: 'Version to publish, e.g. 1.0.0-beta.3. Leave empty to use the version in the csproj.' |
| 41 | + required: false |
| 42 | + type: string |
| 43 | + |
| 44 | +permissions: |
| 45 | + contents: read |
| 46 | + |
| 47 | +jobs: |
| 48 | + publish: |
| 49 | + runs-on: ubuntu-latest |
| 50 | + permissions: |
| 51 | + id-token: write # lets this job ask GitHub for the OIDC token |
| 52 | + contents: read |
| 53 | + |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v7 |
| 56 | + |
| 57 | + - uses: actions/setup-dotnet@v6 |
| 58 | + with: |
| 59 | + dotnet-version: '10.0.x' |
| 60 | + |
| 61 | + # The version typed into the dispatch form wins; left empty, the csproj's own version |
| 62 | + # is used, which is the one CI has been packing all along. |
| 63 | + - name: Work out the version |
| 64 | + id: version |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + version="${{ github.event.inputs.version }}" |
| 68 | + echo "value=$version" >> "$GITHUB_OUTPUT" |
| 69 | + echo "Publishing version: ${version:-(the version in the csproj)}" |
| 70 | +
|
| 71 | + # Never publish something that does not pass its own tests. A package cannot be |
| 72 | + # unpublished from nuget.org, only delisted. |
| 73 | + - name: Test |
| 74 | + run: dotnet test Tests/LabEquipmentController.Tests.csproj -c Release |
| 75 | + |
| 76 | + - name: Pack |
| 77 | + run: | |
| 78 | + if [ -n "${{ steps.version.outputs.value }}" ]; then |
| 79 | + dotnet pack Core/LabEquipmentController.Core.csproj -c Release -o artifacts \ |
| 80 | + -p:Version=${{ steps.version.outputs.value }} |
| 81 | + else |
| 82 | + dotnet pack Core/LabEquipmentController.Core.csproj -c Release -o artifacts |
| 83 | + fi |
| 84 | + ls -l artifacts |
| 85 | + shell: bash |
| 86 | + |
| 87 | + # The temporary key is valid for one hour and each token buys exactly one key, so |
| 88 | + # this sits as late as possible — immediately before the push. |
| 89 | + - name: NuGet login (OIDC → short-lived API key) |
| 90 | + uses: NuGet/login@v1 |
| 91 | + id: login |
| 92 | + with: |
| 93 | + user: ${{ secrets.NUGET_USER }} |
| 94 | + |
| 95 | + - name: Push |
| 96 | + run: | |
| 97 | + dotnet nuget push "artifacts/*.nupkg" \ |
| 98 | + --api-key ${{ steps.login.outputs.NUGET_API_KEY }} \ |
| 99 | + --source https://api.nuget.org/v3/index.json \ |
| 100 | + --skip-duplicate |
| 101 | + shell: bash |
| 102 | + |
| 103 | + # The symbols package is pushed the same way; without it a consumer's stack trace |
| 104 | + # stops at the assembly boundary. |
| 105 | + - name: Push symbols |
| 106 | + continue-on-error: true |
| 107 | + run: | |
| 108 | + dotnet nuget push "artifacts/*.snupkg" \ |
| 109 | + --api-key ${{ steps.login.outputs.NUGET_API_KEY }} \ |
| 110 | + --source https://api.nuget.org/v3/index.json \ |
| 111 | + --skip-duplicate |
| 112 | + shell: bash |
| 113 | + |
| 114 | + - uses: actions/upload-artifact@v7 |
| 115 | + with: |
| 116 | + name: published-nupkg |
| 117 | + path: artifacts/*.*nupkg |
| 118 | + if-no-files-found: error |
0 commit comments