Repository navigation
322 lines (322 loc) · 12.6 KB
/
Copy pathrelease.yml
File metadata and controls
322 lines (322 loc) · 12.6 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
# SPDX-FileCopyrightText: 2026 fxrdhan
# SPDX-License-Identifier: EUPL-1.2
#
# Publishes a release when a v* tag is pushed: the GitHub release with its
# binaries, then the crate on crates.io and the Homebrew formula.
#
# The binaries are built on GitHub runners, one target per runner, natively.
# The justfile's `cross` recipe builds seven targets through Docker instead,
# in containers on the maintainer's machine. This does not.
#
# The release is published once every binary is built and CI has passed on
# main for the tagged commit, release-mode tests included. Its notes are
# the version's section of CHANGELOG.md, the one written by hand: the commit
# titles git-cliff would list say little once a pull request is squashed.
#
# Run any other way, by hand or by a pull request that changes this file, it
# is a dry run: everything is built and packaged, under a stand-in version,
# and nothing is published. Run it by hand on the release branch before
# tagging, since the packaging steps run nowhere else.
name: Release
on:
push:
tags:
- "v*"
pull_request:
branches: [main, dev]
paths:
- .github/workflows/release.yml
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
env:
# The pushed tag; on a dry run, a stand-in that is safe in a file name and
# in the sed below, unlike a pull request's ref name, `150/merge`.
VERSION: ${{ github.event_name == 'push' && github.ref_name || 'v0.0.0-dry-run' }}
jobs:
binaries:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
archive: tar.gz
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
archive: tar.gz
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
archive: tar.gz
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-musl
archive: tar.gz
- os: macos-latest
target: aarch64-apple-darwin
archive: tar.gz
- os: macos-latest
target: x86_64-apple-darwin
archive: tar.gz
- os: windows-latest
target: x86_64-pc-windows-msvc
archive: zip
- os: windows-latest
target: aarch64-pc-windows-msvc
archive: zip
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master
with:
toolchain: stable
targets: ${{ matrix.target }}
# rust-toolchain.toml pins the MSRV for every cargo command in the
# checkout. The binaries are built with stable, as CI's Release Build
# and Release-mode Tests are, and RUSTUP_TOOLCHAIN outranks that file.
- name: Use stable
shell: bash
run: echo "RUSTUP_TOOLCHAIN=stable" >> "$GITHUB_ENV"
# A musl binary is static, so the C in it, libgit2 and zlib, is built
# from the crates' own sources with musl's compiler, which CC_<target>
# names for the cc crate.
- name: Install the musl toolchain
if: endsWith(matrix.target, '-linux-musl')
env:
TARGET: ${{ matrix.target }}
run: |
sudo apt-get update -qq && sudo apt-get install -y -qq musl-tools
echo "CC_${TARGET//-/_}=musl-gcc" >> "$GITHUB_ENV"
# Saved only by a dry run on dev, which a tag's run restores. A cache
# saved under a tag, or a pull request's merge ref, serves no other run.
- name: Rust Cache
uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
key: release-${{ matrix.target }}
save-if: ${{ github.ref == 'refs/heads/dev' }}
- name: Build
run: cargo build --release --locked --target ${{ matrix.target }} --features git,inspect-archives
# What INSTALL.md says of the musl archives, and what lets the binary
# start where there is no glibc.
- name: Check that the musl binary is static
if: endsWith(matrix.target, '-linux-musl')
run: |
file "target/${{ matrix.target }}/release/lez" | tee /dev/stderr \
| grep -Eq 'static(ally|-pie) linked'
- name: Package (tar.gz)
if: matrix.archive == 'tar.gz'
run: |
mkdir -p dist
tar czf "dist/lez_${{ matrix.target }}.tar.gz" -C "target/${{ matrix.target }}/release" lez
# One for each glibc target: cargo-deb names the package's architecture
# after the target, amd64 or arm64. A musl target would give a second
# package of the same name, so it gets none.
- name: Package (.deb)
if: endsWith(matrix.target, '-linux-gnu')
run: |
sudo apt-get update -qq && sudo apt-get install -y -qq pandoc
for page in lez.1 lez_colors.5 lez_colors-explanation.5; do
sed "s/\$version/${VERSION}/g" "man/${page}.md" \
| pandoc --standalone -f markdown -t man > "man/${page}"
done
cargo install cargo-deb --locked
cargo deb --no-build --target ${{ matrix.target }} -o dist/
- name: Package (zip)
if: matrix.archive == 'zip'
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path dist | Out-Null
Compress-Archive -Path "target/${{ matrix.target }}/release/lez.exe" -DestinationPath "dist/lez_${{ matrix.target }}.zip"
- name: Upload
uses: actions/upload-artifact@v7
with:
name: binary-${{ matrix.target }}
path: dist/*
if-no-files-found: error
notes:
name: Release notes
runs-on: ubuntu-latest
outputs:
notes: ${{ steps.notes.outputs.notes }}
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Take the version's section of CHANGELOG.md
id: notes
run: |
# The first `version =` in Cargo.toml is the package's.
version=$(sed -n 's/^version = "\(.*\)"$/\1/p' Cargo.toml | head -n 1)
if [ "${GITHUB_EVENT_NAME}" = push ] && [ "${VERSION}" != "v${version}" ]; then
echo "::error file=Cargo.toml::The tag is ${VERSION}, but Cargo.toml says ${version}."
exit 1
fi
awk -v head="## [${version}]" '
index($0, "## [") == 1 { if (on) exit; on = index($0, head) == 1; next }
on
' CHANGELOG.md > NOTES.md
if ! grep -q '[^[:space:]]' NOTES.md; then
echo "::error file=CHANGELOG.md::CHANGELOG.md has no section for ${version}."
exit 1
fi
cat NOTES.md
{
echo "notes<<EOF_NOTES"
cat NOTES.md
echo "EOF_NOTES"
} >> "$GITHUB_OUTPUT"
docs:
name: Man pages and completions
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Install pandoc
run: sudo apt-get update -qq && sudo apt-get install -y -qq pandoc
- name: Build the tarballs
run: |
version="${VERSION}"
mkdir -p "man-${version}" "completions-${version}" dist
for page in lez.1 lez_colors.5 lez_colors-explanation.5; do
sed "s/\$version/${version}/g" "man/${page}.md" \
| pandoc --standalone -f markdown -t man > "man-${version}/${page}"
done
cp completions/*/* "completions-${version}/"
tar czf "dist/man-${version}.tar.gz" "man-${version}"
tar czf "dist/completions-${version}.tar.gz" "completions-${version}"
- name: Upload
uses: actions/upload-artifact@v7
with:
name: docs
path: dist/*
if-no-files-found: error
# A tag publishes nothing CI has not passed on main: the release-mode tests
# run there alone, and pushing a tag waits for nothing. The binaries build
# meanwhile, so this costs only whatever time CI has left to run.
ci-on-main:
name: CI passed on main
if: github.event_name == 'push' && github.ref_type == 'tag'
runs-on: ubuntu-latest
permissions:
actions: read
steps:
- name: Wait for CI on main to pass for the tagged commit
env:
GH_TOKEN: ${{ github.token }}
run: |
# main and the tag may be pushed together, so the run can still be
# on its way.
run=""
for _ in $(seq 1 20); do
run=$(gh run list --repo "$GITHUB_REPOSITORY" --workflow ci.yml \
--branch main --commit "$GITHUB_SHA" --limit 1 \
--json databaseId --jq '.[0].databaseId // empty' || true)
[ -n "$run" ] && break
sleep 15
done
if [ -z "$run" ]; then
echo "::error::CI never ran on main for ${GITHUB_SHA}. Push the commit to main, then tag it."
exit 1
fi
if ! gh run watch "$run" --repo "$GITHUB_REPOSITORY" --exit-status --compact --interval 30; then
echo "::error::CI failed on main for ${GITHUB_SHA}, so nothing is published."
exit 1
fi
publish:
name: Publish the release
needs: [binaries, docs, notes, ci-on-main]
# Only a pushed tag publishes; run by hand, even on a tag, it is a dry run.
if: github.event_name == 'push' && github.ref_type == 'tag'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Collect the artifacts
uses: actions/download-artifact@v8
with:
path: artifacts
- name: Flatten
run: |
mkdir -p dist
find artifacts -type f -exec mv {} dist/ \;
ls -l dist
- name: Write the release notes
env:
NOTES: ${{ needs.notes.outputs.notes }}
run: |
printf '%s\n' "${NOTES}" > NOTES.md
{
echo
echo "## Checksums"
echo
echo '```'
(cd dist && sha256sum ./*)
echo '```'
} >> NOTES.md
- name: Publish the release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "${GITHUB_REF_NAME}" \
--title "lez ${GITHUB_REF_NAME}" \
--notes-file NOTES.md \
dist/*
homebrew:
name: Update the Homebrew formula
needs: publish
# Its own job, so a tap token that cannot write fails here alone rather
# than marking the release, or anything waiting on it, failed.
if: "!contains(github.ref_name, '-')"
runs-on: ubuntu-latest
steps:
- name: Update Homebrew formula
uses: mislav/bump-homebrew-formula-action@f865c8b0dbebd6e263cc06782a0e974c61cf12d2 # v4.2
if: env.COMMITTER_TOKEN != ''
with:
formula-name: lez
homebrew-tap: fxrdhan/homebrew-tap
base-branch: main
download-url: https://github.com/fxrdhan/lez/archive/refs/tags/${{ github.ref_name }}.tar.gz
commit-message: "bump lez to ${{ github.ref_name }}"
env:
COMMITTER_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
crates-io:
name: Publish to crates.io
# After the GitHub release, because `cargo binstall` takes the version
# from crates.io and the binaries from that release. A dry run, which
# releases nothing, packages and builds the crate without uploading it.
needs: publish
if: ${{ !cancelled() && (needs.publish.result == 'success' || github.event_name != 'push') }}
runs-on: ubuntu-latest
permissions:
contents: read
# Trusted Publishing: crates.io trusts this workflow, so no token is
# stored. Configured under the crate's Settings > Trusted Publishing.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master
with:
toolchain: stable
- name: Use stable
run: echo "RUSTUP_TOOLCHAIN=stable" >> "$GITHUB_ENV"
- name: Check the package
if: github.event_name != 'push'
run: cargo publish --dry-run --locked
- name: Authenticate with crates.io
id: auth
if: github.event_name == 'push'
uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6
- name: Publish
if: github.event_name == 'push'
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
run: cargo publish --locked