Diffinery

homeflare/celldpublic

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