-
Notifications
You must be signed in to change notification settings - Fork 0
469 lines (396 loc) · 14.3 KB
/
release.yml
File metadata and controls
469 lines (396 loc) · 14.3 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
457
458
459
460
461
462
463
464
465
466
467
468
469
name: Release
on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
dry_run:
description: "Dry run (build artifacts but don't create a release)"
type: boolean
default: true
permissions:
contents: write
packages: write
env:
CARGO_TERM_COLOR: always
jobs:
# Build frontend assets once, share with all build jobs
build-frontend:
name: Build Frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Install UI dependencies
working-directory: ui
run: pnpm install --frozen-lockfile
- name: Generate API client
working-directory: ui
run: pnpm run generate-api
- name: Build UI
working-directory: ui
run: pnpm build
- name: Build Storybook
working-directory: ui
run: pnpm storybook:build
- name: Install docs dependencies
working-directory: docs
run: pnpm install --frozen-lockfile
- name: Build docs
working-directory: docs
run: pnpm build
- name: Upload frontend assets
uses: actions/upload-artifact@v4
with:
name: frontend-assets
path: |
ui/dist/
docs/out/
retention-days: 1
# Build WASM app as a static asset
build-wasm:
name: Build WASM
needs: build-frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Install wasm-pack
run: cargo install wasm-pack@0.13.1 --locked
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
shared-key: wasm
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Install UI dependencies
working-directory: ui
run: pnpm install --frozen-lockfile
- name: Generate API client
working-directory: ui
run: pnpm run generate-api
- name: Build WASM module
run: ./scripts/build-wasm.sh --release
- name: Build frontend (WASM mode)
working-directory: ui
run: pnpm build
env:
VITE_WASM_MODE: "true"
- name: Package WASM app
run: |
mkdir -p artifacts
ARCHIVE="hadrian-wasm.tar.gz"
tar czf "artifacts/$ARCHIVE" -C ui/dist .
(cd artifacts && sha256sum "$ARCHIVE") >> "artifacts/checksums.txt"
echo "Built $ARCHIVE"
ls -lh artifacts/
- name: Upload WASM artifact
uses: actions/upload-artifact@v4
with:
name: build-wasm
path: artifacts/
retention-days: 3
# Build release binaries for each target (all feature profiles per target)
build:
name: Build (${{ matrix.target }})
needs: build-frontend
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
features: "full headless standard minimal tiny"
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
features: "standard minimal tiny"
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
features: "standard minimal tiny"
- target: aarch64-apple-darwin
os: macos-latest
features: "full headless standard minimal tiny"
- target: x86_64-pc-windows-msvc
os: windows-latest
features: "standard minimal tiny"
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install dependencies (Linux full/standard)
if: runner.os == 'Linux' && (contains(matrix.features, 'full') || contains(matrix.features, 'standard'))
run: sudo apt-get update && sudo apt-get install -y libxml2-dev libxslt1-dev libxmlsec1-dev libclang-dev libssl-dev pkg-config
- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: brew install libxml2 libxslt libxmlsec1 llvm
- name: Install musl toolchain
if: matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Install aarch64 cross toolchain
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
shared-key: release-${{ matrix.target }}
- name: Download frontend assets
uses: actions/download-artifact@v4
with:
name: frontend-assets
- name: Fetch model catalog
shell: bash
run: mkdir -p data && curl -sSL https://models.dev/api.json -o data/models-dev-catalog.json
- name: Build and package (Unix)
if: runner.os != 'Windows'
shell: bash
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
run: |
TARGET="${{ matrix.target }}"
mkdir -p staging artifacts
for feature in ${{ matrix.features }}; do
echo "::group::Building $feature for $TARGET"
cargo build --release --target "$TARGET" --no-default-features --features "$feature"
echo "::endgroup::"
cp "target/$TARGET/release/hadrian" staging/hadrian
ARCHIVE="hadrian-${TARGET}-${feature}.tar.gz"
tar czf "artifacts/$ARCHIVE" -C staging hadrian
rm staging/hadrian
(cd artifacts && sha256sum "$ARCHIVE") >> "artifacts/checksums.txt"
echo "Built $ARCHIVE"
done
- name: Build and package (Windows)
if: runner.os == 'Windows'
shell: bash
env:
TARGET: ${{ matrix.target }}
run: |
mkdir -p staging artifacts
for feature in ${{ matrix.features }}; do
echo "::group::Building $feature for $TARGET"
cargo build --release --target "$TARGET" --no-default-features --features "$feature"
echo "::endgroup::"
cp "target/$TARGET/release/hadrian.exe" staging/hadrian.exe
ARCHIVE="hadrian-${TARGET}-${feature}.zip"
cd staging && 7z a -tzip "../artifacts/$ARCHIVE" hadrian.exe && cd ..
rm staging/hadrian.exe
(cd artifacts && sha256sum "$ARCHIVE") >> "artifacts/checksums.txt"
echo "Built $ARCHIVE"
done
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.target }}
path: artifacts/
retention-days: 3
# Create GitHub Release (only on tag push, not dry-run)
release:
name: Create Release
needs: [build, build-wasm]
if: github.ref_type == 'tag' && !(github.event_name == 'workflow_dispatch' && inputs.dry_run)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download all build artifacts
uses: actions/download-artifact@v4
with:
pattern: build-*
path: all-artifacts
merge-multiple: false
- name: Collect release assets
run: |
mkdir -p release
# Move all archives to release dir and merge checksums
for dir in all-artifacts/build-*/; do
if [ -d "$dir" ]; then
mv "$dir"/*.tar.gz release/ 2>/dev/null || true
mv "$dir"/*.zip release/ 2>/dev/null || true
cat "$dir/checksums.txt" >> release/hadrian-checksums-sha256.txt 2>/dev/null || true
fi
done
echo "Release assets:"
ls -lh release/
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
files: release/*
# Publish to crates.io (only on tag push, not dry-run)
publish-crate:
name: Publish to crates.io
if: github.ref_type == 'tag' && !(github.event_name == 'workflow_dispatch' && inputs.dry_run)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
shared-key: publish
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libxml2-dev libxslt1-dev libxmlsec1-dev libclang-dev tesseract-ocr tesseract-ocr-eng
- name: Publish to crates.io
run: cargo publish --no-default-features --features headless --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
# Build per-platform Docker images on native runners (no QEMU emulation)
docker:
name: Docker (${{ matrix.suffix }})
if: github.ref_type == 'tag' && !(github.event_name == 'workflow_dispatch' && inputs.dry_run)
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
suffix: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
suffix: arm64
steps:
- uses: actions/checkout@v4
- name: Lowercase image name
id: image
run: echo "name=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.image.outputs.name }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
push: true
tags: ${{ steps.image.outputs.name }}:${{ github.ref_name }}-${{ matrix.suffix }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ matrix.suffix }}
cache-to: type=gha,mode=max,scope=${{ matrix.suffix }}
# Combine per-platform images into a multi-arch manifest
docker-manifest:
name: Docker Manifest
needs: docker
if: github.ref_type == 'tag' && !(github.event_name == 'workflow_dispatch' && inputs.dry_run)
runs-on: ubuntu-latest
steps:
- name: Lowercase image name
id: image
run: echo "name=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.image.outputs.name }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=raw,value=latest
- name: Create and push multi-arch manifests
env:
TAGS: ${{ steps.meta.outputs.tags }}
run: |
IMAGE="${{ steps.image.outputs.name }}"
TAG="${GITHUB_REF_NAME}"
while IFS= read -r tag; do
[ -z "$tag" ] && continue
docker buildx imagetools create -t "$tag" \
"${IMAGE}:${TAG}-amd64" \
"${IMAGE}:${TAG}-arm64"
done <<< "$TAGS"
# Build Docker images without pushing (dry-run validation)
docker-dry-run:
name: Docker Dry Run (${{ matrix.suffix }})
if: github.event_name == 'workflow_dispatch' && inputs.dry_run
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
suffix: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
suffix: arm64
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Build (no push)
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
push: false
cache-from: type=gha,scope=${{ matrix.suffix }}
cache-to: type=gha,mode=max,scope=${{ matrix.suffix }}
# Dry-run summary (manual dispatch with dry_run=true)
dry-run-summary:
name: Dry Run Summary
needs: [build, build-wasm, docker-dry-run]
if: github.event_name == 'workflow_dispatch' && inputs.dry_run
runs-on: ubuntu-latest
steps:
- name: Download all build artifacts
uses: actions/download-artifact@v4
with:
pattern: build-*
path: all-artifacts
merge-multiple: false
- name: Print summary
run: |
echo "## Dry Run Results" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "| Artifact | Size | SHA256 |" >> "$GITHUB_STEP_SUMMARY"
echo "|----------|------|--------|" >> "$GITHUB_STEP_SUMMARY"
for dir in all-artifacts/build-*/; do
if [ -f "$dir/checksums.txt" ]; then
while read -r line; do
hash="${line%% *}"
name="${line##* }"
size=$(stat --printf="%s" "$dir/$name" 2>/dev/null || echo "?")
if [ "$size" != "?" ]; then
human_size=$(numfmt --to=iec-i --suffix=B "$size")
else
human_size="?"
fi
echo "| \`$name\` | $human_size | \`${hash:0:16}...\` |" >> "$GITHUB_STEP_SUMMARY"
done < "$dir/checksums.txt"
fi
done
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "No release was created (dry run mode)." >> "$GITHUB_STEP_SUMMARY"