diff --git a/.github/actions/setup-wasm/action.yml b/.github/actions/setup-wasm/action.yml index 56f51ec..59c59ca 100644 --- a/.github/actions/setup-wasm/action.yml +++ b/.github/actions/setup-wasm/action.yml @@ -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 @@ -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 }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15194fb..933453d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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: @@ -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 @@ -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 }} diff --git a/AGENTS.md b/AGENTS.md index ccc80c3..55aa064 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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 @@ -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 @@ -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 diff --git a/scripts/verify-pack.mjs b/scripts/verify-pack.mjs index 684a904..81925a8 100644 --- a/scripts/verify-pack.mjs +++ b/scripts/verify-pack.mjs @@ -4,8 +4,10 @@ * `loadTunelet()`, the HTTP Wasm loaders and the `NodeNext` TypeScript * declarations. * - * If you give `--out-dir