-
Notifications
You must be signed in to change notification settings - Fork 0
456 lines (402 loc) · 15 KB
/
Copy pathci.yml
File metadata and controls
456 lines (402 loc) · 15 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
name: CI and release
on:
push:
branches:
- main
tags:
- "v*"
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
CRATE_NAME: hubuum-cli
GITHUB_TOKEN: ${{ github.token }}
RUST_BACKTRACE: 1
permissions:
contents: read
jobs:
lint:
name: Lint
if: "!startsWith(github.ref, 'refs/tags/')"
runs-on: ubuntu-24.04
steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Install clippy
run: rustup component add clippy
- name: Run clippy
run: cargo clippy --locked --all-targets -- -D warnings
- name: Run Host extension wrapper tests
run: examples/hubuum-wrappers/tests/test_wrappers.sh
- name: Validate extension JSON Schema
run: npx --yes ajv-cli@5.0.0 compile --spec=draft2020 -s schemas/hubuum-extension.schema.json
- name: Markdown lint
uses: DavidAnson/markdownlint-cli2-action@28a7e8bdb81fd8ad675883de92c758ab78e0ce10 # v24
with:
config: ".markdownlint.json"
globs: "**/*.md"
test:
name: ${{ matrix.platform.os_name }} with rust ${{ matrix.toolchain }}
if: "!startsWith(github.ref, 'refs/tags/')"
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform:
- os_name: Linux-x86_64
os: ubuntu-24.04
target: x86_64-unknown-linux-gnu
skip_tests: false
- os_name: macOS-aarch64
os: macos-latest
target: aarch64-apple-darwin
skip_tests: true
- os_name: Windows-x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
skip_tests: true
toolchain:
- stable
- beta
- nightly
steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Cache cargo and target directories
uses: Swatinem/rust-cache@49a0bdc70d2e1b713ca9e2869b211fcce03d3c1c # v2
- name: Build binary
uses: houseabsolute/actions-rust-cross@21b0f18dc621b25bfae556ff2791fca4173121e8 # v1
with:
command: build
target: ${{ matrix.platform.target }}
toolchain: ${{ matrix.toolchain }}
args: "--locked --release"
- name: Run tests
if: ${{ !matrix.platform.skip_tests }}
uses: houseabsolute/actions-rust-cross@21b0f18dc621b25bfae556ff2791fca4173121e8 # v1
with:
command: test
target: ${{ matrix.platform.target }}
toolchain: ${{ matrix.toolchain }}
args: "--locked --release"
verify-tag-main-ci-success:
name: Verify tagged commit already passed CI on main
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-24.04
permissions:
actions: read
contents: read
steps:
- name: Check for successful main CI run on this commit
env:
GH_TOKEN: ${{ github.token }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
SHA: ${{ github.sha }}
shell: bash
run: |
set -euo pipefail
api="https://api.github.com/repos/${OWNER}/${REPO}/actions/workflows/ci.yml/runs?event=push&branch=main&head_sha=${SHA}&status=completed&per_page=100"
response="$(
curl --silent --show-error --fail \
--header "Authorization: Bearer ${GH_TOKEN}" \
--header "Accept: application/vnd.github+json" \
"${api}"
)"
successful_run_count="$(
jq '[.workflow_runs[] | select(.head_branch == "main" and .conclusion == "success")] | length' <<<"${response}"
)"
if [[ "${successful_run_count}" -eq 0 ]]; then
echo "No successful CI run on main was found for commit ${SHA}." >&2
echo "Version tags must point at a green main commit." >&2
exit 1
fi
echo "Found a successful main CI run for ${SHA}."
validate-release:
name: Validate tagged release metadata
if: startsWith(github.ref, 'refs/tags/v')
needs: verify-tag-main-ci-success
runs-on: ubuntu-24.04
steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Validate version and changelog
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
manifest_version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)"
if [[ -z "${manifest_version}" ]]; then
echo "Unable to determine package version from Cargo.toml" >&2
exit 1
fi
if [[ "${manifest_version}" != "${version}" ]]; then
echo "Tag ${GITHUB_REF_NAME} does not match Cargo.toml version ${manifest_version}" >&2
exit 1
fi
if [[ ! -f CHANGELOG.md ]]; then
echo "CHANGELOG.md is required for versioned releases" >&2
exit 1
fi
if ! grep -q "^## \[${version}\]" CHANGELOG.md; then
echo "CHANGELOG.md is missing an entry for ${version}" >&2
exit 1
fi
- name: Validate lockfile
run: cargo check --locked
build-release-artifacts:
name: Build release artifact (${{ matrix.platform.name }})
if: >-
always() &&
(
(
github.ref == 'refs/heads/main' &&
needs.lint.result == 'success' &&
needs.test.result == 'success'
) ||
(
startsWith(github.ref, 'refs/tags/v') &&
needs.validate-release.result == 'success'
)
)
needs:
- lint
- test
- validate-release
runs-on: ${{ matrix.platform.runner }}
strategy:
fail-fast: false
matrix:
platform:
- name: Linux-x86_64-musl
kind: linux
arch: amd64
os_name: linux-x86_64-musl
runner: ubuntu-24.04
target: x86_64-unknown-linux-musl
rustflags: ""
- name: Linux-aarch64-musl
kind: linux
arch: arm64
os_name: linux-aarch64-musl
runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-musl
rustflags: ""
- name: macOS-ARM64
kind: native
arch: arm64
os_name: macos-aarch64
runner: macos-latest
target: aarch64-apple-darwin
rustflags: "-C link-arg=-Wl,-dead_strip"
- name: Windows-x86_64
kind: native
arch: amd64
os_name: windows-x86_64
runner: windows-latest
target: x86_64-pc-windows-msvc
rustflags: "-C target-feature=+crt-static"
steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Set up Buildx
if: matrix.platform.kind == 'linux'
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4
- name: Export stripped static Linux binary
if: matrix.platform.kind == 'linux'
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7
with:
context: .
file: Dockerfile
target: release-artifacts
platforms: linux/${{ matrix.platform.arch }}
outputs: type=local,dest=dist/bin
build-args: |
CARGO_BUILD_FLAGS=--locked --release
HUBUUM_CLI_BUILD_CHANNEL=${{ github.ref == 'refs/heads/main' && 'main' || 'release' }}
HUBUUM_CLI_BUILD_GIT_SHA=${{ github.sha }}
cache-from: type=gha,scope=static-${{ matrix.platform.os_name }}
cache-to: type=gha,mode=max,scope=static-${{ matrix.platform.os_name }}
- name: Install stable Rust toolchain
if: matrix.platform.kind == 'native'
uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
with:
targets: ${{ matrix.platform.target }}
- name: Cache cargo and target directories
if: matrix.platform.kind == 'native'
uses: Swatinem/rust-cache@49a0bdc70d2e1b713ca9e2869b211fcce03d3c1c # v2
with:
shared-key: ${{ matrix.platform.target }}-stable-release
- name: Build self-contained native binary
if: matrix.platform.kind == 'native'
env:
HUBUUM_CLI_BUILD_CHANNEL: ${{ github.ref == 'refs/heads/main' && 'main' || 'release' }}
HUBUUM_CLI_BUILD_GIT_SHA: ${{ github.sha }}
RUSTFLAGS: ${{ matrix.platform.rustflags }}
run: cargo build --locked --release --target ${{ matrix.platform.target }}
- name: Verify static linkage and package Linux archive
if: matrix.platform.kind == 'linux'
shell: bash
run: |
set -euo pipefail
binary_path="dist/bin/hubuum-cli"
if readelf --dynamic "${binary_path}" | grep --quiet '(NEEDED)'; then
echo "${binary_path} unexpectedly has dynamic runtime dependencies" >&2
readelf --dynamic "${binary_path}" >&2
exit 1
fi
"${binary_path}" --version
suffix="main"
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
suffix="${GITHUB_REF_NAME}"
fi
archive_name="hubuum-cli-${{ matrix.platform.os_name }}-${suffix}.tar.gz"
tar czf "dist/${archive_name}" -C dist/bin hubuum-cli
(
cd dist
sha256sum "${archive_name}" > "${archive_name}.sha256"
)
- name: Verify macOS runtime dependencies
if: matrix.platform.os_name == 'macos-aarch64'
shell: bash
run: |
set -euo pipefail
binary_path="target/${{ matrix.platform.target }}/release/hubuum-cli"
"${binary_path}" --version
if xcrun otool -L "${binary_path}" | grep --extended-regexp --quiet '(/opt/homebrew|/usr/local|libssl|libcrypto)'; then
echo "${binary_path} unexpectedly depends on a package-manager library" >&2
xcrun otool -L "${binary_path}" >&2
exit 1
fi
- name: Package macOS archive
if: matrix.platform.os_name == 'macos-aarch64'
shell: bash
run: |
set -euo pipefail
suffix="main"
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
suffix="${GITHUB_REF_NAME}"
fi
archive_name="hubuum-cli-${{ matrix.platform.os_name }}-${suffix}.tar.gz"
mkdir -p dist
tar czf "dist/${archive_name}" \
-C "target/${{ matrix.platform.target }}/release" \
hubuum-cli
(
cd dist
shasum -a 256 "${archive_name}" > "${archive_name}.sha256"
)
- name: Verify Windows binary starts
if: matrix.platform.os_name == 'windows-x86_64'
shell: pwsh
run: |
& "target/${{ matrix.platform.target }}/release/hubuum-cli.exe" --version
- name: Package Windows archive
if: matrix.platform.os_name == 'windows-x86_64'
shell: pwsh
run: |
$suffix = "main"
if ($env:GITHUB_REF -like "refs/tags/v*") {
$suffix = $env:GITHUB_REF_NAME
}
$archiveName = "hubuum-cli-${{ matrix.platform.os_name }}-$suffix.zip"
New-Item -ItemType Directory -Path dist -Force | Out-Null
Compress-Archive `
-Path "target/${{ matrix.platform.target }}/release/hubuum-cli.exe" `
-DestinationPath "dist/$archiveName" `
-Force
$hash = (Get-FileHash "dist/$archiveName" -Algorithm SHA256).Hash.ToLower()
[System.IO.File]::WriteAllText(
"dist/$archiveName.sha256",
"$hash $archiveName`n",
[System.Text.UTF8Encoding]::new($false)
)
- name: Upload packaged artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: binaries-${{ matrix.platform.os_name }}
path: |
dist/*.tar.gz
dist/*.zip
dist/*.sha256
if-no-files-found: error
publish-release:
name: Publish release
if: >-
always() &&
needs.build-release-artifacts.result == 'success' &&
(
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/tags/v')
)
needs: build-release-artifacts
runs-on: ubuntu-24.04
permissions:
contents: write
concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
- name: Download packaged artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
pattern: binaries-*
path: dist
merge-multiple: true
- name: Verify artifact checksums
shell: bash
run: |
set -euo pipefail
(
cd dist
sha256sum --check --strict ./*.sha256
)
- name: Move main release tag
if: github.ref == 'refs/heads/main'
shell: bash
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -f main-latest "${GITHUB_SHA}"
git push --force origin refs/tags/main-latest
- name: Write main release notes
if: github.ref == 'refs/heads/main'
shell: bash
run: |
cat <<EOF > RELEASE_NOTES.md
Rolling binaries from the latest successful push to \`main\`.
Commit: ${GITHUB_SHA}
EOF
- name: Extract tagged release notes from changelog
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
awk -v version="${version}" '
$0 ~ "^## \\[" version "\\]" { capture = 1 }
capture && /^## \[/ && $0 !~ "^## \\[" version "\\]" { exit }
capture { print }
' CHANGELOG.md > RELEASE_NOTES.md
if [[ ! -s RELEASE_NOTES.md ]]; then
echo "Failed to extract release notes for ${version}" >&2
exit 1
fi
- name: Publish GitHub release
uses: softprops/action-gh-release@5113cdc90fd4d541c801c55356214017bf5ae34b # v3
with:
tag_name: ${{ github.ref == 'refs/heads/main' && 'main-latest' || github.ref_name }}
name: ${{ github.ref == 'refs/heads/main' && 'main' || github.ref_name }}
body_path: RELEASE_NOTES.md
draft: false
prerelease: false
make_latest: ${{ github.ref == 'refs/heads/main' && 'false' || 'true' }}
overwrite_files: true
fail_on_unmatched_files: true
files: dist/*