Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/actions/setup-wasm/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ inputs:
description: Optional Rust components, for example rustfmt and clippy.
required: false
default: ""
node-cache:
description: Optional cache mode for actions/setup-node, for example npm.
required: false
default: "npm"
wasm-pack-version:
description: The wasm-pack version.
required: false
Expand Down Expand Up @@ -103,4 +107,4 @@ runs:
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: ".node-version"
cache: "npm"
cache: ${{ inputs.node-cache }}
90 changes: 86 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Continuous integration for the Rust crate, the Wasm bindings and the
# npm package.
#
# First, build-wasm checks the Rust lints, the docs, the crate archive and the
# Wasm target on Linux, then uploads pkg/. In parallel, msrv checks
# rust-version from Cargo.toml. Next, check-os builds the native library,
# compiles TypeScript and checks the npm archives on Linux, macOS and Windows.
# Last, verify reports one status check for branch protection.
name: CI

on:
Expand All @@ -18,7 +24,7 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
verify:
build-wasm:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
Expand All @@ -28,18 +34,74 @@ jobs:
- uses: ./.github/actions/setup-wasm
with:
components: rustfmt, clippy
node-cache: ""
- run: cargo fmt --check
- run: cargo clippy --locked --lib -- -D warnings
- run: cargo build --locked --release
- run: cargo doc --locked --no-deps
env:
RUSTDOCFLAGS: "-D warnings"
- run: cargo package --locked
- run: npm ci
- run: npm run check:wasm
env:
RUSTDOCFLAGS: "-D warnings"
- run: npm run verify:pack
- run: npm run build:wasm
# Upload the built pkg/ files for the cross-OS matrix.
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wasm-pkg
path: |
pkg/tunelet.js
pkg/tunelet.d.ts
pkg/tunelet_bg.wasm
retention-days: 1
if-no-files-found: error

check-os:
needs: build-wasm
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
include:
- os: ubuntu-latest
cdylib: target/release/libtunelet.so
- os: macos-latest
cdylib: target/release/libtunelet.dylib
- os: windows-latest
cdylib: target/release/tunelet.dll
runs-on: ${{ matrix.os }}
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@df2a88e9fe4098bad09cb42c3dec7187f15861fc # master
with:
toolchain: stable
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
cache-bin: "false"
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: wasm-pkg
path: pkg
digest-mismatch: error
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: ".node-version"
cache: "npm"
- run: cargo build --locked --release
# Check that Cargo built the native dynamic library for this OS.
- run: node --input-type=module -e "import assert from 'node:assert/strict'; import fs from 'node:fs'; const stat = fs.statSync(process.env.CDYLIB); assert.ok(stat.isFile() && stat.size > 0);"
env:
CDYLIB: ${{ matrix.cdylib }}
- run: npm ci
- run: npm run build:ts
# Pack and check the pre-built files without a second Wasm build.
- run: npm run verify:pack -- --ignore-scripts

msrv:
runs-on: ubuntu-latest
Expand All @@ -62,3 +124,23 @@ jobs:
cache-bin: "false"
- run: cargo build --locked --lib
- run: cargo build --locked --lib --target wasm32-unknown-unknown --features wasm

verify:
needs:
- build-wasm
- check-os
- msrv
if: always()
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
# Fail if build-wasm, check-os or msrv did not succeed.
- run: |
if [ "${BUILD_WASM}" != "success" ] || [ "${CHECK_OS}" != "success" ] || [ "${MSRV}" != "success" ]; then
echo "Upstream job results: build-wasm=${BUILD_WASM}, check-os=${CHECK_OS}, msrv=${MSRV}" >&2
exit 1
fi
env:
BUILD_WASM: ${{ needs.build-wasm.result }}
CHECK_OS: ${{ needs.check-os.result }}
MSRV: ${{ needs.msrv.result }}
29 changes: 27 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ this file, rustdoc, code comments, TypeScript comments and commit messages.

## Build and verify

Run these Cargo checks in a POSIX shell (`sh`, `bash` or `zsh`):

```sh
cargo build --locked --release
cargo fmt --check
Expand All @@ -103,6 +105,18 @@ RUSTDOCFLAGS="-D warnings" cargo doc --locked --release --no-deps --target wasm3

If you run `cargo package --locked` before a commit, add `--allow-dirty`.

In PowerShell on Windows, set `RUSTDOCFLAGS` in the environment before `cargo doc` and `npm run check:wasm`:

```powershell
$env:RUSTDOCFLAGS = "-D warnings"
cargo doc --locked --no-deps
cargo doc --locked --release --no-deps --target wasm32-unknown-unknown --features wasm
npm run check:wasm
Remove-Item Env:RUSTDOCFLAGS
```

In `cmd.exe` on Windows, use `set "RUSTDOCFLAGS=-D warnings"` before the doc commands and `set "RUSTDOCFLAGS="` after them.

If you change the Wasm or TypeScript code, also run these commands.
`npm run check:wasm` runs Clippy and rustdoc in release mode for
`wasm32-unknown-unknown`. `npm run build` compiles `src/wasm.rs` and
Expand All @@ -115,8 +129,19 @@ RUSTDOCFLAGS="-D warnings" npm run check:wasm
npm run verify:pack
```

