|
| 1 | +name: Release |
| 2 | + |
| 3 | +# A tag vX.Y.Z publishes the 7 NuGet packages, the two container images and the GitHub Release (spec 009, AC-5). |
| 4 | +# Nothing is published unless the CI is green on the tagged commit, and the `release` environment asks a maintainer |
| 5 | +# to approve the publication. |
| 6 | +on: |
| 7 | + push: |
| 8 | + tags: ['v*'] |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: release-${{ github.ref }} |
| 15 | + cancel-in-progress: false |
| 16 | + |
| 17 | +env: |
| 18 | + DOTNET_NOLOGO: true |
| 19 | + DOTNET_CLI_TELEMETRY_OPTOUT: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + ci: |
| 23 | + name: CI |
| 24 | + uses: ./.github/workflows/ci.yml |
| 25 | + |
| 26 | + packages: |
| 27 | + name: NuGet packages |
| 28 | + needs: ci |
| 29 | + runs-on: ubuntu-latest |
| 30 | + environment: release |
| 31 | + permissions: |
| 32 | + contents: read |
| 33 | + id-token: write # NuGet trusted publishing (D-170) |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v7 |
| 36 | + with: |
| 37 | + fetch-depth: 0 |
| 38 | + |
| 39 | + - uses: actions/setup-dotnet@v6 |
| 40 | + with: |
| 41 | + global-json-file: global.json |
| 42 | + |
| 43 | + # Packing in Release embeds the Vue panel in PythonScriptRunner.Dashboard (D-155). |
| 44 | + - uses: actions/setup-node@v7 |
| 45 | + with: |
| 46 | + node-version-file: panel/.nvmrc |
| 47 | + cache: npm |
| 48 | + cache-dependency-path: panel/package-lock.json |
| 49 | + |
| 50 | + - name: Pack |
| 51 | + run: dotnet pack PythonScriptRunner.slnx --configuration Release --output artifacts/packages |
| 52 | + |
| 53 | + - name: Check the version |
| 54 | + run: | |
| 55 | + expected="${GITHUB_REF_NAME#v}" |
| 56 | + for package in artifacts/packages/*.nupkg; do |
| 57 | + case "$package" in |
| 58 | + *".$expected.nupkg") ;; |
| 59 | + *) echo "$package does not have version $expected"; exit 1 ;; |
| 60 | + esac |
| 61 | + done |
| 62 | + test "$(ls artifacts/packages/*.nupkg | wc -l)" -eq 7 |
| 63 | +
|
| 64 | + - name: Log in to NuGet |
| 65 | + id: nuget |
| 66 | + uses: NuGet/login@v1 |
| 67 | + with: |
| 68 | + user: ${{ vars.NUGET_USER }} |
| 69 | + |
| 70 | + # The symbol packages (.snupkg) next to each .nupkg are pushed with it. |
| 71 | + - name: Push |
| 72 | + run: >- |
| 73 | + dotnet nuget push "artifacts/packages/*.nupkg" |
| 74 | + --api-key "${{ steps.nuget.outputs.NUGET_API_KEY }}" |
| 75 | + --source https://api.nuget.org/v3/index.json |
| 76 | + --skip-duplicate |
| 77 | +
|
| 78 | + - uses: actions/upload-artifact@v7 |
| 79 | + with: |
| 80 | + name: packages |
| 81 | + path: artifacts/packages/ |
| 82 | + |
| 83 | + images: |
| 84 | + name: Container images (${{ matrix.image }}) |
| 85 | + needs: ci |
| 86 | + runs-on: ubuntu-latest |
| 87 | + environment: release |
| 88 | + permissions: |
| 89 | + contents: read |
| 90 | + packages: write |
| 91 | + strategy: |
| 92 | + matrix: |
| 93 | + include: |
| 94 | + - image: psr-worker |
| 95 | + dockerfile: hosts/PythonScriptRunner.WorkerHost/Dockerfile |
| 96 | + - image: psr-dashboard |
| 97 | + dockerfile: hosts/PythonScriptRunner.DashboardHost/Dockerfile |
| 98 | + steps: |
| 99 | + - uses: actions/checkout@v7 |
| 100 | + |
| 101 | + # The build stages compile on the runner's platform; only the final stage runs for arm64 (emulated). |
| 102 | + - uses: docker/setup-qemu-action@v4 |
| 103 | + |
| 104 | + - uses: docker/setup-buildx-action@v4 |
| 105 | + |
| 106 | + - uses: docker/login-action@v4 |
| 107 | + with: |
| 108 | + registry: ghcr.io |
| 109 | + username: ${{ github.actor }} |
| 110 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + |
| 112 | + - id: meta |
| 113 | + uses: docker/metadata-action@v6 |
| 114 | + with: |
| 115 | + images: ghcr.io/scriptrunnerkit/${{ matrix.image }} |
| 116 | + tags: | |
| 117 | + type=semver,pattern={{version}} |
| 118 | + type=semver,pattern={{major}}.{{minor}},enable=${{ !contains(github.ref_name, '-') }} |
| 119 | + type=raw,value=latest,enable=${{ !contains(github.ref_name, '-') }} |
| 120 | +
|
| 121 | + - uses: docker/build-push-action@v7 |
| 122 | + with: |
| 123 | + context: . |
| 124 | + file: ${{ matrix.dockerfile }} |
| 125 | + platforms: linux/amd64,linux/arm64 |
| 126 | + push: true |
| 127 | + tags: ${{ steps.meta.outputs.tags }} |
| 128 | + labels: ${{ steps.meta.outputs.labels }} |
| 129 | + build-args: VERSION=${{ steps.meta.outputs.version }} |
| 130 | + sbom: true |
| 131 | + provenance: mode=max |
| 132 | + cache-from: type=gha,scope=release-${{ matrix.image }} |
| 133 | + cache-to: type=gha,scope=release-${{ matrix.image }},mode=max |
| 134 | + |
| 135 | + github-release: |
| 136 | + name: GitHub Release |
| 137 | + needs: [packages, images] |
| 138 | + runs-on: ubuntu-latest |
| 139 | + permissions: |
| 140 | + contents: write |
| 141 | + steps: |
| 142 | + - uses: actions/checkout@v7 |
| 143 | + |
| 144 | + - uses: actions/download-artifact@v8 |
| 145 | + with: |
| 146 | + name: packages |
| 147 | + path: artifacts/packages |
| 148 | + |
| 149 | + # The notes are the CHANGELOG section of the version, which also carries the compatibility matrix (D-178). |
| 150 | + - name: Release notes |
| 151 | + run: | |
| 152 | + version="${GITHUB_REF_NAME#v}" |
| 153 | + awk -v v="$version" ' |
| 154 | + index($0, "## [" v "]") == 1 { found = 1; next } |
| 155 | + found && index($0, "## [") == 1 { exit } |
| 156 | + found { print } |
| 157 | + ' CHANGELOG.md > notes.md |
| 158 | + test -s notes.md || { echo "CHANGELOG.md has no section for $version"; exit 1; } |
| 159 | +
|
| 160 | + - name: Create the release |
| 161 | + env: |
| 162 | + GH_TOKEN: ${{ github.token }} |
| 163 | + run: | |
| 164 | + prerelease=$([[ "$GITHUB_REF_NAME" == *-* ]] && echo --prerelease || true) |
| 165 | + gh release create "$GITHUB_REF_NAME" artifacts/packages/*.nupkg \ |
| 166 | + --title "PythonScriptRunner ${GITHUB_REF_NAME#v}" --notes-file notes.md --verify-tag $prerelease |
0 commit comments