| 1 | name: Release |
| 2 | |
| 3 | # One release pipeline, two phases. |
| 4 | # |
| 5 | # A push to the candidate ref builds every native target, attests |
| 6 | # provenance, uploads everything to a DRAFT GitHub release, and |
| 7 | # smoke-builds the container image. Publishing the draft is a separate, |
| 8 | # human-approved step after the candidate binaries pass verification; a |
| 9 | # failed candidate is deleted and main never moves. |
| 10 | # |
| 11 | # Publishing the release (release: published) triggers the container |
| 12 | # phase: architecture images are built from the tagged commit, pushed to |
| 13 | # GHCR, and stitched into a multi-architecture manifest with the same |
| 14 | # provenance attestation as the binaries. |
| 15 | on: |
| 16 | push: |
| 17 | branches: |
| 18 | - candidate |
| 19 | release: |
| 20 | types: [published] |
| 21 | workflow_dispatch: |
| 22 | |
| 23 | permissions: |
| 24 | contents: read |
| 25 | |
| 26 | concurrency: |
| 27 | group: release-${{ github.event_name }}-${{ github.ref }} |
| 28 | cancel-in-progress: true |
| 29 | |
| 30 | env: |
| 31 | RUST_VERSION: 1.98.1 |
| 32 | IMAGE: ghcr.io/denoland/celld |
| 33 | |
| 34 | jobs: |
| 35 | build-celld: |
| 36 | name: Build celld ${{ matrix.target }} |
| 37 | if: github.event_name != 'release' |
| 38 | strategy: |
| 39 | fail-fast: false |
| 40 | matrix: |
| 41 | include: |
| 42 | - runner: ubuntu-22.04 |
| 43 | target: x86_64-unknown-linux-gnu |
| 44 | - runner: ubuntu-22.04-arm |
| 45 | target: aarch64-unknown-linux-gnu |
| 46 | - runner: macos-14 |
| 47 | target: aarch64-apple-darwin |
| 48 | runs-on: ${{ matrix.runner }} |
| 49 | timeout-minutes: 90 |
| 50 | steps: |
| 51 | - uses: actions/checkout@v6 |
| 52 | |
| 53 | - name: Build |
| 54 | run: | |
| 55 | set -euo pipefail |
| 56 | rustup toolchain install "$RUST_VERSION" --profile minimal |
| 57 | rustup default "$RUST_VERSION" |
| 58 | cargo build --release --locked |
| 59 | version=$(sed -n 's/^version = "\(.*\)"$/\1/p' crates/celld/Cargo.toml | head -1) |
| 60 | target/release/celld --version | grep -F "$version" |
| 61 | |
| 62 | - name: Package |
| 63 | run: | |
| 64 | set -euo pipefail |
| 65 | mkdir -p out |
| 66 | # -n omits name and timestamp so the envelope is reproducible |
| 67 | # whenever the binary is. |
| 68 | gzip -9 -n -c target/release/celld \ |
| 69 | > "out/celld-${{ matrix.target }}.gz" |
| 70 | |
| 71 | - uses: actions/upload-artifact@v4 |
| 72 | with: |
| 73 | name: celld-${{ matrix.target }} |
| 74 | path: out/celld-${{ matrix.target }}.gz |
| 75 | if-no-files-found: error |
| 76 | |
| 77 | # The Dockerfile must build and its test stage pass before anything can |
| 78 | # be published; nothing is pushed at candidate time. |
| 79 | container-check: |
| 80 | name: Container smoke build |
| 81 | if: github.event_name != 'release' |
| 82 | runs-on: ubuntu-22.04 |
| 83 | timeout-minutes: 60 |
| 84 | permissions: |
| 85 | contents: read |
| 86 | packages: read |
| 87 | steps: |
| 88 | - uses: actions/checkout@v6 |
| 89 | |
| 90 | - uses: docker/setup-buildx-action@v3 |
| 91 | |
| 92 | - name: Log in to GHCR |
| 93 | env: |
| 94 | GHCR_TOKEN: ${{ github.token }} |
| 95 | run: | |
| 96 | printf '%s' "$GHCR_TOKEN" | |
| 97 | docker login ghcr.io --username "$GITHUB_ACTOR" --password-stdin |
| 98 | |
| 99 | - name: Build and test the image |
| 100 | run: | |
| 101 | set -euo pipefail |
| 102 | version=$(sed -n 's/^version = "\(.*\)"$/\1/p' crates/celld/Cargo.toml | head -1) |
| 103 | docker buildx build \ |
| 104 | --platform linux/amd64 \ |
| 105 | --build-arg "CELLD_COMMIT=$GITHUB_SHA" \ |
| 106 | --build-arg "CELLD_VERSION=$version" \ |
| 107 | --cache-from "type=registry,ref=$IMAGE:buildcache-amd64" \ |
| 108 | . |
| 109 | |
| 110 | draft-release: |
| 111 | name: Attest and draft the release |
| 112 | if: github.event_name != 'release' |
| 113 | needs: |
| 114 | - build-celld |
| 115 | runs-on: ubuntu-22.04 |
| 116 | timeout-minutes: 15 |
| 117 | permissions: |
| 118 | contents: write |
| 119 | id-token: write |
| 120 | attestations: write |
| 121 | steps: |
| 122 | - uses: actions/checkout@v6 |
| 123 | |
| 124 | - uses: actions/download-artifact@v4 |
| 125 | with: |
| 126 | path: assets |
| 127 | merge-multiple: true |
| 128 | |
| 129 | # Assets are minimal: the binaries, nothing else. Integrity is the |
| 130 | # attestation plus GitHub's own immutable per-asset digests; gzip's |
| 131 | # CRC catches corruption in transit. |
| 132 | - name: Check assets |
| 133 | run: | |
| 134 | set -euo pipefail |
| 135 | cd assets |
| 136 | for target in \ |
| 137 | x86_64-unknown-linux-gnu \ |
| 138 | aarch64-unknown-linux-gnu \ |
| 139 | aarch64-apple-darwin; do |
| 140 | test -f "celld-$target.gz" |
| 141 | done |
| 142 | |
| 143 | # Attestations require a public repository. Other repository visibilities |
| 144 | # skip this step and retain the release asset digests. |
| 145 | - name: Attest build provenance |
| 146 | if: github.event.repository.visibility == 'public' |
| 147 | uses: actions/attest-build-provenance@v2 |
| 148 | with: |
| 149 | subject-path: assets/*.gz |
| 150 | |
| 151 | - name: Create or refresh the draft release |
| 152 | env: |
| 153 | GH_TOKEN: ${{ github.token }} |
| 154 | run: | |
| 155 | set -euo pipefail |
| 156 | version=$(sed -n 's/^version = "\(.*\)"$/\1/p' crates/celld/Cargo.toml | head -1) |
| 157 | tag="v$version" |
| 158 | existing=$(gh release view "$tag" --json isDraft \ |
| 159 | --jq .isDraft 2>/dev/null || echo "absent") |
| 160 | if [ "$existing" = "false" ]; then |
| 161 | echo "release $tag is already published; bump the version" >&2 |
| 162 | exit 1 |
| 163 | fi |
| 164 | if [ "$existing" = "true" ]; then |
| 165 | gh release delete "$tag" --yes |
| 166 | fi |
| 167 | # The release body is the release commit's message: subject |
| 168 | # dropped (it is the title), trailers stripped, hard wraps |
| 169 | # unfolded so paragraphs and bullets render without awkward |
| 170 | # line breaks. |
| 171 | git log -1 --format=%b "$GITHUB_SHA" | |
| 172 | sed '/^[A-Za-z-]*-by:/d' | |
| 173 | awk ' |
| 174 | /^$/ { if (buf != "") print buf; buf = ""; print; next } |
| 175 | /^- / { if (buf != "") print buf; buf = $0; next } |
| 176 | { sub(/^[ \t]+/, "") |
| 177 | buf = (buf == "" ? $0 : buf " " $0) } |
| 178 | END { if (buf != "") print buf } |
| 179 | ' | cat -s > /tmp/notes.md |
| 180 | gh release create "$tag" \ |
| 181 | --draft \ |
| 182 | --target "$GITHUB_SHA" \ |
| 183 | --title "$tag" \ |
| 184 | --notes-file /tmp/notes.md \ |
| 185 | assets/* |
| 186 | |
| 187 | build-container: |
| 188 | # Static name so a skipped run shows "Build container" instead of the |
| 189 | # unexpanded matrix expression; GitHub still appends the platform when |
| 190 | # the job actually runs. |
| 191 | name: Build container |
| 192 | if: github.event_name == 'release' |
| 193 | strategy: |
| 194 | fail-fast: false |
| 195 | matrix: |
| 196 | include: |
| 197 | - runner: ubuntu-22.04 |
| 198 | platform: linux/amd64 |
| 199 | suffix: amd64 |
| 200 | - runner: ubuntu-22.04-arm |
| 201 | platform: linux/arm64 |
| 202 | suffix: arm64 |
| 203 | runs-on: ${{ matrix.runner }} |
| 204 | timeout-minutes: 60 |
| 205 | permissions: |
| 206 | contents: read |
| 207 | packages: write |
| 208 | steps: |
| 209 | - uses: actions/checkout@v6 |
| 210 | with: |
| 211 | ref: ${{ github.event.release.tag_name }} |
| 212 | |
| 213 | - name: Resolve and validate the release tag |
| 214 | run: | |
| 215 | set -euo pipefail |
| 216 | version=$(sed -n 's/^version = "\(.*\)"$/\1/p' crates/celld/Cargo.toml | head -1) |
| 217 | test "${{ github.event.release.tag_name }}" = "v$version" |
| 218 | echo "TAG_SHA=$(git rev-parse HEAD)" >> "$GITHUB_ENV" |
| 219 | echo "CELLD_VERSION=$version" >> "$GITHUB_ENV" |
| 220 | |
| 221 | # Registry cache export (--cache-to type=registry) needs the |
| 222 | # docker-container driver; the default docker driver cannot export. |
| 223 | - uses: docker/setup-buildx-action@v3 |
| 224 | |
| 225 | - name: Log in to GHCR |
| 226 | env: |
| 227 | GHCR_TOKEN: ${{ github.token }} |
| 228 | run: | |
| 229 | printf '%s' "$GHCR_TOKEN" | |
| 230 | docker login ghcr.io --username "$GITHUB_ACTOR" --password-stdin |
| 231 | |
| 232 | - name: Test, build, and push architecture image |
| 233 | run: | |
| 234 | set -euo pipefail |
| 235 | tag="$IMAGE:$TAG_SHA-${{ matrix.suffix }}" |
| 236 | cache="$IMAGE:buildcache-${{ matrix.suffix }}" |
| 237 | docker buildx build \ |
| 238 | --platform "${{ matrix.platform }}" \ |
| 239 | --build-arg "CELLD_COMMIT=$TAG_SHA" \ |
| 240 | --build-arg "CELLD_VERSION=$CELLD_VERSION" \ |
| 241 | --cache-from "type=registry,ref=$cache" \ |
| 242 | --cache-to "type=registry,ref=$cache,mode=max" \ |
| 243 | --provenance=mode=max \ |
| 244 | --sbom=true \ |
| 245 | --tag "$tag" \ |
| 246 | --push \ |
| 247 | . |
| 248 | |
| 249 | publish-container: |
| 250 | name: Publish multi-architecture image |
| 251 | if: github.event_name == 'release' |
| 252 | needs: build-container |
| 253 | runs-on: ubuntu-24.04 |
| 254 | timeout-minutes: 15 |
| 255 | permissions: |
| 256 | contents: read |
| 257 | packages: write |
| 258 | id-token: write |
| 259 | attestations: write |
| 260 | steps: |
| 261 | - uses: actions/checkout@v6 |
| 262 | with: |
| 263 | ref: ${{ github.event.release.tag_name }} |
| 264 | |
| 265 | - name: Resolve and validate the release tag |
| 266 | run: | |
| 267 | set -euo pipefail |
| 268 | version=$(sed -n 's/^version = "\(.*\)"$/\1/p' crates/celld/Cargo.toml | head -1) |
| 269 | test "${{ github.event.release.tag_name }}" = "v$version" |
| 270 | echo "TAG_SHA=$(git rev-parse HEAD)" >> "$GITHUB_ENV" |
| 271 | echo "CELLD_VERSION=$version" >> "$GITHUB_ENV" |
| 272 | |
| 273 | - name: Log in to GHCR |
| 274 | env: |
| 275 | GHCR_TOKEN: ${{ github.token }} |
| 276 | run: | |
| 277 | printf '%s' "$GHCR_TOKEN" | |
| 278 | docker login ghcr.io --username "$GITHUB_ACTOR" --password-stdin |
| 279 | |
| 280 | - name: Publish immutable and release tags |
| 281 | run: | |
| 282 | set -euo pipefail |
| 283 | docker buildx imagetools create \ |
| 284 | --tag "$IMAGE:sha-$TAG_SHA" \ |
| 285 | --tag "$IMAGE:${{ github.event.release.tag_name }}" \ |
| 286 | --tag "$IMAGE:$CELLD_VERSION" \ |
| 287 | --tag "$IMAGE:latest" \ |
| 288 | "$IMAGE:$TAG_SHA-amd64" \ |
| 289 | "$IMAGE:$TAG_SHA-arm64" |
| 290 | |
| 291 | - name: Resolve manifest digest |
| 292 | id: digest |
| 293 | run: | |
| 294 | set -euo pipefail |
| 295 | digest=$(docker buildx imagetools inspect "$IMAGE:sha-$TAG_SHA" \ |
| 296 | --format '{{json .Manifest.Digest}}' | tr -d '"') |
| 297 | echo "digest=$digest" >> "$GITHUB_OUTPUT" |
| 298 | |
| 299 | # Attestations require a public repository. |
| 300 | - name: Attest image provenance |
| 301 | if: github.event.repository.visibility == 'public' |
| 302 | uses: actions/attest-build-provenance@v2 |
| 303 | with: |
| 304 | subject-name: ghcr.io/denoland/celld |
| 305 | subject-digest: ${{ steps.digest.outputs.digest }} |
| 306 | push-to-registry: true |
| 307 | |
| 308 | # Meaningful only once the package is public; while the repository is |
| 309 | # internal an anonymous pull can only 401, and a red-by-design run |
| 310 | # teaches people to ignore red. Enforced automatically at launch. |
| 311 | - name: Verify anonymous manifest access |
| 312 | if: github.event.repository.visibility == 'public' |
| 313 | run: | |
| 314 | set -euo pipefail |
| 315 | docker logout ghcr.io |
| 316 | docker buildx imagetools inspect "$IMAGE:sha-$TAG_SHA" |