CI: add matrix builds & cross-platform packaging

Restructure GitHub Actions to build Windows and Linux matrix targets and produce platform-specific artifacts.

- .github/workflows/dev-build.yml: split cleanup/build jobs, add matrix (win-x64, linux-x64), set SNOWLUMA_TARGET for builds, produce full and -lite archives (.zip on Windows, .tar.gz on Linux), unify upload step and ensure errors when artifacts missing.
- .github/workflows/release.yml: convert release build to matrix, produce platform archives, download/collect artifacts, generate multi-platform release notes (bash), and create the GitHub release with both .zip and .tar.gz assets.
- packages/core/vite.config.ts: add fs import and SNOWLUMA_TARGET handling, pick platform-specific runtime files (launcher.bat or launcher.sh), enumerate native files per target, fail CI if expected native binaries are missing, and copy native files into dist/native.
- packages/runtime/launcher.sh: add a portable launcher for Linux that prefers a bundled node binary or falls back to PATH and execs index.mjs.

These changes enable cross-target CI packaging and enforce that native binaries are present before releasing.
This commit is contained in:
手瓜一十雪 committed 2026-05-03 16:20:39 +08:00
1 parent df73f58598
commit 82c1721466
4 files changed
+191 -83

No files matched your search

+34 -12
View File
@@ -1,5 +1,6 @@
import { defineConfig, PluginOption, UserConfig } from 'vite';
import { fileURLToPath } from 'url';
import fs from 'fs';
import path from 'path';
import { builtinModules } from 'module';
import cp from 'vite-plugin-cp';
@@ -22,19 +23,40 @@ const nodeModules = [...builtinModules, ...builtinModules.map((m) => `node:${m}`
const runtimeSrc = toPosix(runtimeDir);
const nativeSrc = toPosix(nativeDir);
// Only the runtime distribution assets land in dist/.
// (.gitignore and other dev artifacts must NOT be shipped.)
const runtimeDistFiles = ['launcher.bat', 'package.json'];
// Only ship native binaries matching the current build host's platform/arch.
// Override via SNOWLUMA_TARGET=<platform>-<arch> for cross-target packaging.
// Target selection: `SNOWLUMA_TARGET=<platform>-<arch>` overrides the host
// detection, enabling cross-target packaging on CI.
const targetTriple = process.env.SNOWLUMA_TARGET ?? `${process.platform}-${process.arch}`;
const nativeGlobs = [
`snowluma-${targetTriple}.dll`,
`snowluma-${targetTriple}.node`,
`websocket-${targetTriple}.node`,
const targetPlatform = targetTriple.split('-')[0];
// Runtime scaffolding files copied into dist/. The NTQQ hook is Windows-only,
// so its launcher/shell script differ per target.
const runtimeDistFiles = ['package.json',
targetPlatform === 'win32' ? 'launcher.bat' : 'launcher.sh',
];
// Native binaries shipped for the selected target:
// * `snowluma-*.{dll,node}` – NTQQ hook (Windows-only).
// * `websocket-*.node` – RFC 6455 framing/mask addon (all platforms).
const nativeFiles = [
`websocket-${targetTriple}.node`,
...(targetPlatform === 'win32'
? [`snowluma-${targetTriple}.dll`, `snowluma-${targetTriple}.node`]
: []),
];
// Fail fast if any expected native binary is missing from packages/runtime/native/.
// vite-plugin-cp only emits a warning on missing source files; we want a hard
// error so CI can't accidentally ship an incomplete archive.
const missingNatives = nativeFiles.filter(
(f) => !fs.existsSync(path.join(nativeDir, f)),
);
if (missingNatives.length > 0) {
throw new Error(
`Missing native binaries for target ${targetTriple}:\n` +
missingNatives.map((f) => ` - ${path.join(nativeDir, f)}`).join('\n'),
);
}
const BaseConfigPlugin: PluginOption[] = [
cp({
targets: [
@@ -43,8 +65,8 @@ const BaseConfigPlugin: PluginOption[] = [
dest: distDir,
flatten: true,
})),
...nativeGlobs.map((g) => ({
src: `${nativeSrc}/${g}`,
...nativeFiles.map((f) => ({
src: `${nativeSrc}/${f}`,
dest: path.join(distDir, 'native'),
flatten: true,
})),
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
# Prefer bundled node when present; fall back to $PATH.
if [[ -x "./node" ]]; then
NODE_BIN="./node"
else
NODE_BIN="$(command -v node || true)"
if [[ -z "$NODE_BIN" ]]; then
echo "error: 'node' not found on PATH and no bundled ./node; install Node.js >= 22." >&2
exit 127
fi
fi
exec "$NODE_BIN" ./index.mjs "$@"