From 82c1721466c96c15258c402cacef6d1c38212c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sun, 3 May 2026 16:20:39 +0800 Subject: [PATCH] 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. --- .github/workflows/dev-build.yml | 75 ++++++++++------- .github/workflows/release.yml | 137 ++++++++++++++++++++++---------- packages/core/vite.config.ts | 46 ++++++++--- packages/runtime/launcher.sh | 16 ++++ 4 files changed, 191 insertions(+), 83 deletions(-) create mode 100644 packages/runtime/launcher.sh diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index 81e7b919..d2542d3b 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -8,8 +8,8 @@ on: - 'v*' jobs: - build: - runs-on: windows-latest + cleanup: + runs-on: ubuntu-latest permissions: actions: write contents: read @@ -38,6 +38,25 @@ jobs: page++; } + build: + needs: cleanup + permissions: + contents: read + strategy: + fail-fast: false + matrix: + include: + - name: win-x64 + os: windows-latest + target: win32-x64 + - name: linux-x64 + os: ubuntu-latest + target: linux-x64 + - name: linux-arm64 + os: ubuntu-24.04-arm + target: linux-arm64 + runs-on: ${{ matrix.os }} + steps: - name: Checkout uses: actions/checkout@v4 @@ -58,45 +77,41 @@ jobs: # Always builds the WebUI flavor — no separate "core-only" artifact. - name: Build project + env: + SNOWLUMA_TARGET: ${{ matrix.target }} run: pnpm run build:all - - name: Verify native files - shell: pwsh - run: | - if (!(Test-Path "dist\native\snowluma-win32-x64.node")) { throw "Missing dist\native\snowluma-win32-x64.node" } - if (!(Test-Path "dist\native\snowluma-win32-x64.dll")) { throw "Missing dist\native\snowluma-win32-x64.dll" } - if (!(Test-Path "dist\native\websocket-win32-x64.node")) { throw "Missing dist\native\websocket-win32-x64.node" } - - name: Bundle runtime dependencies working-directory: dist run: npm install --omit=dev - # Two artifacts: - # * SnowLuma-dev.zip – full bundle, ships node.exe (zero-install) - # * SnowLuma-dev-no-node.zip – same bundle without node.exe (user provides Node >= 22) - - name: Package artifact (no-node) - shell: pwsh - run: | - Compress-Archive -Path "dist\*" -DestinationPath "SnowLuma-dev-no-node.zip" - - - name: Package artifact (with node.exe) + # Naming convention: + # SnowLuma-dev-.zip|tar.gz – zero-install (node bundled) + # SnowLuma-dev--lite.zip|tar.gz – user provides Node >= 22 + - name: Package (windows) + if: matrix.os == 'windows-latest' shell: pwsh run: | + Compress-Archive -Path "dist\*" -DestinationPath "SnowLuma-dev-${{ matrix.name }}-lite.zip" Copy-Item (Get-Command node).Source -Destination "dist\node.exe" - Compress-Archive -Path "dist\*" -DestinationPath "SnowLuma-dev.zip" + Compress-Archive -Path "dist\*" -DestinationPath "SnowLuma-dev-${{ matrix.name }}.zip" - - name: Upload artifact (with node.exe) + - name: Package (linux) + if: startsWith(matrix.os, 'ubuntu') + run: | + chmod +x dist/launcher.sh + tar -czf "SnowLuma-dev-${{ matrix.name }}-lite.tar.gz" -C dist . + cp "$(command -v node)" dist/node + chmod +x dist/node + tar -czf "SnowLuma-dev-${{ matrix.name }}.tar.gz" -C dist . + + # Single upload step — glob picks up both variants (.zip on Windows, + # .tar.gz on Linux) for this matrix row. + - name: Upload artifacts uses: actions/upload-artifact@v4 with: - name: SnowLuma-dev-${{ github.sha }} - path: SnowLuma-dev.zip - retention-days: 3 - overwrite: true - - - name: Upload artifact (no-node) - uses: actions/upload-artifact@v4 - with: - name: SnowLuma-dev-${{ github.sha }}-no-node - path: SnowLuma-dev-no-node.zip + name: SnowLuma-dev-${{ github.sha }}-${{ matrix.name }} + path: SnowLuma-dev-${{ matrix.name }}* retention-days: 3 overwrite: true + if-no-files-found: error diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 36609607..658d152f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,20 @@ permissions: jobs: build: - runs-on: windows-latest + strategy: + fail-fast: false + matrix: + include: + - name: win-x64 + os: windows-latest + target: win32-x64 + - name: linux-x64 + os: ubuntu-latest + target: linux-x64 + - name: linux-arm64 + os: ubuntu-24.04-arm + target: linux-arm64 + runs-on: ${{ matrix.os }} steps: - name: Checkout uses: actions/checkout@v4 @@ -34,70 +47,112 @@ jobs: # Always builds the WebUI flavor — no separate "core-only" artifact. - name: Build project + env: + SNOWLUMA_TARGET: ${{ matrix.target }} run: pnpm run build:all - - name: Verify native files - shell: pwsh - run: | - if (!(Test-Path "dist\native\snowluma-win32-x64.node")) { throw "Missing dist\native\snowluma-win32-x64.node" } - if (!(Test-Path "dist\native\snowluma-win32-x64.dll")) { throw "Missing dist\native\snowluma-win32-x64.dll" } - if (!(Test-Path "dist\native\websocket-win32-x64.node")) { throw "Missing dist\native\websocket-win32-x64.node" } - - name: Bundle runtime dependencies working-directory: dist run: npm install --omit=dev - # Two release archives: - # * SnowLuma--win-x64.zip – zero-install bundle (ships node.exe) - # * SnowLuma--win-x64-no-node.zip – same bundle without node.exe - - name: Package release (no-node) - shell: pwsh - run: | - Compress-Archive -Path "dist\*" -DestinationPath "SnowLuma-${{ github.ref_name }}-win-x64-no-node.zip" - - - name: Package release (with node.exe) + # Naming convention: + # SnowLuma--.zip|tar.gz – zero-install (node bundled) + # SnowLuma---lite.zip|tar.gz – user provides Node >= 22 + - name: Package (windows) + if: matrix.os == 'windows-latest' shell: pwsh run: | + Compress-Archive -Path "dist\*" -DestinationPath "SnowLuma-${{ github.ref_name }}-${{ matrix.name }}-lite.zip" Copy-Item (Get-Command node).Source -Destination "dist\node.exe" - Compress-Archive -Path "dist\*" -DestinationPath "SnowLuma-${{ github.ref_name }}-win-x64.zip" + Compress-Archive -Path "dist\*" -DestinationPath "SnowLuma-${{ github.ref_name }}-${{ matrix.name }}.zip" + + - name: Package (linux) + if: startsWith(matrix.os, 'ubuntu') + run: | + chmod +x dist/launcher.sh + tar -czf "SnowLuma-${{ github.ref_name }}-${{ matrix.name }}-lite.tar.gz" -C dist . + cp "$(command -v node)" dist/node + chmod +x dist/node + tar -czf "SnowLuma-${{ github.ref_name }}-${{ matrix.name }}.tar.gz" -C dist . + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: release-${{ matrix.name }} + path: SnowLuma-${{ github.ref_name }}-${{ matrix.name }}* + if-no-files-found: error + retention-days: 1 + + release: + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout (for git log) + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + + - name: Collect release assets + run: | + mkdir -p release + find artifacts -type f \( -name '*.zip' -o -name '*.tar.gz' \) -exec cp {} release/ \; + ls -lh release/ - name: Generate release note - shell: pwsh + shell: bash run: | - $tag = "${{ github.ref_name }}" - $previousTag = git describe --tags --abbrev=0 "$tag^" 2>$null - if ($LASTEXITCODE -ne 0) { $previousTag = "" } - if ($previousTag) { - $range = "$previousTag..$tag" - $changes = git log --pretty=format:"- %s (%h)" $range - } else { - $changes = git log --pretty=format:"- %s (%h)" $tag - } - if (!$changes) { $changes = "- No commit changes detected." } - $body = @" - # SnowLuma $tag + tag="${GITHUB_REF_NAME}" + previousTag="$(git describe --tags --abbrev=0 "${tag}^" 2>/dev/null || true)" + if [[ -n "$previousTag" ]]; then + changes="$(git log --pretty=format:'- %s (%h)' "$previousTag..$tag")" + else + changes="$(git log --pretty=format:'- %s (%h)' "$tag")" + fi + [[ -z "$changes" ]] && changes="- No commit changes detected." + cat > release-notes.md <= 22。 - "@ - $body -replace "(?m)^ ", "" | Set-Content -Path "release-notes.md" -Encoding utf8 + - Windows x64:\`launcher.bat\` 或 \`node index.mjs\`。 + - Linux:\`./launcher.sh\` 或 \`node index.mjs\`。 + - 所有压缩包均已内置 WebUI 静态资源;启动后访问 http://localhost:8080。 + - Linux 版本仅提供 OneBot 桥接能力,NTQQ 进程注入仅在 Windows 下生效。 + EOF - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: - files: SnowLuma-*.zip + files: | + release/*.zip + release/*.tar.gz body_path: release-notes.md overwrite_files: true draft: false diff --git a/packages/core/vite.config.ts b/packages/core/vite.config.ts index f83c08ae..1e50ef46 100644 --- a/packages/core/vite.config.ts +++ b/packages/core/vite.config.ts @@ -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=- for cross-target packaging. +// Target selection: `SNOWLUMA_TARGET=-` 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, })), diff --git a/packages/runtime/launcher.sh b/packages/runtime/launcher.sh new file mode 100644 index 00000000..6b29d9cc --- /dev/null +++ b/packages/runtime/launcher.sh @@ -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 "$@"