mirror of
https://github.com/pithings/unkernel.git
synced 2026-12-02 00:59:32 +08:00
553 lines
26 KiB
YAML
553 lines
26 KiB
YAML
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
# Copyright (C) 2026 Pooya Parsa <pooya@pi0.io>
|
|
#
|
|
# Release: build everything from source (patched wasm-ld, the UP and SMP
|
|
# kernels, the data disk template, the base bundle unkernel.wasm with its
|
|
# SMP patch, the distro images alpine.erofs and debian.erofs and their
|
|
# index distros.json), the guest GL renderer (gl/wasm, virgl.wasm) and
|
|
# the guest Vulkan renderer's translator (vk/naga, kwvk-naga.wasm),
|
|
# smoke-test it, build and pack the npm package (the base bundle, the
|
|
# GL renderer and the translator, no distro image), and for a release publish it to npm
|
|
# (trusted publishing, with provenance) and publish a GitHub release (a
|
|
# normal one, marked latest, its notes a compare link from the previous
|
|
# v* tag) with the npm tarball, unkernel.wasm, distros.json, the images
|
|
# it names, the GL renderer (virgl.mjs, virgl.wasm) and the Vulkan
|
|
# translator (kwvk-naga.wasm) attached, and the page's own files
|
|
# (unkernel-up.wasm and unkernel-smp.wasm, the bundle's two kernels, a
|
|
# gzipped copy of every .wasm, <file>.wasm.gz, and page.json, which lists
|
|
# what the page loads: web/scripts/page-assets.ts), for a page that loads
|
|
# them from a CORS mirror of the assets. The SDK's
|
|
# fetchDistro() and the page's build (web/scripts/kernel.ts) download those
|
|
# assets by the tag v<version>, the version stamped into package.json (the
|
|
# page takes the GL renderer for its GL option and the translator for its
|
|
# Vulkan option).
|
|
#
|
|
# Runs:
|
|
# - by hand from main (Actions > Release > Run workflow): a release with
|
|
# a generated version <package.json version>-<YYMMDD>-<commit>, e.g.
|
|
# 0.2.0-261120-7e36b21 (the commit's UTC date and short hash). After the
|
|
# build passes it tags the commit v<version>. Unchecking "release" makes
|
|
# it a smoke run (same build and version, no tag or release).
|
|
# - on a pushed tag v<version> that points at a commit on main: a release
|
|
# of that version
|
|
# Any other ref is refused before anything is built or any cache is touched.
|
|
# The version is stamped into package.json before the package is built and
|
|
# packed. A tag the workflow creates (with GITHUB_TOKEN) does not start it
|
|
# again.
|
|
#
|
|
# Caches (all restored and saved explicitly, so an expensive step is kept
|
|
# even when a later step fails):
|
|
# toolchain the patched wasm-ld (~1 h to build on a 2-core runner);
|
|
# key: LLVM commit, kernel/patches/llvm
|
|
# linux-src the patched kernel tree; key: base commit, kernel/patches/linux
|
|
# kernel-out the UP and SMP kernel build directories, reused only with
|
|
# the same tree (same patches, clang and fake-llvm wrapper), so
|
|
# Kbuild rebuilds incrementally and never from a different source
|
|
# downloads Binaryen, the base's busybox, the Alpine and Debian root file
|
|
# systems, erofs-utils, lz4 and zstd (checksums are verified
|
|
# anyway); key: env.sh, build.sh and the guest's pins
|
|
# (guest/**/pins.sh)
|
|
# zig, pnpm by their setup actions
|
|
name: Release
|
|
|
|
on:
|
|
push:
|
|
tags: ["v*"]
|
|
workflow_dispatch:
|
|
inputs:
|
|
release:
|
|
description: Tag this commit v<version>-<YYMMDD>-<commit> and publish a GitHub release (unchecked = smoke run)
|
|
type: boolean
|
|
default: true
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: release-${{ github.ref }}
|
|
cancel-in-progress: false
|
|
|
|
defaults:
|
|
run:
|
|
shell: bash
|
|
|
|
jobs:
|
|
guard:
|
|
name: Check the ref is on main
|
|
runs-on: ubuntu-24.04
|
|
timeout-minutes: 5
|
|
outputs:
|
|
version: ${{ steps.check.outputs.version }}
|
|
release: ${{ steps.check.outputs.release }}
|
|
steps:
|
|
- name: Refuse refs that are not main or a tag on main; pick the version
|
|
id: check
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
RELEASE_INPUT: ${{ inputs.release }}
|
|
run: |
|
|
case "$GITHUB_REF" in
|
|
refs/heads/main)
|
|
base="$(gh api "repos/$GITHUB_REPOSITORY/contents/package.json?ref=$GITHUB_SHA" \
|
|
-H "Accept: application/vnd.github.raw" | jq -r .version)"
|
|
date="$(date -u -d "$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA" --jq .commit.committer.date)" +%y%m%d)"
|
|
# One prerelease identifier (hyphens do not split it), so a commit
|
|
# like 0123456 is fine, and same-base versions sort by date.
|
|
version="$base-$date-${GITHUB_SHA::7}"
|
|
release="${RELEASE_INPUT:-true}"
|
|
if [ "$release" = true ] && gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/v$version" --silent 2>/dev/null; then
|
|
echo "::error::tag v$version exists already: this commit has been released"
|
|
exit 1
|
|
fi
|
|
;;
|
|
refs/tags/v*)
|
|
# "identical" or "behind": the tagged commit is main or an ancestor of it.
|
|
status="$(gh api "repos/$GITHUB_REPOSITORY/compare/main...$GITHUB_SHA" --jq .status)"
|
|
case "$status" in
|
|
identical | behind) ;;
|
|
*) echo "::error::$GITHUB_REF_NAME ($GITHUB_SHA) is not on main (compare: $status)"; exit 1 ;;
|
|
esac
|
|
version="${GITHUB_REF_NAME#v}"
|
|
release=true
|
|
;;
|
|
*) echo "::error::releases run only from main or a v* tag on main, not $GITHUB_REF"; exit 1 ;;
|
|
esac
|
|
# semver (npm rejects anything else), as in semver.org's regular expression
|
|
n='(0|[1-9][0-9]*)' id='(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)'
|
|
[[ "$version" =~ ^$n\.$n\.$n(-$id(\.$id)*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$ ]] ||
|
|
{ echo "::error::$version is not a semver version"; exit 1; }
|
|
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
echo "release=$release" >> "$GITHUB_OUTPUT"
|
|
echo "ok: $GITHUB_REF ($GITHUB_SHA), $([ "$release" = true ] && echo "release" || echo "smoke run") of $version"
|
|
|
|
build:
|
|
name: Build and smoke-test
|
|
needs: guard
|
|
# The repository variable RELEASE_RUNNER names a larger runner (more
|
|
# cores for the wasm-ld and kernel builds), if one is set up.
|
|
runs-on: ${{ vars.RELEASE_RUNNER || 'ubuntu-24.04' }}
|
|
timeout-minutes: 240
|
|
env:
|
|
# The base build then writes base.cpio, which the bundle gets, without
|
|
# kwtest, abitest and kwbench. The kwtest steps boot this bundle's
|
|
# kernel with base-test.cpio instead: the same initramfs plus the test
|
|
# programs.
|
|
KW_RELEASE: "1"
|
|
steps:
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
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
|
|
echo /usr/lib/llvm-22/bin >> "$GITHUB_PATH"
|
|
|
|
- uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2.2.1
|
|
with:
|
|
version: 0.16.0
|
|
|
|
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
|
with:
|
|
node-version: 26
|
|
package-manager-cache: false
|
|
|
|
- uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
|
|
with:
|
|
cache: true
|
|
|
|
- name: Check prerequisites
|
|
run: ./setup.sh --check
|
|
|
|
- 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"
|
|
|
|
# Patched wasm-ld. With vendor/toolchain/bin/wasm-ld present, build.sh
|
|
# skips the toolchain step; lld is linked statically against LLVM.
|
|
# The key leaves out the clang version: apt.llvm.org rebuilds change
|
|
# it often, and which clang compiled the linker does not matter.
|
|
- name: Restore toolchain
|
|
id: toolchain
|
|
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
|
with:
|
|
path: |
|
|
vendor/build/lld22/bin/lld
|
|
vendor/toolchain/bin
|
|
key: toolchain-${{ runner.os }}-${{ steps.keys.outputs.llvm }}-${{ hashFiles('kernel/patches/llvm/**') }}
|
|
# The earlier key (with the clang version), only while that cache exists.
|
|
restore-keys: toolchain-${{ runner.os }}-${{ steps.keys.outputs.llvm }}-${{ steps.keys.outputs.clang }}-${{ hashFiles('kernel/patches/llvm/**') }}
|
|
- name: Build the patched wasm-ld
|
|
if: steps.toolchain.outputs.cache-hit != 'true'
|
|
run: |
|
|
if [ -x vendor/toolchain/bin/wasm-ld ]; then
|
|
echo "restored from ${{ steps.toolchain.outputs.cache-matched-key }}"
|
|
else
|
|
kernel/build.sh toolchain
|
|
fi
|
|
- name: Save toolchain
|
|
if: steps.toolchain.outputs.cache-hit != 'true'
|
|
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
|
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 # v6.1.0
|
|
with:
|
|
path: vendor/downloads
|
|
key: downloads-${{ hashFiles('kernel/tools/env.sh', 'kernel/build.sh', 'guest/**/pins.sh', 'gl/wasm/pins.sh', 'vk/pins.sh') }}
|
|
restore-keys: downloads-
|
|
|
|
# Exact key only: build.sh never re-applies the series on an existing
|
|
# kw-arm64-user branch, so a tree with other patches must not be restored.
|
|
- name: Restore the kernel tree
|
|
id: linux-src
|
|
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
|
with:
|
|
path: vendor/src/linux-wasm-kernel
|
|
key: linux-src-${{ steps.keys.outputs.linux }}-${{ hashFiles('kernel/patches/linux/**') }}
|
|
|
|
# Only from a build of the same tree (exact linux-src key above), so
|
|
# file times order correctly and make rebuilds what changed.
|
|
- name: Restore the kernel build
|
|
id: kernel-out
|
|
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
|
with:
|
|
path: |
|
|
vendor/build/kernel
|
|
vendor/build/kernel-smp
|
|
key: kernel-out-${{ steps.keys.outputs.clang }}-${{ hashFiles('kernel/patches/linux/**', 'kernel/tools/fake-llvm/**') }}-${{ hashFiles('src/**', 'include/**', 'build.zig', 'build.zig.zon', 'kernel/build.sh') }}
|
|
restore-keys: kernel-out-${{ steps.keys.outputs.clang }}-${{ hashFiles('kernel/patches/linux/**', 'kernel/tools/fake-llvm/**') }}-
|
|
|
|
- name: Drop a kernel build that does not match the tree
|
|
if: steps.linux-src.outputs.cache-hit != 'true'
|
|
run: rm -rf vendor/build/kernel vendor/build/kernel-smp
|
|
|
|
# build.sh would run `zig build` itself, whose native artifacts (unused
|
|
# here) target the runner's CPU, and hosted runners vary in CPU model,
|
|
# which invalidates that part of the zig cache. Build for a baseline
|
|
# CPU instead and hand build.sh the library.
|
|
- name: Build kwemu
|
|
run: |
|
|
zig build -Dkwemu-jit=true -Dcpu=baseline
|
|
zig build -Dkwemu-jit=true -Dkwemu-atomics=true -Dcpu=baseline --prefix vendor/build/kwemu-smp
|
|
|
|
# Both kernels of the one tree: the bundle carries the UP kernel and a
|
|
# patch to the SMP one (kernel/build.sh, bundle.mjs --smp).
|
|
- name: Build the kernels
|
|
env:
|
|
KWEMU: ${{ github.workspace }}/zig-out/lib/libkwemu.a
|
|
KWEMU_SMP: ${{ github.workspace }}/vendor/build/kwemu-smp/lib/libkwemu.a
|
|
run: |
|
|
kernel/build.sh kernel
|
|
kernel/build.sh smp
|
|
|
|
- name: Save the kernel tree
|
|
if: steps.linux-src.outputs.cache-hit != 'true'
|
|
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
|
with:
|
|
path: vendor/src/linux-wasm-kernel
|
|
key: ${{ steps.linux-src.outputs.cache-primary-key }}
|
|
- name: Save the kernel build
|
|
if: steps.kernel-out.outputs.cache-hit != 'true'
|
|
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
|
with:
|
|
path: |
|
|
vendor/build/kernel
|
|
vendor/build/kernel-smp
|
|
key: ${{ steps.kernel-out.outputs.cache-primary-key }}
|
|
|
|
# The distro images' build runs the SDK from source (the Debian image
|
|
# boots on the base bundle at build time: guest/tools/vm-run.ts).
|
|
- name: Install npm dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
# The template first: the base bundle carries it.
|
|
- name: Build the data disk template and the base bundle
|
|
env:
|
|
KW_SMP: "1" # the bundle must carry the SMP patch
|
|
run: |
|
|
kernel/build.sh datadisk
|
|
kernel/build.sh base
|
|
ls -l vendor/build/bundle/unkernel.wasm vendor/build/initramfs/base.cpio vendor/build/initramfs/base-test.cpio
|
|
sha256sum vendor/build/bundle/unkernel.wasm
|
|
|
|
# alpine.erofs and debian.erofs (and .ext4, not released), their ids
|
|
# and distros.json, after the base bundle: the Debian image boots on it
|
|
# to make apt's source cache, and distros.json takes its ABI and base
|
|
# id from it. Network only for the pinned downloads.
|
|
- name: Build the distro images
|
|
run: |
|
|
kernel/build.sh distro 2>&1 | tee distro.log
|
|
if grep -q "has no apt cache" distro.log; then
|
|
echo "::error::the Debian image was built without apt's cache"
|
|
exit 1
|
|
fi
|
|
cat vendor/build/distro/distros.json
|
|
# shellcheck disable=SC2016 # JavaScript, not shell
|
|
node -e '
|
|
const fs = require("node:fs"), crypto = require("node:crypto");
|
|
const j = JSON.parse(fs.readFileSync("vendor/build/distro/distros.json", "utf8"));
|
|
const want = Number(/^#define KW_ABI_VERSION (\d+)$/m.exec(fs.readFileSync("include/kw_emu.h", "utf8"))[1]);
|
|
const fail = (m) => { console.log(`::error::distros.json: ${m}`); process.exit(1); };
|
|
if (j.abi !== want) fail(`abi ${j.abi}, include/kw_emu.h has ${want}`);
|
|
if (!j.base) fail("no base id");
|
|
const names = j.distros.map((d) => d.name).sort().join(",");
|
|
if (names !== "alpine,debian") fail(`distros ${names}, expected alpine,debian`);
|
|
for (const d of j.distros) {
|
|
if (!/^[a-z0-9]+\.erofs$/.test(d.file)) fail(`${d.name}: ${d.file} is not an erofs image`);
|
|
const b = fs.readFileSync(`vendor/build/distro/${d.file}`);
|
|
const sum = crypto.createHash("sha256").update(b).digest("hex");
|
|
if (b.length !== d.size || sum !== d.sha256) fail(`${d.file}: ${b.length} bytes, ${sum}`);
|
|
if (!d.image) fail(`${d.name}: no image id`);
|
|
}
|
|
console.log(`ok: abi ${j.abi}, ${j.base}, ${j.distros.map((d) => `${d.file} ${d.image}`).join(", ")}`);
|
|
'
|
|
|
|
# The guest GL renderer the package carries (dist/virgl.mjs and
|
|
# virgl.wasm): emscripten and virglrenderer, both pinned (gl/wasm/pins.sh;
|
|
# emscripten goes into the downloads cache).
|
|
- name: Build the GL renderer
|
|
run: |
|
|
gl/wasm/build.sh
|
|
ls -l vendor/build/gl-wasm/virgl.mjs vendor/build/gl-wasm/virgl.wasm
|
|
|
|
# The guest Vulkan renderer's SPIR-V to WGSL translator the package
|
|
# carries (dist/kwvk-naga.wasm): naga for wasm32, its crates pinned by
|
|
# vk/naga/Cargo.lock (the runner's rustup). The base above carries the
|
|
# ICD (vk/build.sh icd: zig and the Vulkan headers pinned in vk/pins.sh,
|
|
# which go into the downloads cache).
|
|
- name: Build the Vulkan translator
|
|
run: |
|
|
rustup target add wasm32-unknown-unknown
|
|
vk/build.sh naga
|
|
ls -l vendor/build/vk/kwvk-naga.wasm
|
|
|
|
- name: Save downloads
|
|
if: steps.downloads.outputs.cache-hit != 'true'
|
|
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
|
with:
|
|
path: vendor/downloads
|
|
key: ${{ steps.downloads.outputs.cache-primary-key }}
|
|
|
|
# The kernel tests boot the base bundle's kernel with base-test.cpio
|
|
# (no distro image): the test program is PID 1.
|
|
- name: kwtest (JIT)
|
|
run: |
|
|
node js/cli.ts --timeout 600 --kernel vendor/build/bundle/unkernel.wasm --initrd base-test \
|
|
--append "console=hvc0 rdinit=/usr/bin/kwtest" </dev/null | tee kwtest.log
|
|
grep -q 'kwtest: 0 failure(s)' kwtest.log
|
|
- name: kwtest (no JIT)
|
|
run: |
|
|
node js/cli.ts --timeout 900 --no-jit --kernel vendor/build/bundle/unkernel.wasm --initrd base-test \
|
|
--append "console=hvc0 rdinit=/usr/bin/kwtest" </dev/null | tee kwtest.log
|
|
grep -q 'kwtest: 0 failure(s)' kwtest.log
|
|
|
|
- name: kwtest (SMP, 2 CPUs)
|
|
run: |
|
|
node js/cli.ts --timeout 900 --smp 2 --kernel vendor/build/bundle/unkernel.wasm --initrd base-test \
|
|
--append "console=hvc0 rdinit=/usr/bin/kwtest" </dev/null | tee kwtest.log
|
|
grep -q 'kwtest: 0 failure(s)' kwtest.log
|
|
|
|
# The arm64 user ABI without a libc (guest/src/test/abitest.c), on the
|
|
# UP kernel and on the SMP kernel with 2 CPUs.
|
|
- name: abitest (UP, SMP)
|
|
run: |
|
|
for cpus in 1 2; do
|
|
node js/cli.ts --timeout 300 --smp "$cpus" --kernel vendor/build/bundle/unkernel.wasm --initrd base-test \
|
|
--append "console=hvc0 rdinit=/usr/bin/abitest" </dev/null | tee abitest.log
|
|
grep -q 'abitest: 0 failure(s)' abitest.log
|
|
done
|
|
|
|
- name: Typecheck
|
|
run: |
|
|
pnpm typecheck
|
|
pnpm typecheck:web
|
|
- name: Kernel patch tests
|
|
env:
|
|
KPATCH_UP: vendor/build/kernel/vmlinux32.wasm
|
|
KPATCH_SMP: vendor/build/kernel-smp/vmlinux32.wasm
|
|
run: pnpm test:kpatch
|
|
- name: SDK unit tests
|
|
run: |
|
|
pnpm test:tty
|
|
pnpm test:http
|
|
pnpm test:9p
|
|
# The base bundle with each image (createKernel({ distro })): boot,
|
|
# the root overlay on a data disk, snapshots.
|
|
- name: Distro tests
|
|
run: pnpm test:distro
|
|
|
|
- name: Build the package
|
|
env:
|
|
VERSION: ${{ needs.guard.outputs.version }}
|
|
run: |
|
|
npm pkg set version="$VERSION"
|
|
pnpm build
|
|
ls -l dist/*.wasm
|
|
cmp dist/unkernel.wasm vendor/build/bundle/unkernel.wasm
|
|
cmp dist/virgl.wasm vendor/build/gl-wasm/virgl.wasm
|
|
cmp dist/kwvk-naga.wasm vendor/build/vk/kwvk-naga.wasm
|
|
# The api suite (~85 s) runs once, on the built package: the same code
|
|
# as the sources, plus the packaging (its distro tests read
|
|
# vendor/build/distro/alpine.erofs).
|
|
- name: Test the built package
|
|
run: |
|
|
node dist/cli.mjs --timeout 600 --kernel dist/unkernel.wasm --initrd vendor/build/initramfs/base-test.cpio \
|
|
--append "console=hvc0 rdinit=/usr/bin/kwtest" </dev/null | tee kwtest.log
|
|
grep -q 'kwtest: 0 failure(s)' kwtest.log
|
|
UNKERNEL_DIST=1 node --test test/api.test.ts
|
|
# The release's assets: the npm tarball (the base bundle and no distro
|
|
# image: the SDK downloads those by the tag), unkernel.wasm, distros.json,
|
|
# the images it names (not the .ext4, .tar or .id files next to them) and
|
|
# the GL renderer for the page (virgl.mjs, virgl.wasm), the Vulkan
|
|
# translator for the page (kwvk-naga.wasm), the third-party notices
|
|
# those carry (THIRD-PARTY.md), and for a page that loads its files from
|
|
# a mirror of these assets (CORS) rather than copying them into its
|
|
# output: the bundle's UP and SMP kernels (unkernel-up.wasm,
|
|
# unkernel-smp.wasm, split as a page build splits it), a gzipped copy
|
|
# of every .wasm (<file>.wasm.gz, for DecompressionStream: the mirror
|
|
# sends files as they are) and page.json (tag, ABI, base id, Linux
|
|
# release, each file's size and sha256 and its .gz's, the images;
|
|
# web/scripts/page-assets.ts).
|
|
- name: Pack
|
|
env:
|
|
VERSION: ${{ needs.guard.outputs.version }}
|
|
run: |
|
|
mkdir -p out
|
|
# A fixed name; the version is inside (package.json) and in the tag.
|
|
mv "out/$(npm pack --pack-destination out | tail -1)" out/unkernel.tgz
|
|
if tar -tzf out/unkernel.tgz | grep -E '\.(erofs|ext4|tar|cpio)$'; then
|
|
echo "::error::the npm package carries a distro image or initramfs"
|
|
exit 1
|
|
fi
|
|
size=$(stat -c %s out/unkernel.tgz)
|
|
echo "npm package: $size bytes packed, $(tar -tzvf out/unkernel.tgz | awk '{ s += $3 } END { print s }') unpacked"
|
|
if [ "$size" -gt 20000000 ]; then
|
|
echo "::error::the npm package is $size bytes (more than 20 MB)"
|
|
exit 1
|
|
fi
|
|
cp vendor/build/bundle/unkernel.wasm vendor/build/distro/distros.json vendor/build/gl-wasm/virgl.mjs vendor/build/gl-wasm/virgl.wasm vendor/build/vk/kwvk-naga.wasm THIRD-PARTY.md out/
|
|
for f in $(node -p 'JSON.parse(require("node:fs").readFileSync("vendor/build/distro/distros.json", "utf8")).distros.map((d) => d.file).join(" ")'); do
|
|
cp "vendor/build/distro/$f" out/
|
|
done
|
|
node web/scripts/page-assets.ts out --tag "v$VERSION"
|
|
for f in unkernel-up.wasm unkernel-smp.wasm unkernel-up.wasm.gz unkernel-smp.wasm.gz page.json; do
|
|
[ -s "out/$f" ] || { echo "::error::no $f (the bundle must carry the SMP patch)"; exit 1; }
|
|
done
|
|
ls -l out
|
|
(cd out && sha256sum -- *)
|
|
|
|
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
|
with:
|
|
name: release
|
|
path: out/
|
|
if-no-files-found: error
|
|
|
|
# Every step can run again ("Re-run failed jobs"): the tag, the npm
|
|
# version and the GitHub release are each skipped when they exist.
|
|
release:
|
|
name: Tag, publish to npm and on GitHub
|
|
needs: [guard, build]
|
|
if: needs.guard.outputs.release == 'true'
|
|
runs-on: ubuntu-24.04
|
|
timeout-minutes: 15
|
|
permissions:
|
|
contents: write # the tag and the GitHub release
|
|
id-token: write # npm trusted publishing (OIDC, no token) and provenance
|
|
steps:
|
|
# History and tags only (no blobs), to find the previous tag for the
|
|
# release notes.
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
fetch-depth: 0
|
|
fetch-tags: true
|
|
filter: tree:0
|
|
|
|
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
with:
|
|
name: release
|
|
path: out
|
|
|
|
# A pushed tag exists already; a manual release creates it here, on the
|
|
# commit that was built.
|
|
- name: Create the tag
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
TAG: v${{ needs.guard.outputs.version }}
|
|
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
|
|
echo "created $TAG at $GITHUB_SHA"
|
|
fi
|
|
|
|
# Trusted publishing needs npm >= 11.5.1 (Node 26 has it). npmjs.com
|
|
# trusts this workflow file (release.yml) of this repository; no token.
|
|
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
|
with:
|
|
node-version: 26
|
|
package-manager-cache: false
|
|
|
|
# Every release goes to the dist-tag latest. npm refuses to publish a
|
|
# semver prerelease (every generated version) without an explicit
|
|
# --tag, hence the flag. Only this repository publishes the package: a
|
|
# fork that runs the workflow releases on GitHub only.
|
|
- name: Publish to npm
|
|
if: github.repository == 'pithings/unkernel'
|
|
env:
|
|
VERSION: ${{ needs.guard.outputs.version }}
|
|
run: |
|
|
npm --version
|
|
if [ "$(npm view "unkernel@$VERSION" version 2>/dev/null)" = "$VERSION" ]; then
|
|
echo "unkernel@$VERSION is on npm already"
|
|
exit 0
|
|
fi
|
|
npm publish ./out/unkernel.tgz --access public --provenance --tag latest
|
|
|
|
- name: Publish the GitHub release
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
TAG: v${{ needs.guard.outputs.version }}
|
|
run: |
|
|
# gh uploads the assets to a draft and publishes it after the last
|
|
# one: a run cut off in between leaves a draft without some of them.
|
|
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
|
|
have="$(gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json assets --jq '.assets[].name')"
|
|
for f in out/*; do
|
|
grep -qxF "$(basename "$f")" <<<"$have" || gh release upload "$TAG" "$f" --repo "$GITHUB_REPOSITORY"
|
|
done
|
|
if [ "$(gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json isDraft --jq .isDraft)" = true ]; then
|
|
gh release edit "$TAG" --repo "$GITHUB_REPOSITORY" --draft=false --latest
|
|
fi
|
|
echo "release $TAG exists"
|
|
exit 0
|
|
fi
|
|
# The notes: the diff from the previous v* tag on main's history (an
|
|
# existing release keeps its notes, which may have been edited).
|
|
if prev="$(git describe --tags --abbrev=0 --match 'v*' "$GITHUB_SHA^" 2>/dev/null)"; then
|
|
notes="**Full Changelog**: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/compare/$prev...$TAG"
|
|
else
|
|
notes="**Full Changelog**: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/commits/$TAG"
|
|
fi
|
|
echo "$notes"
|
|
gh release create "$TAG" out/* --repo "$GITHUB_REPOSITORY" \
|
|
--latest --verify-tag --notes "$notes" --title "$TAG"
|