Files
unkernel/.github/workflows/release-x64.yml

314 lines
12 KiB
YAML

name: Release x64
on:
push:
tags: ["v*-x64.*"]
workflow_dispatch:
inputs:
tag:
description: Release tag (e.g. v0.2.0-261127-3b71fa5-x64.1; leave empty for smoke build)
type: string
default: ""
release:
description: Create tag and publish GitHub Release
type: boolean
default: false
permissions:
contents: read
concurrency:
group: release-x64-${{ github.ref }}
cancel-in-progress: false
defaults:
run:
shell: bash
jobs:
guard:
name: Validate x64-main ref and release tag
runs-on: ubuntu-24.04
timeout-minutes: 5
outputs:
tag: ${{ steps.check.outputs.tag }}
release: ${{ steps.check.outputs.release }}
steps:
- name: Check branch or tag ancestry
id: check
env:
GH_TOKEN: ${{ github.token }}
INPUT_TAG: ${{ inputs.tag }}
INPUT_RELEASE: ${{ inputs.release }}
run: |
case "$GITHUB_REF" in
refs/heads/x64-main)
release="${INPUT_RELEASE:-false}"
tag="${INPUT_TAG}"
if [ "$release" = true ] && [ -z "$tag" ]; then
echo "::error::tag input is required when release=true on x64-main"
exit 1
fi
if [ -z "$tag" ]; then
tag="smoke-${GITHUB_SHA::7}"
fi
;;
refs/tags/v*-x64.*)
status="$(gh api "repos/$GITHUB_REPOSITORY/compare/x64-main...$GITHUB_SHA" --jq .status)"
case "$status" in
identical | behind) ;;
*) echo "::error::$GITHUB_REF_NAME ($GITHUB_SHA) is not on x64-main (compare: $status)"; exit 1 ;;
esac
tag="$GITHUB_REF_NAME"
release=true
;;
*)
echo "::error::release-x64 runs only on x64-main or v*-x64.* tags, not $GITHUB_REF"
exit 1
;;
esac
if [ "$release" = true ]; then
if [[ ! "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?-x64\.[1-9][0-9]*$ ]]; then
echo "::error::tag '$tag' must match v<upstream-tag>-x64.<seq>"
exit 1
fi
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "release=$release" >> "$GITHUB_OUTPUT"
build:
name: Build and verify on x86-64
needs: guard
runs-on: ${{ vars.RELEASE_RUNNER || 'ubuntu-24.04' }}
timeout-minutes: 240
env:
KW_RELEASE: "1"
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
persist-credentials: false
- name: Install clang 22 and host tools
run: |
sudo install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/keyrings/apt.llvm.org.asc >/dev/null
echo "deb [signed-by=/etc/apt/keyrings/apt.llvm.org.asc] http://apt.llvm.org/noble/ llvm-toolchain-noble-22 main" |
sudo tee /etc/apt/sources.list.d/llvm-22.list >/dev/null
sudo apt-get update -q
sudo apt-get install -y -q --no-install-recommends \
clang-22 lld-22 llvm-22 cmake ninja-build flex bison bc m4 e2fsprogs patch meson pkg-config gcc-multilib
echo /usr/lib/llvm-22/bin >> "$GITHUB_PATH"
- uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29
with:
version: 0.16.0
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1
with:
node-version: 26
package-manager-cache: false
- uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115
with:
cache: true
- name: Check prerequisites and install JS deps
run: |
./setup.sh --check
pnpm install --frozen-lockfile
- name: Cache keys
id: keys
run: |
{
echo "linux=$(sed -n 's/^LINUX_BASE=//p' kernel/build.sh)"
echo "llvm=$(sed -n 's/^LLVM_COMMIT=//p' kernel/build.sh)"
echo "clang=$(clang --version | head -1 | sha256sum | cut -c1-16)"
} >> "$GITHUB_OUTPUT"
- name: Restore toolchain
id: toolchain
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
with:
path: |
vendor/build/lld22/bin/lld
vendor/toolchain/bin
key: toolchain-${{ runner.os }}-${{ steps.keys.outputs.llvm }}-${{ hashFiles('kernel/patches/llvm/**') }}
- name: Build patched wasm-ld
if: steps.toolchain.outputs.cache-hit != 'true'
run: kernel/build.sh toolchain
- name: Save toolchain
if: steps.toolchain.outputs.cache-hit != 'true'
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
with:
path: |
vendor/build/lld22/bin/lld
vendor/toolchain/bin
key: ${{ steps.toolchain.outputs.cache-primary-key }}
- name: Restore downloads
id: downloads
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
with:
path: vendor/downloads
key: x64-downloads-${{ hashFiles('kernel/tools/env.sh', 'kernel/build.sh', 'guest/**/pins.sh') }}
restore-keys: x64-downloads-
- name: Fetch Binaryen
run: KW_ARCH=x64 kernel/build.sh binaryen
- name: Run kwemu x64 unit, JIT, and lockstep tests
run: |
PATH="$PWD/vendor/toolchain/binaryen/bin:$PATH" zig build test -Dkwemu-arch=x64 -j"$(nproc)"
- name: Build kwemu-x64 UP and SMP libraries
run: |
zig build -Dkwemu-arch=x64 -Dkwemu-jit=true -Dcpu=baseline --prefix vendor/build/kwemu-x64
zig build -Dkwemu-arch=x64 -Dkwemu-jit=true -Dkwemu-atomics=true -Dcpu=baseline --prefix vendor/build/kwemu-x64-smp
- name: Restore Linux x64 tree
id: linux-src
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
with:
path: vendor/src/linux-wasm-kernel
key: x64-linux-src-${{ steps.keys.outputs.linux }}-${{ hashFiles('kernel/patches/linux/**', 'kernel/patches/linux-x64/**') }}
- name: Restore Linux x64 build
id: kernel-out
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
with:
path: |
vendor/build/kernel-x64
vendor/build/kernel-x64-smp
key: x64-kernel-out-${{ steps.keys.outputs.clang }}-${{ hashFiles('kernel/patches/linux/**', 'kernel/patches/linux-x64/**', 'kernel/tools/fake-llvm/**') }}-${{ hashFiles('src/**', 'include/**', 'build.zig', 'build.zig.zon', 'kernel/build.sh') }}
- name: Clean mismatched kernel build
if: steps.linux-src.outputs.cache-hit != 'true'
run: rm -rf vendor/build/kernel-x64 vendor/build/kernel-x64-smp
- name: Build UP and SMP x64 kernels
env:
KW_ARCH: x64
KWEMU: ${{ github.workspace }}/vendor/build/kwemu-x64/lib/libkwemu.a
KWEMU_SMP: ${{ github.workspace }}/vendor/build/kwemu-x64-smp/lib/libkwemu.a
run: |
kernel/build.sh kernel
kernel/build.sh smp
- name: Save Linux x64 tree
if: steps.linux-src.outputs.cache-hit != 'true'
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
with:
path: vendor/src/linux-wasm-kernel
key: ${{ steps.linux-src.outputs.cache-primary-key }}
- name: Save Linux x64 build
if: steps.kernel-out.outputs.cache-hit != 'true'
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
with:
path: |
vendor/build/kernel-x64
vendor/build/kernel-x64-smp
key: ${{ steps.kernel-out.outputs.cache-primary-key }}
- name: Build data disk template and base bundle
env:
KW_ARCH: x64
KW_SMP: "1"
run: |
kernel/build.sh datadisk
kernel/build.sh base
ls -lh vendor/build/bundle-x64/unkernel.wasm vendor/build/initramfs-x64/base.cpio vendor/build/initramfs-x64/base-test.cpio
- name: Save downloads
if: steps.downloads.outputs.cache-hit != 'true'
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
with:
path: vendor/downloads
key: ${{ steps.downloads.outputs.cache-primary-key }}
- name: Run abitest, abitest32, and kwtest (UP and SMP)
run: |
for cpus in 1 4; do
rc=0
node js/cli.ts --timeout 300 --cpus "$cpus" --kernel vendor/build/bundle-x64/unkernel.wasm \
--initrd vendor/build/initramfs-x64/base-test.cpio \
--append "console=hvc0 rdinit=/usr/bin/abitest" --exit 1 </dev/null > abitest.log 2>&1 || rc=$?
cat abitest.log
test "$rc" -eq 0 -o "$rc" -eq 253
grep -q 'abitest x86_64: 0x00000000 failure(s)' abitest.log
grep -q 'abitest32 i386: 0x00000000 failure(s)' abitest.log
grep -q 'exitcode=0x00000000' abitest.log
rc=0
node js/cli.ts --timeout 300 --cpus "$cpus" --kernel vendor/build/bundle-x64/unkernel.wasm \
--initrd vendor/build/initramfs-x64/base-test.cpio \
--append "console=hvc0 rdinit=/usr/bin/abitest32" --exit 1 </dev/null > abitest32.log 2>&1 || rc=$?
cat abitest32.log
test "$rc" -eq 0 -o "$rc" -eq 253
grep -q 'abitest32 i386: 0x00000000 failure(s)' abitest32.log
grep -q 'exitcode=0x00000000' abitest32.log
node js/cli.ts --timeout 600 --cpus "$cpus" --kernel vendor/build/bundle-x64/unkernel.wasm \
--initrd vendor/build/initramfs-x64/base-test.cpio \
--append "console=hvc0 rdinit=/usr/bin/kwtest" --exit 1 </dev/null > kwtest.log 2>&1
cat kwtest.log
grep -q 'kwtest: 0 failure(s)' kwtest.log
done
- name: Pack release artifacts
run: |
mkdir -p out
cp vendor/build/bundle-x64/unkernel.wasm out/unkernel.wasm
(cd out && sha256sum unkernel.wasm > SHA256SUMS)
cat out/SHA256SUMS
ls -lh out/
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
with:
name: release-x64
path: out/
if-no-files-found: error
release:
name: Tag and publish GitHub Release
needs: [guard, build]
if: needs.guard.outputs.release == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
contents: write
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333
with:
name: release-x64
path: out
- name: Create tag if needed
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.guard.outputs.tag }}
run: |
if gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$TAG" --silent 2>/dev/null; then
echo "$TAG exists"
else
gh api "repos/$GITHUB_REPOSITORY/git/refs" -f ref="refs/tags/$TAG" -f sha="$GITHUB_SHA" --silent
fi
- name: Publish GitHub Release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.guard.outputs.tag }}
run: |
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
for f in out/*; do
gh release upload "$TAG" "$f" --repo "$GITHUB_REPOSITORY" --clobber
done
else
gh release create "$TAG" out/unkernel.wasm out/SHA256SUMS --repo "$GITHUB_REPOSITORY" \
--latest --verify-tag --title "$TAG" \
--notes "Native x86-64-v3 + i386 (IA32_EMULATION) UP+SMP unkernel.wasm bundle."
fi