- `.github/workflows/ci.yml` runs these checks on each pull request and each
push to `main`.
`npm run verify:pack -- --ignore-scripts` checks the pre-built `pkg/` and
`dist/` files without a second Wasm build. If `pkg/` is ready, run
`npm run build:ts` before `npm run verify:pack -- --ignore-scripts`.

- `.github/workflows/ci.yml` runs on each pull request and each push to `main`.
`build-wasm` checks the format, Clippy, rustdoc, the crate archive and
`check:wasm` on `ubuntu-latest`, then builds and uploads `pkg/`. `check-os`
runs on `ubuntu-latest`, `macos-latest` and `windows-latest` with isolated
failures (`fail-fast: false`). Each runner builds `libtunelet.so`,
`libtunelet.dylib` or `tunelet.dll`, compiles TypeScript and runs
`npm run verify:pack -- --ignore-scripts`. `msrv` checks `rust-version` from
`Cargo.toml` on `ubuntu-latest`. `verify` reports the combined status for
branch protection.
- 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
Expand Down
41 changes: 35 additions & 6 deletions scripts/verify-pack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* `loadTunelet()`, the HTTP Wasm loaders and the `NodeNext` TypeScript
* declarations.
*
* If you give `--out-dir <dir>`, the script writes both `.tgz` archives and
* `SHA256SUMS.txt` to `<dir>` after all checks succeed.
* If you give `--ignore-scripts`, the script checks the pre-built `pkg/` and
* `dist/` files without a build. If you give `--out-dir <dir>`, the script
* writes both `.tgz` archives and `SHA256SUMS.txt` to `<dir>` after all checks
* succeed.
*/
import assert from "node:assert/strict";
import { execFileSync, spawn } from "node:child_process";
Expand Down Expand Up @@ -36,11 +38,33 @@ const PACKAGE_NAME_PATTERN =

const repoRoot = fileURLToPath(new URL("..", import.meta.url));

/** Read the optional `--out-dir` flag from `process.argv`. */
/** If `filePath` is a regular file on disk, return `true`. */
function isRegularFile(filePath) {
try {
return fs.statSync(filePath).isFile();
} catch {
return false;
}
}

/** Check that all expected source files exist in `repoRoot`. */
function verifyPrebuiltFiles() {
for (const archivePath of EXPECTED_ARCHIVE_PATHS) {
const relativeFile = archivePath.slice("package/".length);
const fullPath = path.join(repoRoot, relativeFile);
assert.ok(
isRegularFile(fullPath),
`Expected built file at ${relativeFile}`,
);
}
}

/** Read the optional `--ignore-scripts` and `--out-dir` flags from `process.argv`. */
function parseCliOptions(argv) {
const { values, positionals } = parseArgs({
args: argv,
options: {
"ignore-scripts": { type: "boolean", default: false },
"out-dir": { type: "string" },
},
strict: true,
Expand All @@ -50,15 +74,16 @@ function parseCliOptions(argv) {
0,
`Unexpected positional arguments: ${positionals.join(" ")}`,
);
const ignoreScripts = Boolean(values["ignore-scripts"]);
const rawOutDir = values["out-dir"];
if (rawOutDir === undefined) {
return { outDir: undefined };
return { ignoreScripts, outDir: undefined };
}
assert.ok(
rawOutDir.trim().length > 0 && !rawOutDir.startsWith("-"),
"--out-dir requires a directory path",
);
return { outDir: path.resolve(process.cwd(), rawOutDir) };
return { ignoreScripts, outDir: path.resolve(process.cwd(), rawOutDir) };
}

/** Read and check the manifest in `package.json`. */
Expand Down Expand Up @@ -1003,8 +1028,11 @@ function writeVerifiedOutputs(outDir, archives) {
);
}

const { outDir } = parseCliOptions(process.argv.slice(2));
const { ignoreScripts, outDir } = parseCliOptions(process.argv.slice(2));
const manifest = readPackageManifest();
if (ignoreScripts) {
verifyPrebuiltFiles();
}
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "tunelet-verify-pack-"));

try {
Expand All @@ -1019,6 +1047,7 @@ try {
repoRoot,
unscopedPackDir,
unscopedFileName,
{ ignoreScripts },
);
await verifyPackedArchive(
unscopedWorkDir,
Expand Down
Loading