Diffinery

homeflare/celldpublic

celld/.github/workflows/release.yml
331 lines · 11.0 KBRaw History
1name: 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.
15on:
16 push:
17 branches:
18 - candidate
19 release:
20 types: [published]
21 workflow_dispatch:
22
23permissions:
24 contents: read
25
26concurrency:
27 group: release-${{ github.event_name }}-${{ github.ref }}
28 cancel-in-progress: true
29
30env:
31 RUST_VERSION: 1.97.1
32 IMAGE: ghcr.io/denoland/celld
33
34jobs:
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 the test stage
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 --target test \
106 --build-arg "CELLD_COMMIT=$GITHUB_SHA" \
107 --build-arg "CELLD_VERSION=$version" \
108 --cache-from "type=registry,ref=$IMAGE:buildcache-amd64" \
109 .
110
111 draft-release:
112 name: Attest and draft the release
113 if: github.event_name != 'release'
114 needs:
115 - build-celld
116 runs-on: ubuntu-22.04
117 timeout-minutes: 15
118 permissions:
119 contents: write
120 id-token: write
121 attestations: write
122 steps:
123 - uses: actions/checkout@v6
124
125 - uses: actions/download-artifact@v4
126 with:
127 path: assets
128 merge-multiple: true
129
130 # Assets are minimal: the binaries, nothing else. Integrity is the
131 # attestation plus GitHub's own immutable per-asset digests; gzip's
132 # CRC catches corruption in transit.
133 - name: Check assets
134 run: |
135 set -euo pipefail
136 cd assets
137 for target in \
138 x86_64-unknown-linux-gnu \
139 aarch64-unknown-linux-gnu \
140 aarch64-apple-darwin; do
141 test -f "celld-$target.gz"
142 done
143
144 # Attestations require a public repository; until the visibility flip
145 # this step is skipped and drafts carry checksums only.
146 - name: Attest build provenance
147 if: github.event.repository.visibility == 'public'
148 uses: actions/attest-build-provenance@v2
149 with:
150 subject-path: assets/*.gz
151
152 - name: Create or refresh the draft release
153 env:
154 GH_TOKEN: ${{ github.token }}
155 run: |
156 set -euo pipefail
157 version=$(sed -n 's/^version = "\(.*\)"$/\1/p' crates/celld/Cargo.toml | head -1)
158 tag="v$version"
159 existing=$(gh release view "$tag" --json isDraft \
160 --jq .isDraft 2>/dev/null || echo "absent")
161 if [ "$existing" = "false" ]; then
162 echo "release $tag is already published; bump the version" >&2
163 exit 1
164 fi
165 if [ "$existing" = "true" ]; then
166 gh release delete "$tag" --yes
167 fi
168 # The release body is the release commit's message: subject
169 # dropped (it is the title), trailers stripped, hard wraps
170 # unfolded so paragraphs and bullets render without awkward
171 # line breaks.
172 git log -1 --format=%b "$GITHUB_SHA" |
173 sed '/^[A-Za-z-]*-by:/d' |
174 awk '
175 /^$/ { if (buf != "") print buf; buf = ""; print; next }
176 /^- / { if (buf != "") print buf; buf = $0; next }
177 { sub(/^[ \t]+/, "")
178 buf = (buf == "" ? $0 : buf " " $0) }
179 END { if (buf != "") print buf }
180 ' | cat -s > /tmp/notes.md
181 gh release create "$tag" \
182 --draft \
183 --target "$GITHUB_SHA" \
184 --title "$tag" \
185 --notes-file /tmp/notes.md \
186 assets/*
187
188 build-container:
189 # Static name so a skipped run shows "Build container" instead of the
190 # unexpanded matrix expression; GitHub still appends the platform when
191 # the job actually runs.
192 name: Build container
193 if: github.event_name == 'release'
194 strategy:
195 fail-fast: false
196 matrix:
197 include:
198 - runner: ubuntu-22.04
199 platform: linux/amd64
200 suffix: amd64
201 - runner: ubuntu-22.04-arm
202 platform: linux/arm64
203 suffix: arm64
204 runs-on: ${{ matrix.runner }}
205 timeout-minutes: 60
206 permissions:
207 contents: read
208 packages: write
209 steps:
210 - uses: actions/checkout@v6
211 with:
212 ref: ${{ github.event.release.tag_name }}
213
214 - name: Resolve and validate the release tag
215 run: |
216 set -euo pipefail
217 version=$(sed -n 's/^version = "\(.*\)"$/\1/p' crates/celld/Cargo.toml | head -1)
218 test "${{ github.event.release.tag_name }}" = "v$version"
219 echo "TAG_SHA=$(git rev-parse HEAD)" >> "$GITHUB_ENV"
220 echo "CELLD_VERSION=$version" >> "$GITHUB_ENV"
221
222 # Registry cache export (--cache-to type=registry) needs the
223 # docker-container driver; the default docker driver cannot export.
224 - uses: docker/setup-buildx-action@v3
225
226 - name: Log in to GHCR
227 env:
228 GHCR_TOKEN: ${{ github.token }}
229 run: |
230 printf '%s' "$GHCR_TOKEN" |
231 docker login ghcr.io --username "$GITHUB_ACTOR" --password-stdin
232
233 - name: Test architecture image
234 run: |
235 set -euo pipefail
236 cache="$IMAGE:buildcache-${{ matrix.suffix }}"
237 docker buildx build \
238 --platform "${{ matrix.platform }}" \
239 --target test \
240 --build-arg "CELLD_COMMIT=$TAG_SHA" \
241 --build-arg "CELLD_VERSION=$CELLD_VERSION" \
242 --cache-from "type=registry,ref=$cache" \
243 --cache-to "type=registry,ref=$cache,mode=max" \
244 .
245
246 - name: Build and push architecture image
247 run: |
248 set -euo pipefail
249 tag="$IMAGE:$TAG_SHA-${{ matrix.suffix }}"
250 cache="$IMAGE:buildcache-${{ matrix.suffix }}"
251 docker buildx build \
252 --platform "${{ matrix.platform }}" \
253 --build-arg "CELLD_COMMIT=$TAG_SHA" \
254 --build-arg "CELLD_VERSION=$CELLD_VERSION" \
255 --cache-from "type=registry,ref=$cache" \
256 --cache-to "type=registry,ref=$cache,mode=max" \
257 --provenance=mode=max \
258 --sbom=true \
259 --tag "$tag" \
260 --push \
261 .
262
263 publish-container:
264 name: Publish multi-architecture image
265 if: github.event_name == 'release'
266 needs: build-container
267 runs-on: ubuntu-24.04
268 timeout-minutes: 15
269 permissions:
270 contents: read
271 packages: write
272 id-token: write
273 attestations: write
274 steps:
275 - uses: actions/checkout@v6
276 with:
277 ref: ${{ github.event.release.tag_name }}
278
279 - name: Resolve and validate the release tag
280 run: |
281 set -euo pipefail
282 version=$(sed -n 's/^version = "\(.*\)"$/\1/p' crates/celld/Cargo.toml | head -1)
283 test "${{ github.event.release.tag_name }}" = "v$version"
284 echo "TAG_SHA=$(git rev-parse HEAD)" >> "$GITHUB_ENV"
285 echo "CELLD_VERSION=$version" >> "$GITHUB_ENV"
286
287 - name: Log in to GHCR
288 env:
289 GHCR_TOKEN: ${{ github.token }}
290 run: |
291 printf '%s' "$GHCR_TOKEN" |
292 docker login ghcr.io --username "$GITHUB_ACTOR" --password-stdin
293
294 - name: Publish immutable and release tags
295 run: |
296 set -euo pipefail
297 docker buildx imagetools create \
298 --tag "$IMAGE:sha-$TAG_SHA" \
299 --tag "$IMAGE:${{ github.event.release.tag_name }}" \
300 --tag "$IMAGE:$CELLD_VERSION" \
301 --tag "$IMAGE:latest" \
302 "$IMAGE:$TAG_SHA-amd64" \
303 "$IMAGE:$TAG_SHA-arm64"
304
305 - name: Resolve manifest digest
306 id: digest
307 run: |
308 set -euo pipefail
309 digest=$(docker buildx imagetools inspect "$IMAGE:sha-$TAG_SHA" \
310 --format '{{json .Manifest.Digest}}' | tr -d '"')
311 echo "digest=$digest" >> "$GITHUB_OUTPUT"
312
313 # Attestations require a public repository; skipped until the
314 # visibility flip.
315 - name: Attest image provenance
316 if: github.event.repository.visibility == 'public'
317 uses: actions/attest-build-provenance@v2
318 with:
319 subject-name: ghcr.io/denoland/celld
320 subject-digest: ${{ steps.digest.outputs.digest }}
321 push-to-registry: true
322
323 # Meaningful only once the package is public; while the repository is
324 # internal an anonymous pull can only 401, and a red-by-design run
325 # teaches people to ignore red. Enforced automatically at launch.
326 - name: Verify anonymous manifest access
327 if: github.event.repository.visibility == 'public'
328 run: |
329 set -euo pipefail
330 docker logout ghcr.io
331 docker buildx imagetools inspect "$IMAGE:sha-$TAG_SHA"