Repository navigation
436 lines (382 loc) · 15.6 KB
/
Copy pathrelease.yml
File metadata and controls
436 lines (382 loc) · 15.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
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
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
actions: write
env:
CARGO_TERM_COLOR: always
jobs:
# ── Tests must pass before release ─────────────────────────────
test:
name: Test
runs-on: ubuntu-latest
env:
A3S_DEPS_STUB: "1"
steps:
- uses: actions/checkout@v4
- name: Init submodules
run: git -c http.extraheader= submodule update --init --recursive
- uses: dtolnay/rust-toolchain@stable
- name: Install protoc
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Create stub libkrun for linking
run: |
echo "void krun_stub(void) {}" > /tmp/krun_stub.c
gcc -shared -o /tmp/libkrun.so /tmp/krun_stub.c
sudo cp /tmp/libkrun.so /usr/lib/
sudo ldconfig
- uses: Swatinem/rust-cache@v2
with:
workspaces: src
- run: cd src && cargo test --workspace --lib
# ── Build matrix ───────────────────────────────────────────────
build:
name: Build (${{ matrix.target }})
needs: test
strategy:
matrix:
include:
- target: linux-x86_64
os: ubuntu-latest
rust_target: x86_64-unknown-linux-musl
guest_target: x86_64-unknown-linux-musl
build_cri: true
- target: linux-arm64
os: ubuntu-24.04-arm
rust_target: aarch64-unknown-linux-musl
guest_target: aarch64-unknown-linux-musl
build_cri: true
- target: macos-arm64
os: macos-14
rust_target: ""
guest_target: aarch64-unknown-linux-musl
build_cri: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Init submodules
run: |
git -c http.extraheader= submodule update --init --recursive
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.guest_target }}
- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential pkg-config libssl-dev \
musl-tools libclang-dev patchelf protobuf-compiler
- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew install lld llvm protobuf
pip3 install --break-system-packages ziglang
cargo install cargo-zigbuild
- uses: Swatinem/rust-cache@v2
with:
workspaces: src
key: release-${{ matrix.target }}
- name: Build host binaries
run: |
cd src
cargo build --release -p a3s-box-cli -p a3s-box-shim
if [ "${{ matrix.build_cri }}" = "true" ]; then
cargo build --release -p a3s-box-cri
fi
- name: Build guest binaries
run: |
cd src
if [ "${{ runner.os }}" = "macOS" ]; then
cargo zigbuild --release \
-p a3s-box-guest-init \
--target ${{ matrix.guest_target }}
else
cargo build --release \
-p a3s-box-guest-init \
--target ${{ matrix.guest_target }}
fi
- name: Package release
run: |
TAG="${GITHUB_REF#refs/tags/}"
DIR="a3s-box-${TAG}-${{ matrix.target }}"
mkdir -p "$DIR/lib"
cp src/target/release/a3s-box "$DIR/"
cp src/target/release/a3s-box-shim "$DIR/"
if [ "${{ matrix.build_cri }}" = "true" ]; then
cp src/target/release/a3s-box-cri "$DIR/"
fi
cp "src/target/${{ matrix.guest_target }}/release/a3s-box-guest-init" "$DIR/"
# Find and copy libkrun/libkrunfw shared libraries from build output
BUILD_DIR=$(find src/target/release/build -name "out" -path "*libkrun*" -type d | head -1)
if [ -n "$BUILD_DIR" ]; then
find "$BUILD_DIR" -name "libkrun*" \( -name "*.dylib" -o -name "*.so*" \) -exec cp {} "$DIR/lib/" \;
find "$BUILD_DIR" -name "libkrunfw*" \( -name "*.dylib" -o -name "*.so*" \) -exec cp {} "$DIR/lib/" \;
fi
# Fix rpath for macOS binaries to look in ../lib relative to bin
if [ "${{ runner.os }}" = "macOS" ]; then
for bin in "$DIR/a3s-box" "$DIR/a3s-box-shim"; do
install_name_tool -add_rpath @executable_path/../lib "$bin" 2>/dev/null || true
install_name_tool -add_rpath @executable_path/lib "$bin" 2>/dev/null || true
done
fi
# Fix rpath for Linux binaries
if [ "${{ runner.os }}" = "Linux" ]; then
for bin in "$DIR/a3s-box" "$DIR/a3s-box-shim"; do
patchelf --set-rpath '$ORIGIN/lib' "$bin" 2>/dev/null || true
done
if [ "${{ matrix.build_cri }}" = "true" ]; then
patchelf --set-rpath '$ORIGIN/lib' "$DIR/a3s-box-cri" 2>/dev/null || true
fi
fi
cp README.md "$DIR/" 2>/dev/null || true
cp LICENSE "$DIR/" 2>/dev/null || true
# List package contents
echo "Package contents:"
ls -lhR "$DIR/"
tar czf "${DIR}.tar.gz" "$DIR"
echo "ASSET=${DIR}.tar.gz" >> "$GITHUB_ENV"
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: ${{ env.ASSET }}
# ── Create GitHub Release ──────────────────────────────────────
# ── Windows native WHPX build ──────────────────────────────────
build-windows:
name: Build Windows (WHPX Backend)
needs: [test, build]
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Init submodules
run: git -c http.extraheader= submodule update --init --recursive
- uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-pc-windows-msvc
- uses: Swatinem/rust-cache@v2
with:
workspaces: src
key: release-windows
- name: Build Windows native binaries
run: |
cd src
cargo build --release -p a3s-box-cli -p a3s-box-shim --target x86_64-pc-windows-msvc
- name: Download Linux guest init artifact
uses: actions/download-artifact@v4
with:
name: linux-x86_64
path: linux-x86_64
- name: Package Windows release
shell: bash
run: |
TAG="${GITHUB_REF#refs/tags/}"
DIR="a3s-box-${TAG}-windows-x86_64"
mkdir -p "$DIR/lib"
cp src/target/x86_64-pc-windows-msvc/release/a3s-box.exe "$DIR/"
cp src/target/x86_64-pc-windows-msvc/release/a3s-box-shim.exe "$DIR/"
tar -xzf "linux-x86_64/a3s-box-${TAG}-linux-x86_64.tar.gz" -C linux-x86_64
cp "linux-x86_64/a3s-box-${TAG}-linux-x86_64/a3s-box-guest-init" "$DIR/"
if [ -f "src/target/x86_64-pc-windows-msvc/release/krun.dll" ]; then
cp src/target/x86_64-pc-windows-msvc/release/krun.dll "$DIR/lib/"
elif [ -f "src/deps/libkrun-sys/prebuilt/x86_64-pc-windows-msvc/krun.dll" ]; then
cp src/deps/libkrun-sys/prebuilt/x86_64-pc-windows-msvc/krun.dll "$DIR/lib/"
else
echo "krun.dll is required for the native WHPX package" >&2
exit 1
fi
# Copy README and LICENSE
cp README.md "$DIR/" 2>/dev/null || true
cp LICENSE "$DIR/" 2>/dev/null || true
# List package contents
echo "Package contents:"
ls -lhR "$DIR/"
# Create zip archive (Windows-friendly)
powershell Compress-Archive -Path "$DIR" -DestinationPath "${DIR}.zip"
echo "ASSET=${DIR}.zip" >> "$GITHUB_ENV"
- uses: actions/upload-artifact@v4
with:
name: windows-x86_64
path: ${{ env.ASSET }}
release:
name: GitHub Release
needs: [build, build-windows]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: List artifacts
run: find artifacts -type f
- name: Create release
uses: softprops/action-gh-release@v2
with:
name: ${{ github.ref_name }}
generate_release_notes: true
files: |
artifacts/**/*.tar.gz
artifacts/**/*.zip
# ── Publish to crates.io ───────────────────────────────────────
publish-crates:
name: Publish to crates.io
needs: release
runs-on: ubuntu-latest
env:
A3S_DEPS_STUB: "1"
steps:
- uses: actions/checkout@v4
- name: Init submodules
run: git -c http.extraheader= submodule update --init --recursive
- uses: dtolnay/rust-toolchain@stable
- name: Install protoc
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Create stub libkrun for linking
run: |
echo "void krun_stub(void) {}" > /tmp/krun_stub.c
gcc -shared -o /tmp/libkrun.so /tmp/krun_stub.c
sudo cp /tmp/libkrun.so /usr/lib/
sudo ldconfig
- uses: Swatinem/rust-cache@v2
with:
workspaces: src
- name: Publish crates
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
# NOTE: crates.io is NOT the primary distribution channel — the GitHub
# Release tarballs + Homebrew + winget are. This step is best-effort but
# MUST NOT silently report success on a real failure (it used to:
# `cargo publish || echo "Skipped"` masked 403s / version-requirement
# errors as "may already be published"). Now an already-published
# version is skipped truthfully and a genuine failure is a ::warning::.
run: |
cd src
VERSION="${GITHUB_REF_NAME#v}"
echo "Publishing version $VERSION (in dependency order)"
FAILED=""
# Order matters: a dependent is published AFTER its internal deps so
# the index has them. runtime depends on core + netproxy + libkrun-sys;
# a3s-box-sdk is dependency-free (a thin CLI wrapper) so its position is free.
for crate in a3s-libkrun-sys a3s-box-core a3s-box-netproxy a3s-box-runtime a3s-box-sdk; do
code=$(curl -s -o /dev/null -w '%{http_code}' "https://crates.io/api/v1/crates/$crate/$VERSION")
if [ "$code" = "200" ]; then
echo "✓ $crate@$VERSION already on crates.io — skipping"
continue
fi
echo "Publishing $crate@$VERSION..."
if cargo publish -p "$crate" --allow-dirty; then
echo "✓ published $crate@$VERSION"
sleep 30 # let the sparse index update before dependents publish
else
echo "::warning title=crates.io publish failed::$crate@$VERSION failed (token/auth or version requirement). GitHub Release + Homebrew + winget are unaffected."
FAILED="$FAILED $crate"
fi
done
if [ -n "$FAILED" ]; then
echo "::warning::crates.io publish incomplete for:$FAILED — does NOT block the release; rotate CARGO_REGISTRY_TOKEN / fix version requirements to resolve."
fi
# ── Update Homebrew Formula ────────────────────────────────────
publish-homebrew:
name: Update Homebrew
needs: release
runs-on: ubuntu-latest
steps:
- name: Wait for release assets
run: sleep 15
- name: Extract version
id: version
run: |
TAG="${GITHUB_REF#refs/tags/}"
VERSION="${TAG#v}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Download release tarballs and compute SHA256
run: |
TAG="${{ steps.version.outputs.tag }}"
BASE="https://github.com/${GITHUB_REPOSITORY}/releases/download/${TAG}"
for target in linux-x86_64 linux-arm64 macos-arm64; do
FILE="a3s-box-${TAG}-${target}.tar.gz"
curl -sL "${BASE}/${FILE}" -o "${FILE}"
SHA=$(shasum -a 256 "${FILE}" | awk '{print $1}')
echo "SHA_${target//-/_}=${SHA}" >> "$GITHUB_ENV"
echo "${target}: ${SHA}"
done
- name: Checkout homebrew-tap
uses: actions/checkout@v4
with:
repository: A3S-Lab/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: homebrew-tap
- name: Update formula
run: |
TAG="${{ steps.version.outputs.tag }}"
VERSION="${{ steps.version.outputs.version }}"
REPO="${GITHUB_REPOSITORY}"
cat > homebrew-tap/Formula/a3s-box.rb <<FORMULA
class A3sBox < Formula
desc "MicroVM sandbox runtime with TEE support"
homepage "https://github.com/${REPO}"
version "${VERSION}"
license "MIT"
on_macos do
on_arm do
url "https://github.com/${REPO}/releases/download/${TAG}/a3s-box-${TAG}-macos-arm64.tar.gz"
sha256 "${SHA_macos_arm64}"
end
end
on_linux do
on_arm do
url "https://github.com/${REPO}/releases/download/${TAG}/a3s-box-${TAG}-linux-arm64.tar.gz"
sha256 "${SHA_linux_arm64}"
end
on_intel do
url "https://github.com/${REPO}/releases/download/${TAG}/a3s-box-${TAG}-linux-x86_64.tar.gz"
sha256 "${SHA_linux_x86_64}"
end
end
def install
bin.install "a3s-box"
bin.install "a3s-box-shim"
bin.install "a3s-box-guest-init"
bin.install "a3s-box-cri" if File.exist?("a3s-box-cri")
lib.install Dir["lib/*"] if Dir.exist?("lib")
end
test do
assert_match "a3s-box", shell_output("#{bin}/a3s-box --version")
end
end
FORMULA
# Remove leading whitespace from heredoc
sed -i 's/^ //' homebrew-tap/Formula/a3s-box.rb
- name: Push formula
run: |
cd homebrew-tap
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/a3s-box.rb
git commit -m "chore: update a3s-box to ${{ steps.version.outputs.tag }}"
git push
# ── Trigger winget publishing ───────────────────────────────────
trigger-winget:
name: Trigger winget Publishing
needs: release
runs-on: ubuntu-latest
steps:
- name: Trigger winget workflow
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const tag = context.ref.replace('refs/tags/', '');
const version = tag.replace('v', '');
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'publish-winget.yml',
ref: 'main',
inputs: {
version: version
}
});
console.log(`Triggered winget publishing for version ${version}`);