From 171ca357e2bb130a93eb3d16f25fc5c7534874c6 Mon Sep 17 00:00:00 2001 From: "google-labs-stitch[bot]" <315546542+google-labs-stitch[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 03:19:20 +0000 Subject: [PATCH] ci: run the full verification pipeline on three OS runners - Run the Rust, Wasm and npm checks on Linux, macOS and Windows - Verify each Binaryen 133 archive with SHA-256 before extraction - Check the native dynamic library after each Cargo release build - Report the combined matrix result through the verify summary job - Find npm across MSI, Chocolatey, MSYS2 and Volta in verify-pack.mjs - Document the CI matrix and PowerShell commands in AGENTS.md --- .github/workflows/ci.yml | 128 +++++++++++++++++++++++++--- AGENTS.md | 53 ++++++++++-- scripts/verify-pack.mjs | 177 +++++++++++++++++++++++++++++++++++---- 3 files changed, 326 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2562d00..499f125 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,5 @@ # Continuous integration for the Rust crate, the Wasm bindings and the -# npm package. +# npm package across Linux, macOS and Windows. name: CI on: @@ -18,9 +18,29 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: - verify: - runs-on: ubuntu-latest - timeout-minutes: 15 + verify-os: + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest + include: + - os: ubuntu-latest + binaryen_archive: binaryen-version_133-x86_64-linux.tar.gz + binaryen_sha256: 2dc9c7813f5375db93d96ead4b78222fcc3e2677bbb832297af4797782a37489 + cdylib: libtunelet.so + - os: macos-latest + binaryen_archive: binaryen-version_133-arm64-macos.tar.gz + binaryen_sha256: ad66da82ac13f163e424b1643f16c6dfcccc98b5966296b43e52d3cab04f84a8 + cdylib: libtunelet.dylib + - os: windows-latest + binaryen_archive: binaryen-version_133-x86_64-windows.tar.gz + binaryen_sha256: 17a2cbeac6b5693c5fbafab3838d3c65fd9c1eb38b05f5baec6c657e8c84995b + cdylib: tunelet.dll + runs-on: ${{ matrix.os }} + timeout-minutes: 20 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -37,19 +57,90 @@ jobs: with: tool: wasm-pack@0.15.1 checksum: true - # Install Binaryen wasm-opt 133 and verify its SHA-256 checksum. - - run: | - curl --proto '=https' --tlsv1.2 -fsSL -o "$RUNNER_TEMP/binaryen.tar.gz" https://github.com/WebAssembly/binaryen/releases/download/version_133/binaryen-version_133-x86_64-linux.tar.gz - echo "2dc9c7813f5375db93d96ead4b78222fcc3e2677bbb832297af4797782a37489 $RUNNER_TEMP/binaryen.tar.gz" | sha256sum --check - tar -xzf "$RUNNER_TEMP/binaryen.tar.gz" -C "$RUNNER_TEMP" - echo "$RUNNER_TEMP/binaryen-version_133/bin" >> "$GITHUB_PATH" - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: "24" cache: "npm" + # Download Binaryen wasm-opt 133, check its SHA-256 digest and extract it. + - shell: bash + env: + BINARYEN_ARCHIVE: ${{ matrix.binaryen_archive }} + BINARYEN_SHA256: ${{ matrix.binaryen_sha256 }} + run: | + node --input-type=module - <<'EOF' + import assert from "node:assert/strict"; + import { execFileSync } from "node:child_process"; + import crypto from "node:crypto"; + import fs from "node:fs"; + import os from "node:os"; + import path from "node:path"; + + const tempDir = process.env.RUNNER_TEMP; + assert.ok(tempDir, "RUNNER_TEMP must be set"); + const archiveName = process.env.BINARYEN_ARCHIVE; + assert.ok(archiveName, "BINARYEN_ARCHIVE must be set"); + const expectedSha256 = process.env.BINARYEN_SHA256; + assert.ok(expectedSha256, "BINARYEN_SHA256 must be set"); + const githubPath = process.env.GITHUB_PATH; + assert.ok(githubPath, "GITHUB_PATH must be set"); + + const archivePath = path.join(tempDir, archiveName); + const archiveUrl = `https://github.com/WebAssembly/binaryen/releases/download/version_133/${archiveName}`; + execFileSync( + process.platform === "win32" ? "curl.exe" : "curl", + [ + "--proto", + "=https", + "--tlsv1.2", + "-fsSL", + "--retry", + "3", + "-o", + archivePath, + archiveUrl, + ], + { stdio: "inherit" }, + ); + + const actualSha256 = crypto + .createHash("sha256") + .update(fs.readFileSync(archivePath)) + .digest("hex"); + assert.equal( + actualSha256, + expectedSha256, + `Binaryen SHA-256 mismatch for ${archiveName}`, + ); + + const winTar = path.join( + process.env.SystemRoot ?? "C:\\Windows", + "System32", + "tar.exe", + ); + const tarCommand = + process.platform === "win32" && fs.existsSync(winTar) + ? winTar + : "tar"; + execFileSync(tarCommand, ["-xzf", archiveName], { + cwd: tempDir, + stdio: "inherit", + }); + + const binDir = path.join(tempDir, "binaryen-version_133", "bin"); + const wasmOpt = path.join( + binDir, + process.platform === "win32" ? "wasm-opt.exe" : "wasm-opt", + ); + assert.ok(fs.existsSync(wasmOpt), `Expected ${wasmOpt}`); + fs.appendFileSync(githubPath, `${binDir}${os.EOL}`); + EOF - run: cargo fmt --check - run: cargo clippy --locked --lib -- -D warnings - run: cargo build --locked --release + # Check that the release build created the native dynamic library. + - run: node --input-type=module -e "import assert from 'node:assert/strict'; import fs from 'node:fs'; const stat = fs.statSync(process.env.CDYLIB_PATH); assert.ok(stat.isFile() && stat.size > 0);" + env: + CDYLIB_PATH: target/release/${{ matrix.cdylib }} - run: cargo doc --locked --no-deps env: RUSTDOCFLAGS: "-D warnings" @@ -58,4 +149,19 @@ jobs: - run: npm run check:wasm env: RUSTDOCFLAGS: "-D warnings" - - run: npm run verify:pack + - run: node scripts/verify-pack.mjs + + # Report the combined matrix status under the verify check name. + verify: + needs: verify-os + if: ${{ always() }} + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - run: | + if [ "${VERIFY_OS_RESULT}" != "success" ]; then + echo "verify-os result: ${VERIFY_OS_RESULT}" >&2 + exit 1 + fi + env: + VERIFY_OS_RESULT: ${{ needs.verify-os.result }} diff --git a/AGENTS.md b/AGENTS.md index 4bc6d47..de8755e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -90,29 +90,68 @@ this file, rustdoc, code comments, TypeScript comments and commit messages. ## Build and verify +In a POSIX shell, run these commands to check the Rust crate and the +`wasm` feature: + ```sh cargo build --locked --release cargo fmt --check cargo clippy --locked --lib -- -D warnings RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps +cargo package --list --locked rustup target add wasm32-unknown-unknown cargo clippy --locked --lib --target wasm32-unknown-unknown --features wasm -- -D warnings RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps --target wasm32-unknown-unknown --features wasm ``` -If you change the Wasm or TypeScript code, also run these commands. -`npm run check:wasm` runs Clippy and rustdoc for `wasm32-unknown-unknown`. -`npm run build` compiles `src/wasm.rs` and `src/index.ts`. -`npm run verify:pack` runs `npm run build` and checks the archives: +In PowerShell, set `RUSTDOCFLAGS` in the environment before you run +`cargo doc`: + +```powershell +cargo build --locked --release +cargo fmt --check +cargo clippy --locked --lib -- -D warnings +$env:RUSTDOCFLAGS = "-D warnings" +cargo doc --locked --no-deps +cargo package --list --locked +rustup target add wasm32-unknown-unknown +cargo clippy --locked --lib --target wasm32-unknown-unknown --features wasm -- -D warnings +cargo doc --locked --no-deps --target wasm32-unknown-unknown --features wasm +Remove-Item Env:RUSTDOCFLAGS +``` + +If you change the Wasm code, the TypeScript code or the build scripts, +also run the package checks. `npm run check:wasm` runs Clippy and +rustdoc for `wasm32-unknown-unknown`. `npm run build` compiles +`src/wasm.rs` and `src/index.ts`. `node scripts/verify-pack.mjs` runs +`npm pack`, triggers `prepack` and checks the archive, `loadTunelet()` +and the TypeScript declarations. `npm run verify:pack` runs the same +script. + +In a POSIX shell, run these commands: ```sh npm ci RUSTDOCFLAGS="-D warnings" npm run check:wasm -npm run verify:pack +node scripts/verify-pack.mjs +``` + +In PowerShell, run these commands: + +```powershell +npm ci +$env:RUSTDOCFLAGS = "-D warnings" +npm run check:wasm +Remove-Item Env:RUSTDOCFLAGS +node scripts/verify-pack.mjs ``` -- `.github/workflows/ci.yml` runs these checks on each pull request and each - push to `main`. +- `.github/workflows/ci.yml` runs these checks on `ubuntu-latest`, + `macos-latest` and `windows-latest` for each pull request and each + push to `main`. Each runner installs `wasm-pack` and Binaryen + `wasm-opt`, compiles the crate and the Wasm bindings and runs + `node scripts/verify-pack.mjs`. The `verify` job reports the combined + status of the three runners. - Make sure that there are no new warnings. This includes broken rustdoc links. - The crate has no tests (`test = false`). Do not add tests or test diff --git a/scripts/verify-pack.mjs b/scripts/verify-pack.mjs index 921fa6f..b499fd8 100644 --- a/scripts/verify-pack.mjs +++ b/scripts/verify-pack.mjs @@ -43,29 +43,178 @@ function readPackageName() { return packageName; } +/** Return true if `filePath` exists and is a regular file. */ +function isRegularFile(filePath) { + try { + return fs.statSync(filePath).isFile(); + } catch { + return false; + } +} + +/** Find `npm` on Windows across standard and split Node.js layouts. */ +function resolveWin32Npm() { + const nodeDir = path.dirname(process.execPath); + const candidateDirs = [nodeDir]; + + const rawPath = process.env.PATH ?? process.env.Path ?? ""; + for (const entry of rawPath.split(path.delimiter)) { + const cleaned = entry.trim().replace(/^"+|"+$/g, ""); + if (cleaned.length > 0 && path.isAbsolute(cleaned)) { + candidateDirs.push(cleaned); + } + } + + const voltaRoots = []; + if (/[\\/]tools[\\/]image[\\/]node[\\/]/i.test(nodeDir)) { + voltaRoots.push( + path.resolve(nodeDir, "..", "..", "..", ".."), + path.resolve(nodeDir, "..", "..", "..", "..", ".."), + ); + } + if (process.env.VOLTA_HOME && path.isAbsolute(process.env.VOLTA_HOME)) { + voltaRoots.push(process.env.VOLTA_HOME); + } + if (process.env.LOCALAPPDATA && path.isAbsolute(process.env.LOCALAPPDATA)) { + voltaRoots.push(path.join(process.env.LOCALAPPDATA, "Volta")); + candidateDirs.push( + path.join(process.env.LOCALAPPDATA, "Programs", "nodejs"), + ); + } + for (const voltaRoot of voltaRoots) { + candidateDirs.push(path.join(voltaRoot, "bin")); + const voltaNpmImageRoot = path.join(voltaRoot, "tools", "image", "npm"); + try { + const versions = fs + .readdirSync(voltaNpmImageRoot) + .sort((a, b) => b.localeCompare(a, undefined, { numeric: true })); + for (const version of versions) { + candidateDirs.push(path.join(voltaNpmImageRoot, version, "bin")); + } + } catch { + // Ignore absent Volta image directories. + } + } + + if (process.env.APPDATA && path.isAbsolute(process.env.APPDATA)) { + candidateDirs.push(path.join(process.env.APPDATA, "npm")); + } + if (process.env.NVM_SYMLINK && path.isAbsolute(process.env.NVM_SYMLINK)) { + candidateDirs.push(process.env.NVM_SYMLINK); + } + if ( + process.env.ChocolateyInstall && + path.isAbsolute(process.env.ChocolateyInstall) + ) { + const chocoRoot = process.env.ChocolateyInstall; + candidateDirs.push( + path.join(chocoRoot, "lib", "npm", "tools"), + path.join(chocoRoot, "lib", "nodejs", "tools"), + path.join(chocoRoot, "lib", "nodejs.commandline", "tools"), + path.join(chocoRoot, "lib", "nodejs-lts", "tools"), + path.join(chocoRoot, "bin"), + ); + } + for (const envName of ["ProgramFiles", "ProgramFiles(x86)"]) { + const baseDir = process.env[envName]; + if (baseDir && path.isAbsolute(baseDir)) { + candidateDirs.push( + path.join(baseDir, "nodejs"), + path.join(baseDir, "Volta"), + ); + } + } + + const seenDirs = new Set(); + for (const dir of candidateDirs) { + const key = path.normalize(dir).toLowerCase(); + if (seenDirs.has(key)) { + continue; + } + seenDirs.add(key); + + const cliCandidates = [ + path.join(dir, "node_modules", "npm", "bin", "npm-cli.js"), + path.resolve( + dir, + "..", + "lib", + "node_modules", + "npm", + "bin", + "npm-cli.js", + ), + path.resolve(dir, "..", "node_modules", "npm", "bin", "npm-cli.js"), + path.join(dir, "npm-cli.js"), + path.join(dir, "bin", "npm-cli.js"), + path.resolve( + dir, + "..", + "lib", + "npm", + "tools", + "node_modules", + "npm", + "bin", + "npm-cli.js", + ), + path.resolve( + dir, + "..", + "npm", + "tools", + "node_modules", + "npm", + "bin", + "npm-cli.js", + ), + path.resolve( + dir, + "..", + "..", + "npm", + "tools", + "node_modules", + "npm", + "bin", + "npm-cli.js", + ), + ]; + for (const cliPath of cliCandidates) { + if (isRegularFile(cliPath)) { + return { command: process.execPath, prefixArgs: [cliPath] }; + } + } + + const exePath = path.join(dir, "npm.exe"); + if (isRegularFile(exePath)) { + return { command: exePath, prefixArgs: [] }; + } + } + + throw new Error( + `npm-cli.js or npm.exe was not found for ${process.execPath}`, + ); +} + /** Run `npm pack` without a shell and return the relative archive path. */ function packArchive(packDir) { const npmExecPath = process.env.npm_execpath; if (npmExecPath) { + const isWin32Exe = + process.platform === "win32" && /\.exe$/i.test(npmExecPath); + const command = isWin32Exe ? npmExecPath : process.execPath; + const prefixArgs = isWin32Exe ? [] : [npmExecPath]; execFileSync( - process.execPath, - [npmExecPath, "pack", "--pack-destination", packDir], + command, + [...prefixArgs, "pack", "--pack-destination", packDir], { cwd: repoRoot, stdio: "inherit" }, ); } else if (process.platform === "win32") { - const npmCliPath = path.join( - path.dirname(process.execPath), - "node_modules", - "npm", - "bin", - "npm-cli.js", - ); - if (!fs.existsSync(npmCliPath)) { - throw new Error(`npm-cli.js was not found at ${npmCliPath}`); - } + const { command, prefixArgs } = resolveWin32Npm(); execFileSync( - process.execPath, - [npmCliPath, "pack", "--pack-destination", packDir], + command, + [...prefixArgs, "pack", "--pack-destination", packDir], { cwd: repoRoot, stdio: "inherit" }, ); } else {