From 6d7d0a693c93d0213c8556b81b27240268bc0409 Mon Sep 17 00:00:00 2001 From: Kinflou Date: Thu, 12 Nov 2026 06:49:53 +0800 Subject: [PATCH] ci: harden the workflows, use the org's reusable Rust CI and the CI images The Rust matrix is the reusable rust-ci.yml, the wasm build runs in the CI wasm image and the valgrind count in the CI bench image (no apt install), every action is pinned by SHA, tokens are read-only except in the jobs that push, and the reports and nightly workflows split their publish and issue steps into jobs of their own. Adds lint.yml, renovate.json and an exact rust-toolchain.toml (1.99.1). --- .github/workflows/bench.yml | 92 +++++++++++---- .github/workflows/ci.yml | 210 ++++++++++++++++++++++------------ .github/workflows/lint.yml | 27 +++++ .github/workflows/nightly.yml | 120 +++++++++++++++---- .github/workflows/reports.yml | 79 +++++++++---- renovate.json | 6 + rust-toolchain.toml | 2 + 7 files changed, 399 insertions(+), 137 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 renovate.json create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index 66e0daf..ecc01eb 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -12,6 +12,21 @@ name: Benchmarks # the Observatory reads. A manual run from another branch does a dry run of # the publish. A pull request only checks that every benchmark runs (once, # uncounted, no valgrind): a full count takes too long for every push. +# +# This is not the org's reusable bench workflow: that one is the iai-callgrind +# gate for a Cargo project (`cargo bench` on the base and the head, its report +# script's `--targets` protocol). Here the counts are valgrind's, taken of +# Node running the TypeScript runtime, in shards, with no base to compare. The +# `count` jobs do use the org's CI bench image, which has valgrind (3.24) and +# python3, in place of installing valgrind from apt on the runner. The image +# has no Node (and the TypeScript runtime needs one to run), so the jobs +# install an exact Node version with `actions/setup-node`, as the VM jobs do. +# The Rust toolchain in the image isn't used: the wasm core is vendored, built. +# +# The published history steps up where this moved to the image: valgrind went +# from 3.22 (Ubuntu 24.04's) to 3.24, and the userland under Node from +# Ubuntu 24.04's to Debian 13's. Node itself is the version the published +# history was counted with (22.23.4): bump it on purpose, not along the way. on: pull_request: @@ -34,26 +49,40 @@ on: permissions: contents: read -# A full count takes a while: a newer push to `main` supersedes the -# running one rather than queueing behind it (and the publish skips a report -# older than the one already published either way). +# A newer push to the same pull request supersedes this run; a branch's runs +# queue instead (the publish skips a report older than the one already +# published either way). concurrency: - group: bench-${{ github.ref }} - cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +# Container jobs default to `sh`; the steps are bash. +defaults: + run: + shell: bash jobs: smoke: if: github.event_name == 'pull_request' name: shared benchmarks run - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 20 defaults: run: + shell: bash working-directory: runtime steps: - - uses: actions/checkout@v7 - - uses: actions/setup-node@v7 + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - node-version: 22 + persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 22.23.4 + cache: npm + cache-dependency-path: runtime/package-lock.json - run: npm ci - run: npm run build - name: Each shared benchmark, a few iterations uncounted @@ -66,20 +95,26 @@ jobs: if: github.event_name != 'pull_request' name: count (shard ${{ matrix.shard }}/4) timeout-minutes: 150 - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + # valgrind and python3 are in the image; harden-runner is for VM jobs. + container: ghcr.io/comlineproject/ci-bench@sha256:235555448c3c6027960cd95c0b2974014484e0c4f2808f064eb4cb3df91cebc0 strategy: fail-fast: true matrix: shard: [0, 1, 2, 3] defaults: run: + shell: bash working-directory: runtime steps: - - uses: actions/checkout@v7 - - uses: actions/setup-node@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: - node-version: 22 - - run: sudo apt-get update && sudo apt-get install -y valgrind + node-version: 22.23.4 + cache: npm + cache-dependency-path: runtime/package-lock.json - run: npm ci - run: npm run build - name: Build the region addon @@ -88,8 +123,10 @@ jobs: cc -O2 -shared -fPIC -I"$(dirname "$(dirname "$(node -p process.execPath)")")/include/node" \ -o bench/.core/region.node bench/region/region.c - name: Count - run: python3 bench/count.py --shared --shard ${{ matrix.shard }}/4 -j "$(nproc)" --commit "${{ github.sha }}" --json part-${{ matrix.shard }}.json | tee -a "$GITHUB_STEP_SUMMARY" - - uses: actions/upload-artifact@v7 + env: + SHARD: ${{ matrix.shard }} + run: python3 bench/count.py --shared --shard "$SHARD/4" -j "$(nproc)" --commit "$GITHUB_SHA" --json "part-$SHARD.json" | tee -a "$GITHUB_STEP_SUMMARY" + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: bench-part-${{ matrix.shard }} path: runtime/part-${{ matrix.shard }}.json @@ -97,32 +134,39 @@ jobs: bench: needs: count name: shared benchmarks - timeout-minutes: 150 - runs-on: ubuntu-latest + timeout-minutes: 30 + runs-on: ubuntu-24.04 permissions: contents: write defaults: run: + shell: bash working-directory: runtime steps: - - uses: actions/checkout@v7 + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - - uses: actions/setup-node@v7 + # This job pushes to the reports branch with the checkout's token. + persist-credentials: true + # merge.py lists the benchmarks with `node bench/shared.mjs`. + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: - node-version: 22 - - uses: actions/download-artifact@v7 + node-version: 22.23.4 + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: pattern: bench-part-* path: runtime/parts merge-multiple: true - name: Merge run: python3 bench/merge.py --out typescript.bench.json parts/part-*.json - - uses: actions/upload-artifact@v7 + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: typescript.bench.json path: runtime/typescript.bench.json - - uses: ComlineProject/observatory/.github/actions/publish-report@v1 + - uses: ComlineProject/observatory/.github/actions/publish-report@8d21b1fbe68f8b639676153ce1a308eaafdcc6a7 # v1 with: reports: runtime/typescript.bench.json readme: .github/reports-branch.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 67de496..baa09f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,61 +4,102 @@ on: push: pull_request: +permissions: + contents: read + +# A newer push to the same pull request supersedes this run; a branch's runs +# queue instead. +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +# Container jobs default to `sh`; the steps are bash. +defaults: + run: + shell: bash + env: CARGO_TERM_COLOR: always jobs: - build_and_test: - name: Rust project - stable - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - run: rustup update stable && rustup default stable - - run: cargo build --verbose - - run: cargo test --verbose - # `std-extra/` is generated and committed; this fails if it was edited - # by hand, or if a generator change moved its output without it being - # regenerated. - - run: cargo run -p xtask -- --check + # The Cargo workspace's toolchain matrix (stable, beta, nightly on + # ubuntu-24.04), the same build and tests on ubuntu-24.04-arm, macos-15 and + # windows-2025 (core#9: paths and line endings are where they're expected to + # differ), and a stable canary on ubuntu-26.04 that may fail without failing + # the run: the org's reusable workflow. + # + # `std-extra/` is generated and committed; the xtask check fails if it was + # edited by hand, or if a generator change moved its output without it + # being regenerated. The reusable workflow has no step after the tests, so + # the check is its `extra-setup` hook, which runs in every job before the + # build: that keeps it on every platform, as before, and `cargo run` builds + # the workspace's dependencies for the build and tests that follow. + # + # No `--locked`: the repository doesn't commit a Cargo.lock. + rust: + name: rust + permissions: + contents: read + uses: ComlineProject/.github/.github/workflows/rust-ci.yml@797d473553d7f2fc50895bb2573acb83ac63c7cb # main, no release tag yet + with: + extra-setup: cargo run -p xtask -- --check wasip1: # The generator as a WASI module, which the CLI runs under wasmtime. # `comline-codegen` takes comline-core with `default-features = false` # (the IR only), so the parser and its tree-sitter dependency stay out of - # this build (core#144). + # this build (core#144). In the wasm CI image (stable 1.99.1, which + # `rust-toolchain.toml` pins, and both wasm targets). name: Generator builds for wasm32-wasip1 - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 30 + container: ghcr.io/comlineproject/ci-wasm@sha256:badd6af13cee6c459c9284de8ef0ef4a1667ed7e35582f87d1afb08f3c30fd8f steps: - - uses: actions/checkout@v4 - - run: rustup update stable && rustup default stable - - run: rustup target add wasm32-wasip1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - run: cargo build --verbose -p comline-codegen-typescript --bin comline-gen-typescript --target wasm32-wasip1 runtime: name: runtime - Node - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 30 defaults: run: + shell: bash working-directory: runtime steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: - node-version: 20 + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 20.20.2 + cache: npm + cache-dependency-path: runtime/package-lock.json # The Rust reference the property tests (test/prop/) compare against, # built at the runtime commit the core is vendored from. Without it they # fail in CI rather than skip. - id: reference run: echo "rev=$(cat core/CORE_REV)" >> "$GITHUB_OUTPUT" - - uses: actions/cache@v4 + - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 id: reference-cache with: path: ~/.cargo/bin/comline-reference key: comline-reference-${{ steps.reference.outputs.rev }} + # Keep in step with rust-toolchain.toml. - if: steps.reference-cache.outputs.cache-hit != 'true' - run: | - rustup update stable && rustup default stable - cargo install --locked --git https://github.com/ComlineProject/runtime --rev "${{ steps.reference.outputs.rev }}" comline-reference + uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1 + with: + toolchain: 1.99.1 + - if: steps.reference-cache.outputs.cache-hit != 'true' + env: + REV: ${{ steps.reference.outputs.rev }} + run: cargo install --locked --git https://github.com/ComlineProject/runtime --rev "$REV" comline-reference - run: echo "COMLINE_REFERENCE=$HOME/.cargo/bin/comline-reference" >> "$GITHUB_ENV" - run: npm ci - run: npm run typecheck @@ -74,7 +115,7 @@ jobs: # glue) is rebuilt from source at CORE_REV, with the runtime's pinned # toolchain (the script installs it and its wasm32 target) and its # committed Cargo.lock; this fails unless every byte matches. - - uses: actions/cache@v4 + - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: | ~/.cargo/registry/index @@ -87,15 +128,24 @@ jobs: # ops protocol (runtime/test/conformance-server.ts), against the vendored # corpus: the same proof the Rust runtime gives through `comline-reference`. name: runtime - comline conformance - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 30 defaults: run: + shell: bash working-directory: runtime steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: - node-version: 20 + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 20.20.2 + cache: npm + cache-dependency-path: runtime/package-lock.json # The CLI at the tip of its default branch, built once per commit (the # docs repo's cli-drift workflow does the same). - name: Resolve the CLI's current commit @@ -106,15 +156,20 @@ jobs: run: | branch=$(gh api repos/ComlineProject/cli --jq .default_branch) echo "sha=$(gh api "repos/ComlineProject/cli/commits/$branch" --jq .sha)" >> "$GITHUB_OUTPUT" - - uses: actions/cache@v4 + - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 id: cli-cache with: path: ~/.cargo/bin/comline key: comline-${{ runner.os }}-${{ steps.cli.outputs.sha }} + # Keep in step with rust-toolchain.toml. - if: steps.cli-cache.outputs.cache-hit != 'true' - run: | - rustup update stable && rustup default stable - cargo install --locked --git https://github.com/ComlineProject/cli --rev "${{ steps.cli.outputs.sha }}" comline + uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1 + with: + toolchain: 1.99.1 + - if: steps.cli-cache.outputs.cache-hit != 'true' + env: + SHA: ${{ steps.cli.outputs.sha }} + run: cargo install --locked --git https://github.com/ComlineProject/cli --rev "$SHA" comline - run: npm ci && npm run build # Every official encoding that is fully implemented here. - name: Conformance - datagram@1, datagram@2, jsonrpc@1, packed@1, comline@1 @@ -133,15 +188,26 @@ jobs: std_extra: name: std-extra - Node - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 20 defaults: run: + shell: bash working-directory: std-extra steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: - node-version: 20 + node-version: 20.20.2 + cache: npm + cache-dependency-path: | + runtime/package-lock.json + std-extra/package-lock.json # `@comline/runtime` is an optional peer of `@comline/std` (its types # name `Layout`), and isn't on npm yet: link the sibling, built. - run: npm ci && npm run build @@ -157,12 +223,22 @@ jobs: # Generated code must type-check on the oldest TypeScript the generator # registers at (`LANG_VERSION`), not only on the one in the lockfiles. name: Generated code type-checks at the floor (TypeScript 5.0) - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 20 steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: - node-version: 20 + node-version: 20.20.2 + cache: npm + cache-dependency-path: | + runtime/package-lock.json + std-extra/package-lock.json - run: npm ci && npm run build working-directory: runtime - run: npx -y -p typescript@5.0.4 tsc -p tsconfig.generated.json @@ -172,59 +248,53 @@ jobs: - run: npx -y -p typescript@5.0.4 tsc --noEmit working-directory: std-extra - # Cross-platform (core#9): the same checks on the other platforms, as - # separate jobs so the Linux check names above stay unchanged. - rust_xp: - name: Rust project - stable (${{ matrix.os }}) - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [windows-latest, macos-latest, ubuntu-24.04-arm] - defaults: - run: - shell: bash - steps: - - uses: actions/checkout@v7 - - run: rustup update stable && rustup default stable - - uses: Swatinem/rust-cache@v2 - - run: cargo build --verbose - - run: cargo test --verbose - - run: cargo run -p xtask -- --check - + # The Node job on the other platforms, as separate jobs so the Linux check + # name above stays unchanged. (The Rust workspace's cross-platform build is + # the `rust` job's.) runtime_xp: name: runtime - Node 22 (${{ matrix.os }}) runs-on: ${{ matrix.os }} + timeout-minutes: 30 strategy: fail-fast: false matrix: - os: [windows-latest, macos-latest, ubuntu-24.04-arm] + os: [windows-2025, macos-15, ubuntu-24.04-arm] defaults: run: shell: bash working-directory: runtime steps: - - uses: actions/checkout@v7 - - uses: actions/setup-node@v7 + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - node-version: 22 + persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 22.23.5 cache: npm cache-dependency-path: runtime/package-lock.json # The Rust reference the property tests compare against, built on the # platform under test (cached per OS and architecture). - id: reference run: echo "rev=$(cat core/CORE_REV)" >> "$GITHUB_OUTPUT" - - uses: actions/cache@v5 + - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 id: reference-cache with: path: | ~/.cargo/bin/comline-reference ~/.cargo/bin/comline-reference.exe key: comline-reference-${{ runner.os }}-${{ runner.arch }}-${{ steps.reference.outputs.rev }} + # Keep in step with rust-toolchain.toml. - if: steps.reference-cache.outputs.cache-hit != 'true' - run: | - rustup update stable && rustup default stable - cargo install --locked --git https://github.com/ComlineProject/runtime --rev "${{ steps.reference.outputs.rev }}" comline-reference + uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1 + with: + toolchain: 1.99.1 + - if: steps.reference-cache.outputs.cache-hit != 'true' + env: + REV: ${{ steps.reference.outputs.rev }} + run: cargo install --locked --git https://github.com/ComlineProject/runtime --rev "$REV" comline-reference - run: echo "COMLINE_REFERENCE=$(command -v comline-reference)" >> "$GITHUB_ENV" - run: npm ci - run: npm run typecheck diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..d4cdcbe --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,27 @@ +name: Lint + +# actionlint on the workflows, and the Renovate config checked with +# `--strict`: the org's reusable lint workflow. + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +# Not `lint-...`: the reusable workflow's own group is that, and groups are +# case-insensitive, so the same name would make the call wait on itself. +concurrency: + group: ci-lint-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + lint: + name: lint + permissions: + contents: read + uses: ComlineProject/.github/.github/workflows/lint.yml@797d473553d7f2fc50895bb2573acb83ac63c7cb # main, no release tag yet + with: + renovate-config: renovate.json diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index b3367b7..431410f 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -5,6 +5,11 @@ name: Nightly differential tests # on the open one with the same title, rather than blocking anything. # Each run, pass or fail, also writes `typescript.fuzz.json` (each property's # verdict) and commits it to the `reports` branch, which the Observatory reads. +# +# Three jobs, so the one that runs the repository's code and its dependencies +# holds a read-only token: `properties` runs the tests; `publish` (the only +# one that can push) commits the report; `issue` (the only one that can write +# issues) reports a divergence. on: schedule: @@ -12,34 +17,54 @@ on: workflow_dispatch: permissions: - contents: write - issues: write + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: properties: name: runtime - properties against the reference - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 60 defaults: run: + shell: bash working-directory: runtime + outputs: + rev: ${{ steps.reference.outputs.rev }} + # The outcomes of the two steps the other jobs go by. + properties: ${{ steps.properties.outcome }} + report: ${{ steps.report.outcome }} steps: - - uses: actions/checkout@v7 + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: - fetch-depth: 0 - - uses: actions/setup-node@v7 + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: - node-version: 22 + node-version: 22.23.5 + cache: npm + cache-dependency-path: runtime/package-lock.json - id: reference run: echo "rev=$(cat core/CORE_REV)" >> "$GITHUB_OUTPUT" - - uses: actions/cache@v6 + - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 id: reference-cache with: path: ~/.cargo/bin/comline-reference key: comline-reference-${{ steps.reference.outputs.rev }} + # Keep in step with rust-toolchain.toml. - if: steps.reference-cache.outputs.cache-hit != 'true' - run: | - rustup update stable && rustup default stable - cargo install --locked --git https://github.com/ComlineProject/runtime --rev "${{ steps.reference.outputs.rev }}" comline-reference + uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1 + with: + toolchain: 1.99.1 + - if: steps.reference-cache.outputs.cache-hit != 'true' + env: + REV: ${{ steps.reference.outputs.rev }} + run: cargo install --locked --git https://github.com/ComlineProject/runtime --rev "$REV" comline-reference - run: echo "COMLINE_REFERENCE=$HOME/.cargo/bin/comline-reference" >> "$GITHUB_ENV" - run: npm ci - run: npx tsc -p tsconfig.json @@ -50,8 +75,9 @@ jobs: FC_NUM_RUNS=20000 node --test \ --test-reporter=spec --test-reporter-destination=stdout \ --test-reporter=./scripts/prop-verdicts.mjs --test-reporter-destination="$RUNNER_TEMP/verdicts.json" \ - dist/test/prop/*.test.js 2>&1 | tee "$RUNNER_TEMP/properties.log" + dist/test/prop/*.test.js 2>&1 | tee properties.log - name: Write typescript.fuzz.json + id: report if: always() && steps.properties.outcome != 'skipped' env: RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} @@ -71,22 +97,72 @@ jobs: fs.writeFileSync("typescript.fuzz.json", JSON.stringify(report, null, 2) + "\n"); ' cat typescript.fuzz.json - - uses: ComlineProject/observatory/.github/actions/publish-report@v1 - if: always() && hashFiles('runtime/typescript.fuzz.json') != '' + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + if: always() && steps.report.outcome == 'success' + with: + name: typescript.fuzz.json + path: runtime/typescript.fuzz.json + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + if: always() && steps.properties.outcome == 'failure' + with: + name: properties-log + path: runtime/properties.log + + publish: + name: publish the report + needs: properties + if: ${{ !cancelled() && needs.properties.outputs.report == 'success' }} + runs-on: ubuntu-24.04 + timeout-minutes: 15 + permissions: + contents: write + steps: + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + # This job pushes to the reports branch with the checkout's token. + persist-credentials: true + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: typescript.fuzz.json + path: reports + - uses: ComlineProject/observatory/.github/actions/publish-report@8d21b1fbe68f8b639676153ce1a308eaafdcc6a7 # v1 with: - reports: runtime/typescript.fuzz.json + reports: reports/typescript.fuzz.json readme: .github/reports-branch.md dry-run: ${{ github.ref != 'refs/heads/main' }} + + issue: + name: open or update an issue + needs: properties + if: ${{ !cancelled() && needs.properties.outputs.properties == 'failure' }} + runs-on: ubuntu-24.04 + timeout-minutes: 10 + permissions: + issues: write + steps: + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: audit + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: properties-log + path: ${{ runner.temp }}/log - name: Open or update an issue - if: failure() && steps.properties.outcome == 'failure' env: GH_TOKEN: ${{ github.token }} TITLE: "Nightly: the differential property tests found a divergence" + REPO: ${{ github.repository }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + REV: ${{ needs.properties.outputs.rev }} + SHA: ${{ github.sha }} run: | - log="$RUNNER_TEMP/properties.log" - run_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + log="$RUNNER_TEMP/log/properties.log" { - echo "The nightly property tests against \`comline-reference\` (CORE_REV \`${{ steps.reference.outputs.rev }}\`, commit ${{ github.sha }}) failed: $run_url" + echo "The nightly property tests against \`comline-reference\` (CORE_REV \`$REV\`, commit $SHA) failed: $RUN_URL" echo echo "A divergence in no class \`known-divergences.json\` lists, with its shrunk counterexample. Replay it with \`FC_SEED\` and \`FC_PATH\` from the report." echo @@ -94,9 +170,9 @@ jobs: grep -E "Counterexample|Got error|^ +(type|value|bytes|input):|\(in |seed" "$log" | head -60 || true echo '```' } > "$RUNNER_TEMP/body.md" - existing="$(gh issue list --repo "${{ github.repository }}" --state open --search "in:title \"$TITLE\"" --json number,title --jq ".[] | select(.title == env.TITLE) | .number" | head -1)" + existing="$(gh issue list --repo "$REPO" --state open --search "in:title \"$TITLE\"" --json number,title --jq ".[] | select(.title == env.TITLE) | .number" | head -1)" if [ -n "$existing" ]; then - gh issue comment "$existing" --repo "${{ github.repository }}" --body-file "$RUNNER_TEMP/body.md" + gh issue comment "$existing" --repo "$REPO" --body-file "$RUNNER_TEMP/body.md" else - gh issue create --repo "${{ github.repository }}" --title "$TITLE" --label bug --body-file "$RUNNER_TEMP/body.md" + gh issue create --repo "$REPO" --title "$TITLE" --label bug --body-file "$RUNNER_TEMP/body.md" fi diff --git a/.github/workflows/reports.yml b/.github/workflows/reports.yml index aef66e7..e1a3571 100644 --- a/.github/workflows/reports.yml +++ b/.github/workflows/reports.yml @@ -3,9 +3,14 @@ name: Reports # Size and coverage reports for the Observatory: the runtime package as # shipped (npm pack, plus its built entry file) and the line/function/branch # coverage of its own tests, the property tests included (they compare against -# the Rust reference, built as in ci.yml, at the default PR run count). On every push to `main` (and a manual run) -# they're committed to the `reports` branch; elsewhere the publish is a dry run. A pull request runs it only when this -# workflow (or its helper script) changes. +# the Rust reference, built as in ci.yml, at the default PR run count). On every +# push to `main` (and a manual run) the `publish` job commits them to the +# `reports` branch; a manual run from another branch does a dry run of it. A +# pull request runs the measuring job only when this workflow (or its helper +# script) changes, and never the publish. +# +# Only `publish` can write, and it runs none of the repository's code: the +# job that installs the dependencies and runs the tests has a read-only token. on: pull_request: @@ -20,23 +25,27 @@ permissions: contents: read concurrency: - group: reports-${{ github.ref }} - cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: reports: name: size and coverage - runs-on: ubuntu-latest - permissions: - contents: write + runs-on: ubuntu-24.04 + timeout-minutes: 30 steps: - - uses: actions/checkout@v7 + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: - fetch-depth: 0 + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - id: node - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: - node-version: 22 + node-version: 22.23.5 + cache: npm + cache-dependency-path: runtime/package-lock.json - run: npm ci working-directory: runtime - run: npm run build @@ -48,7 +57,7 @@ jobs: mkdir -p ../packed npm pack --pack-destination ../packed mv ../packed/*.tgz ../packed/runtime.tgz - - uses: ComlineProject/observatory/.github/actions/report-size@v1 + - uses: ComlineProject/observatory/.github/actions/report-size@8d21b1fbe68f8b639676153ce1a308eaafdcc6a7 # v1 with: output: typescript.size.json toolchain: node ${{ steps.node.outputs.node-version }} @@ -60,15 +69,20 @@ jobs: # ci.yml does (same cache key, same rev). - id: reference run: echo "rev=$(cat runtime/core/CORE_REV)" >> "$GITHUB_OUTPUT" - - uses: actions/cache@v4 + - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 id: reference-cache with: path: ~/.cargo/bin/comline-reference key: comline-reference-${{ steps.reference.outputs.rev }} + # Keep in step with rust-toolchain.toml. - if: steps.reference-cache.outputs.cache-hit != 'true' - run: | - rustup update stable && rustup default stable - cargo install --locked --git https://github.com/ComlineProject/runtime --rev "${{ steps.reference.outputs.rev }}" comline-reference + uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1 + with: + toolchain: 1.99.1 + - if: steps.reference-cache.outputs.cache-hit != 'true' + env: + REV: ${{ steps.reference.outputs.rev }} + run: cargo install --locked --git https://github.com/ComlineProject/runtime --rev "$REV" comline-reference - run: echo "COMLINE_REFERENCE=$HOME/.cargo/bin/comline-reference" >> "$GITHUB_ENV" - name: Test with coverage @@ -80,17 +94,40 @@ jobs: - name: Convert coverage run: | python3 -I runtime/scripts/lcov-to-observatory.py runtime/coverage.lcov \ - typescript.coverage.json "${{ github.sha }}" "node $(node -p process.versions.node) test coverage" \ + typescript.coverage.json "$GITHUB_SHA" "node $(node -p process.versions.node) test coverage" \ "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" | tee -a "$GITHUB_STEP_SUMMARY" - - uses: actions/upload-artifact@v7 + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: reports path: | typescript.size.json typescript.coverage.json - - uses: ComlineProject/observatory/.github/actions/publish-report@v1 + if-no-files-found: error + + publish: + name: publish + needs: reports + if: github.event_name != 'pull_request' + runs-on: ubuntu-24.04 + timeout-minutes: 15 + permissions: + contents: write + steps: + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + # This job pushes to the reports branch with the checkout's token. + persist-credentials: true + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: reports + path: reports + - uses: ComlineProject/observatory/.github/actions/publish-report@8d21b1fbe68f8b639676153ce1a308eaafdcc6a7 # v1 with: - reports: typescript.size.json typescript.coverage.json + reports: reports/typescript.size.json reports/typescript.coverage.json readme: .github/reports-branch.md dry-run: ${{ github.ref != 'refs/heads/main' }} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..41ffaef --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "github>ComlineProject/.github:renovate-config" + ] +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..246cb22 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.99.1"