Repository navigation
333 lines (313 loc) · 12.9 KB
/
Copy pathrelease.yml
File metadata and controls
333 lines (313 loc) · 12.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
name: Release
# Pushing a `release-*` tag (e.g. `release-2026-11-28`) on a commit on main
# releases every crate below whose `<crate>-vX.Y.Z` tag doesn't exist yet. The
# full CI and TCK run on that commit while the binaries build, and each crate
# publishes once CI, TCK and all of its builds pass. acdc-parser isn't released
# here; it's published by hand.
#
# Pull requests and pushes to main that change this file build every crate
# without publishing anything.
on:
push:
# GitHub ignores `paths` for tag pushes, so every release tag runs this.
tags: ['release-*']
branches: [main]
paths: ['.github/workflows/release.yml', '.cargo/config.toml']
pull_request:
paths: ['.github/workflows/release.yml', '.cargo/config.toml']
permissions:
contents: read
concurrency:
group: release-${{ github.ref }}
# Never cancel a release; superseded dry runs can go.
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}
defaults:
run:
shell: bash
env:
CARGO_TERM_COLOR: always
jobs:
ci:
uses: ./.github/workflows/ci.yml
with:
all: true
tck:
uses: ./.github/workflows/tck.yml
plan:
runs-on: ubuntu-latest
outputs:
releases: ${{ steps.plan.outputs.releases }}
native: ${{ steps.plan.outputs.native }}
wasm: ${{ steps.plan.outputs.wasm }}
targets: ${{ steps.plan.outputs.targets }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: taiki-e/install-action@073e1fd0bc889c9aee68dbaaa927cde1b5653a83 # v2.90.11
with:
tool: parse-changelog
- name: Find what to release
id: plan
run: |
set -euo pipefail
# What each native archive holds besides the binary, relative to the
# repository root.
declare -A include=(
[acdc-cli]="LICENSE,acdc-cli/README.adoc,acdc-cli/CHANGELOG.md,converters/pdf/crates/theme/assets/fonts/OFL.txt,converters/pdf/crates/theme/assets/fonts/LICENSE-NotoColorEmoji.txt"
[acdc-lsp]="LICENSE,acdc-lsp/README.md,acdc-lsp/CHANGELOG.md"
[acdc-mcp]="LICENSE,acdc-mcp/README.adoc,acdc-mcp/CHANGELOG.md"
)
# `glibc` is the oldest glibc a Linux binary may need. Those targets
# build with cargo-zigbuild, which links against that version. 2.28 is
# as low as it goes: libghostty-vt, built with Zig 0.16, calls
# `statx`, which glibc added in 2.28.
targets=$(jq -c . <<'EOF'
[
{"target": "aarch64-apple-darwin", "os": "macos-15"},
{"target": "x86_64-apple-darwin", "os": "macos-15-intel"},
{"target": "x86_64-unknown-linux-gnu", "os": "ubuntu-22.04", "glibc": "2.28"},
{"target": "aarch64-unknown-linux-gnu", "os": "ubuntu-22.04-arm", "glibc": "2.28"},
{"target": "x86_64-pc-windows-msvc", "os": "windows-2022"}
]
EOF
)
release=false
if [[ $GITHUB_REF == refs/tags/release-* ]]; then
release=true
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
echo "::error::${GITHUB_REF#refs/tags/} isn't on main. Tag a commit on main."
exit 1
fi
fi
metadata=$(cargo metadata --no-deps --format-version 1 --locked)
releases='[]'
missing_notes=false
for crate in acdc-cli acdc-lsp acdc-mcp acdc-editor-wasm; do
package=$(jq -ec --arg crate "$crate" '.packages[] | select(.name == $crate)' <<<"$metadata")
version=$(jq -er .version <<<"$package")
tag="$crate-v$version"
publish=false
if [[ $release == true ]]; then
# Exit 2 means the tag doesn't exist. Anything else is an error,
# never a reason to release everything.
status=0
git ls-remote --exit-code --tags origin "refs/tags/$tag" >/dev/null || status=$?
case $status in
0) echo "$tag is already released"; continue ;;
2) publish=true ;;
*) echo "::error::Couldn't list the tags on origin"; exit 1 ;;
esac
fi
if ! parse-changelog "$crate/CHANGELOG.md" "$version" >/dev/null; then
echo "::error::$crate $version has no CHANGELOG section"
missing_notes=true
fi
if [[ $crate == acdc-editor-wasm ]]; then
kind=wasm bin='' files=''
else
kind=native
bin=$(jq -er '[.targets[] | select(.kind | index("bin")) | .name] | if length == 1 then .[0] else error("expected one binary") end' <<<"$package")
files=${include[$crate]:-}
if [[ -z $files ]]; then
echo "::error::$crate has no packaging entry in release.yml"
exit 1
fi
fi
releases=$(jq -c \
--arg crate "$crate" --arg version "$version" --arg tag "$tag" \
--argjson publish "$publish" --arg kind "$kind" --arg bin "$bin" --arg include "$files" \
'. + [{$crate, $version, $tag, $publish, $kind} + (if $kind == "native" then {$bin, $include} else {} end)]' \
<<<"$releases")
done
if [[ $missing_notes == true ]]; then
exit 1
fi
if [[ $releases == '[]' ]]; then
echo "::error::Nothing to release: every crate's version is already tagged"
exit 1
fi
{
echo "releases=$releases"
echo "native=$(jq -c 'map(select(.kind == "native"))' <<<"$releases")"
echo "wasm=$(jq -c 'map(select(.kind == "wasm")) | first // empty' <<<"$releases")"
echo "targets=$targets"
} | tee -a "$GITHUB_OUTPUT"
build:
needs: plan
if: needs.plan.outputs.native != '[]'
name: build (${{ matrix.release.crate }}, ${{ matrix.platform.target }})
strategy:
fail-fast: false
matrix:
release: ${{ fromJSON(needs.plan.outputs.native) }}
platform: ${{ fromJSON(needs.plan.outputs.targets) }}
runs-on: ${{ matrix.platform.os }}
timeout-minutes: 90
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform.target }}
# libghostty-vt, behind acdc-cli's terminal emulator, builds with zig.
# cargo-zigbuild uses it too, for the Linux targets.
- if: matrix.release.crate == 'acdc-cli' || matrix.platform.glibc
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
- if: matrix.platform.glibc
uses: taiki-e/install-action@073e1fd0bc889c9aee68dbaaa927cde1b5653a83 # v2.90.11
with:
tool: cargo-zigbuild
# Always a dry run: the action builds and archives, and `publish` uploads
# once everything has passed.
- uses: taiki-e/upload-rust-binary-action@f0d45ae91ee7b8ee928de7a9d04d893a08bcbec6 # v1.30.2
with:
dry-run: true
dry-run-intended: true
ref: refs/tags/${{ matrix.release.tag }}
bin: ${{ matrix.release.bin }}
package: ${{ matrix.release.crate }}
# cargo-zigbuild reads the glibc version from a `.2.28` suffix.
target: ${{ matrix.platform.glibc && format('{0}.{1}', matrix.platform.target, matrix.platform.glibc) || matrix.platform.target }}
build-tool: ${{ matrix.platform.glibc && 'cargo-zigbuild' || '' }}
all-features: true
locked: true
archive: ${{ matrix.release.crate }}-$target
leading-dir: true
include: ${{ matrix.release.include }}
checksum: sha256
# Every runner builds for its own architecture, so the binary that goes
# into the archive can run here. acdc-lsp ignores --version and serves
# on stdin, so it exits as soon as it reads EOF.
- name: Check the binary starts
env:
BIN: target/${{ matrix.platform.target }}/release/${{ matrix.release.bin }}${{ runner.os == 'Windows' && '.exe' || '' }}
run: '"$BIN" --version </dev/null'
- name: Check the glibc version the binary needs
if: matrix.platform.glibc
env:
BIN: target/${{ matrix.platform.target }}/release/${{ matrix.release.bin }}
GLIBC: ${{ matrix.platform.glibc }}
run: |
newest=$(objdump -T "$BIN" | grep -o 'GLIBC_[0-9.]*' | sed 's/^GLIBC_//' | sort -uV | tail -n 1)
echo "$BIN needs glibc $newest"
if [[ $(printf '%s\n' "$newest" "$GLIBC" | sort -V | tail -n 1) != "$GLIBC" ]]; then
echo "::error::$BIN needs glibc $newest, newer than $GLIBC"
exit 1
fi
- uses: actions/upload-artifact@v7
with:
name: ${{ matrix.release.tag }}-${{ matrix.platform.target }}
path: ${{ matrix.release.crate }}-${{ matrix.platform.target }}.*
if-no-files-found: error
wasm:
needs: plan
if: needs.plan.outputs.wasm != ''
runs-on: ubuntu-latest
timeout-minutes: 30
env:
ARCHIVE: acdc-editor-wasm-v${{ fromJSON(needs.plan.outputs.wasm).version }}.tar.gz
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- uses: taiki-e/install-action@073e1fd0bc889c9aee68dbaaa927cde1b5653a83 # v2.90.11
with:
tool: wasm-pack
- run: wasm-pack build acdc-editor-wasm --target web --release
- name: Create tarball and checksum
run: |
tar -czf "$ARCHIVE" -C acdc-editor-wasm/pkg .
sha256sum "$ARCHIVE" > "$ARCHIVE.sha256"
- uses: actions/upload-artifact@v7
with:
name: ${{ fromJSON(needs.plan.outputs.wasm).tag }}
path: ${{ env.ARCHIVE }}*
if-no-files-found: error
publish:
needs: [ci, tck, plan, build, wasm]
# A crate whose build failed doesn't hold back the others; its own
# completeness check below fails instead.
if: ${{ !cancelled() && needs.ci.result == 'success' && needs.tck.result == 'success' && needs.plan.result == 'success' }}
name: publish (${{ matrix.release.tag }})
strategy:
fail-fast: false
matrix:
release: ${{ fromJSON(needs.plan.outputs.releases) }}
runs-on: ubuntu-latest
permissions:
contents: write
env:
CRATE: ${{ matrix.release.crate }}
VERSION: ${{ matrix.release.version }}
TAG: ${{ matrix.release.tag }}
KIND: ${{ matrix.release.kind }}
PUBLISH: ${{ matrix.release.publish }}
TARGETS: ${{ needs.plan.outputs.targets }}
steps:
- uses: actions/checkout@v7
- uses: taiki-e/install-action@073e1fd0bc889c9aee68dbaaa927cde1b5653a83 # v2.90.11
with:
tool: parse-changelog
- if: matrix.release.kind == 'native'
uses: actions/download-artifact@v8
with:
pattern: ${{ matrix.release.tag }}-*
merge-multiple: true
path: dist
- if: matrix.release.kind == 'wasm'
uses: actions/download-artifact@v8
with:
name: ${{ matrix.release.tag }}
path: dist
- name: Check every file is there and intact
run: |
set -euo pipefail
missing=()
if [[ $KIND == native ]]; then
for target in $(jq -r '.[].target' <<<"$TARGETS"); do
stem="dist/$CRATE-$target"
[[ -f $stem.sha256 ]] || missing+=("$stem.sha256")
[[ -f $stem.tar.gz || -f $stem.zip ]] || missing+=("$stem.tar.gz or .zip")
done
else
archive="dist/$CRATE-v$VERSION.tar.gz"
[[ -f $archive ]] || missing+=("$archive")
[[ -f $archive.sha256 ]] || missing+=("$archive.sha256")
fi
if (( ${#missing[@]} > 0 )); then
echo "::error::$TAG is missing ${missing[*]}"
exit 1
fi
cd dist
sha256sum --check --strict -- *.sha256
- name: Publish the release
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: |
set -euo pipefail
notes="$RUNNER_TEMP/notes.md"
parse-changelog "$CRATE/CHANGELOG.md" "$VERSION" > "$notes"
args=(release create "$TAG" dist/* --target "$GITHUB_SHA" --title "$CRATE $VERSION" --notes-file "$notes")
if [[ $VERSION == *-* ]]; then
args+=(--prerelease)
fi
if [[ $KIND == wasm ]]; then
args+=(--latest=false)
fi
if [[ $PUBLISH != true ]]; then
echo "Dry run, so not running: gh $(printf '%q ' "${args[@]}")"
ls -l dist
cat "$notes"
exit 0
fi
status=0
git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null || status=$?
case $status in
0) echo "::notice::$TAG was already released by another run"; exit 0 ;;
2) gh "${args[@]}" ;;
*) echo "::error::Couldn't list the tags on origin"; exit 1 ;;
esac