From de343e70e113f32460ed48ebf50e914d853b3b07 Mon Sep 17 00:00:00 2001 From: tignear Date: Tue, 27 Oct 2026 19:54:48 +0900 Subject: [PATCH] ci: qualify release-branch candidates outside the master queue Keep affected PR checks and a bounded combined-tree integration gate in the master queue. Move heavy backend/platform/conformance validation to release candidates and the daily/manual cadence, rather than rerunning it on each speculative queue tree or every master push. Release Please updates version PRs on master but cannot create releases. After a version PR merges, a dedicated staging workflow advances release to that exact merge commit without force-pushing. Staging has no concurrency group, so other PR closures and master pushes cannot discard its pending one-shot event. Release Candidate runs full CI on that fixed SHA. Only successful qualification can create the stable tag and GitHub Release and dispatch package publication. Reject superseded candidates, unrelated commits and existing tags at a different SHA. Retry publication only for the same qualified source. Both stable publishers require a successful Release Candidate run on release at their exact build SHA, including manual retries. They wait for the parent workflow to finish instead of duplicating full validation. Recovery commits can use validation_only on release before numbered recovery-tag publication. Nightly and independent Aplite publication retain their existing policies. After this change lands, run node scripts/configure-merge-checks.mjs --apply to replace deferred platform requirements with Queue validation on master. The dry-run-by-default migration preserves other checks and enforcement and refuses to apply before the replacement workflows exist on master. The release branch has been bootstrapped from master; no release has been published. Validation: 327 Node script tests; workflow syntax with actionlint (excluding its existing ubuntu-26.04-arm/cache-mode schema gaps); pnpm lint; diff checks. The unchanged queue command previously passed 260 tests (8 existing skips), and default workspace cargo check passed. Actual multi-platform qualification and publication require GitHub Actions after deployment. Change-Id: Ic5bb694d5d17ce58a1dd1cfc97a04c8777881dcb --- .github/workflows/ci-napi.yml | 23 ++- .github/workflows/ci.yml | 177 ++++++++++++----- .github/workflows/publish-crates.yml | 20 +- .github/workflows/release-candidate.yml | 83 ++++++++ .github/workflows/release.yml | 42 +--- .github/workflows/stage-release-candidate.yml | 47 +++++ CONTRIBUTING.md | 83 ++++++-- scripts/check-release-qualification.mjs | 28 +++ scripts/check-release-qualification.test.mjs | 21 ++ scripts/ci-changes.mjs | 29 +-- scripts/ci-changes.test.mjs | 71 ++----- scripts/ci-workflow.test.mjs | 34 ++-- scripts/configure-merge-checks.mjs | 57 ++++++ scripts/configure-merge-checks.test.mjs | 32 +++ scripts/promote-release-candidate.mjs | 54 ++++++ scripts/release-pr-update.test.mjs | 4 +- scripts/release-publication.test.mjs | 183 ++++++------------ scripts/release-validation.test.mjs | 100 ++++++++++ 18 files changed, 757 insertions(+), 331 deletions(-) create mode 100644 .github/workflows/release-candidate.yml create mode 100644 .github/workflows/stage-release-candidate.yml create mode 100644 scripts/check-release-qualification.mjs create mode 100644 scripts/check-release-qualification.test.mjs create mode 100644 scripts/configure-merge-checks.mjs create mode 100644 scripts/configure-merge-checks.test.mjs create mode 100644 scripts/promote-release-candidate.mjs create mode 100644 scripts/release-validation.test.mjs diff --git a/.github/workflows/ci-napi.yml b/.github/workflows/ci-napi.yml index 76645afad97..8200ecb90d1 100644 --- a/.github/workflows/ci-napi.yml +++ b/.github/workflows/ci-napi.yml @@ -133,6 +133,25 @@ jobs: if: env.NIGHTLY != 'true' run: node scripts/check-release-version.mjs + qualify: + name: Verify release branch qualification + needs: validate-release + if: ${{ !startsWith(inputs.channel, 'nightly-') }} + runs-on: ubuntu-latest + timeout-minutes: 12 + permissions: + contents: read + actions: read + steps: + - uses: actions/checkout@v7 + with: + ref: ${{ needs.validate-release.outputs.build_sha }} + - name: Require the successful candidate run + env: + GH_TOKEN: ${{ github.token }} + CANDIDATE_SHA: ${{ needs.validate-release.outputs.build_sha }} + run: node scripts/check-release-qualification.mjs + build: needs: validate-release cache-mode: write @@ -281,7 +300,8 @@ jobs: run: pnpm --filter="!@celox-sim/celox-napi" --filter="!@celox-sim/playground" -r test publish: - needs: [validate-release, test] + needs: [validate-release, test, qualify] + if: ${{ !cancelled() && needs.validate-release.result == 'success' && needs.test.result == 'success' && (needs.qualify.result == 'success' || (startsWith(inputs.channel, 'nightly-') && needs.qualify.result == 'skipped')) }} runs-on: ubuntu-latest name: Publish environment: npm @@ -318,6 +338,7 @@ jobs: - name: Download all artifacts uses: actions/download-artifact@v8 with: + pattern: bindings-* path: crates/celox-napi/artifacts - name: Create npm dirs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8fce6137741..5bfe3952428 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ name: CI # Ordinary PRs run focused checks; queue draft PRs run pre-merge validation. -# Keep merge_group during migration and rollback; landed pushes need no rerun. +# Heavy validation runs on release candidates and at the scheduled cadence. on: pull_request: merge_group: @@ -9,11 +9,17 @@ on: schedule: - cron: "17 1 * * *" workflow_dispatch: + workflow_call: + inputs: + validation_ref: + description: Immutable publication source SHA + required: true + type: string concurrency: # A new push must not cancel the daily full run halfway through its corpus. - group: ${{ github.workflow }}-${{ github.ref }}-${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && 'full' || 'changes' }} - cancel-in-progress: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} + group: ${{ github.workflow }}-${{ inputs.validation_ref || github.ref }}-${{ (inputs.validation_ref != '' || github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && 'full' || 'changes' }} + cancel-in-progress: ${{ inputs.validation_ref == '' && github.event_name != 'push' && github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} env: CARGO_INCREMENTAL: "0" @@ -29,8 +35,9 @@ jobs: STABLE_LANE: ${{ github.ref_name == 'master' || github.base_ref == 'master' || (github.event_name == 'merge_group' && github.event.merge_group.base_ref == 'refs/heads/master') }} outputs: queue: ${{ steps.classify.outputs.queue }} + full_validation: ${{ steps.classify.outputs.full_validation }} + fast_queue: ${{ steps.classify.outputs.fast_queue }} docs: ${{ steps.classify.outputs.docs }} - release: ${{ steps.classify.outputs.release }} javascript: ${{ steps.classify.outputs.javascript }} napi: ${{ steps.classify.outputs.napi }} napi_arm64: ${{ steps.classify.outputs.napi_arm64 }} @@ -52,8 +59,15 @@ jobs: rust_library_features: ${{ steps.classify.outputs.rust_library_features }} scripts: ${{ steps.classify.outputs.scripts }} steps: + - name: Validate qualification revision + if: inputs.validation_ref != '' + env: + VALIDATION_REF: ${{ inputs.validation_ref }} + run: '[[ "$VALIDATION_REF" =~ ^[0-9a-f]{40}$ ]]' + - uses: actions/checkout@v7 with: + ref: ${{ inputs.validation_ref || github.sha }} fetch-depth: 0 - name: Classify changed files @@ -61,8 +75,7 @@ jobs: env: BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || github.event.before }} HEAD_SHA: ${{ github.event.pull_request.head.sha || github.event.merge_group.head_sha || github.sha }} - FULL_VALIDATION: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} - MERGE_GROUP_BASE_REF: ${{ github.event.merge_group.base_ref || format('refs/heads/{0}', github.base_ref) }} + FULL_VALIDATION: ${{ contains(github.event.pull_request.labels.*.name, 'ci:full') || inputs.validation_ref != '' || github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} RELEASE_PLEASE_PR: ${{ github.event_name == 'pull_request' && github.head_ref == 'release-please--branches--master--components--celox' && github.event.pull_request.head.repo.full_name == github.repository }} QUEUE_VALIDATION: ${{ github.event_name != 'pull_request' || startsWith(github.head_ref, 'mergify/merge-queue/') || contains(github.event.pull_request.labels.*.name, 'ci:full') }} # Keep the classifier usable before the pinned toolchain is installed. @@ -80,6 +93,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 + with: + ref: ${{ inputs.validation_ref || github.sha }} - uses: pnpm/action-setup@v6 @@ -104,6 +119,7 @@ jobs: steps: - uses: actions/checkout@v7 with: + ref: ${{ inputs.validation_ref || github.sha }} submodules: recursive - name: Install Nix @@ -148,24 +164,24 @@ jobs: fi - name: cargo clippy - if: (needs.changes.result != 'success' || needs.changes.outputs.rust == 'true') && needs.changes.outputs.rust_full != 'false' + if: needs.changes.outputs.fast_queue != 'true' && ((needs.changes.result != 'success' || needs.changes.outputs.rust == 'true') && needs.changes.outputs.rust_full != 'false') run: cargo clippy --locked --workspace --exclude lydite-celox --all-targets --features celox/systemverilog,celox/cranelift,celox/wasm-runtime,celox/wasm-component,celox/veryl-reference,celox-vpi/cranelift,celox-vpi/wasm-runtime,celox-bench/cranelift,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim --no-deps - name: Lint the crates this pull request can affect - if: needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_lint_packages != '' + if: needs.changes.outputs.fast_queue != 'true' && (needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_lint_packages != '') env: BUILDS: ${{ needs.changes.outputs.rust_lint_builds }} run: | node scripts/run-ci-rust-scope.mjs lint - name: Build Rust API documentation - if: (needs.changes.result != 'success' || needs.changes.outputs.rust == 'true') && needs.changes.outputs.rust_full != 'false' + if: needs.changes.outputs.fast_queue != 'true' && ((needs.changes.result != 'success' || needs.changes.outputs.rust == 'true') && needs.changes.outputs.rust_full != 'false') env: RUSTDOCFLAGS: -D warnings run: cargo doc --locked --workspace --exclude lydite-celox --no-deps - name: Build the API documentation this pull request can affect - if: needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_doc_libraries != '' + if: needs.changes.outputs.fast_queue != 'true' && (needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_doc_libraries != '') env: RUSTDOCFLAGS: -D warnings LIBRARIES: ${{ needs.changes.outputs.rust_doc_libraries }} @@ -206,6 +222,11 @@ jobs: if: needs.changes.result == 'success' && needs.changes.outputs.rust == 'true' && needs.changes.outputs.scripts != 'true' run: node --test scripts/ci-changes.test.mjs scripts/ci-rust-scope.test.mjs scripts/ci-lydite-changes.test.mjs + - name: Check default workspace integration + if: needs.changes.outputs.fast_queue == 'true' && needs.changes.outputs.rust == 'true' + timeout-minutes: 20 + run: cargo check --locked --workspace --exclude 'lydite*' + rust-tests: name: Rust Tests needs: changes @@ -217,6 +238,7 @@ jobs: steps: - uses: actions/checkout@v7 with: + ref: ${{ inputs.validation_ref || github.sha }} submodules: recursive - uses: ./.github/actions/setup-rust @@ -230,12 +252,12 @@ jobs: run: node scripts/ci-rust-reports.mjs reset - uses: actions/setup-python@v7 - if: needs.changes.outputs.rust_vpi_e2e != 'false' + if: needs.changes.outputs.fast_queue != 'true' && (needs.changes.outputs.rust_vpi_e2e != 'false') with: python-version: "3.14" - name: Install cocotb - if: needs.changes.outputs.rust_vpi_e2e != 'false' + if: needs.changes.outputs.fast_queue != 'true' && (needs.changes.outputs.rust_vpi_e2e != 'false') run: python -m pip install cocotb==2.1.0 - name: Install cargo-nextest @@ -244,7 +266,7 @@ jobs: tool: cargo-nextest@0.9.144 - name: Build the optimized vtest executor - if: needs.changes.outputs.rust_full != 'false' || contains(format(' {0} ', needs.changes.outputs.rust_packages), ' celox ') + if: needs.changes.outputs.fast_queue != 'true' && (needs.changes.outputs.rust_full != 'false' || contains(format(' {0} ', needs.changes.outputs.rust_packages), ' celox ')) run: node scripts/run-vtest.mjs --prepare-ci # Enable the frontend and suite features together so common integration @@ -252,31 +274,40 @@ jobs: # nextest schedules tests from all binaries on one pool; `cargo test` # runs the binaries one after another. # A pull request builds and runs only the tests its changes can affect - # (scripts/ci-rust-scope.mjs); merge groups and the daily run keep the + # (scripts/ci-rust-scope.mjs); post-merge and release validation keep the # Celox workspace. lydite-checks.yml owns Lydite tests at its own cadence. - name: Run workspace tests with CI features id: workspace-tests - if: needs.changes.outputs.rust_full != 'false' + if: needs.changes.outputs.fast_queue != 'true' && (needs.changes.outputs.rust_full != 'false') run: >- cargo nextest run --locked --workspace --exclude 'lydite*' --profile ci --features celox/systemverilog,celox/cranelift,celox/wasm-runtime,celox/wasm-component,celox/veryl-reference,celox-vpi/cranelift,celox-vpi/wasm-runtime,celox-bench/cranelift,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim,celox-test-suite/runtime-cases - name: Run the tests this pull request can affect id: scoped-tests - if: needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_packages != '' + if: needs.changes.outputs.fast_queue != 'true' && (needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_packages != '') env: BUILDS: ${{ needs.changes.outputs.rust_builds }} FILTER: ${{ needs.changes.outputs.rust_filter }} run: | node scripts/run-ci-rust-scope.mjs test + - name: Run merge queue integration tests + id: queue-tests + if: needs.changes.outputs.fast_queue == 'true' + timeout-minutes: 20 + run: >- + cargo nextest run --locked -p celox --features systemverilog --profile ci + --test counter --test hierarchy --test native_exec + --test simulation_limits --test sv_unit_scope --test sv_packages + - name: Collect Rust test reports if: success() || failure() run: node scripts/ci-rust-reports.mjs collect - name: Run cocotb VPI end-to-end test id: cocotb-tests - if: needs.changes.outputs.rust_vpi_e2e != 'false' + if: needs.changes.outputs.fast_queue != 'true' && (needs.changes.outputs.rust_vpi_e2e != 'false') env: RUST_FULL: ${{ needs.changes.outputs.rust_full }} BUILDS: ${{ needs.changes.outputs.rust_builds }} @@ -298,17 +329,17 @@ jobs: token: ${{ secrets.MERGIFY_TOKEN }} report_path: work/ci-reports/rust/*.xml job_name: rust-tests - test_step_outcome: ${{ steps.cocotb-tests.outcome == 'failure' && 'failure' || steps.workspace-tests.outcome != 'skipped' && steps.workspace-tests.outcome || steps.scoped-tests.outcome }} + test_step_outcome: ${{ steps.queue-tests.outcome != 'skipped' && steps.queue-tests.outcome || steps.cocotb-tests.outcome == 'failure' && 'failure' || steps.workspace-tests.outcome != 'skipped' && steps.workspace-tests.outcome || steps.scoped-tests.outcome }} # nextest does not run documentation tests. - name: Run workspace documentation tests with CI features - if: needs.changes.outputs.rust_full != 'false' + if: needs.changes.outputs.fast_queue != 'true' && (needs.changes.outputs.rust_full != 'false') run: >- cargo test --locked --workspace --exclude 'lydite*' --doc --features celox/systemverilog,celox/cranelift,celox/wasm-runtime,celox/wasm-component,celox/veryl-reference,celox-vpi/cranelift,celox-vpi/wasm-runtime,celox-bench/cranelift,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim,celox-test-suite/runtime-cases - name: Run the documentation tests of the changed libraries - if: needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_libraries != '' + if: needs.changes.outputs.fast_queue != 'true' && (needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_libraries != '') env: LIBRARIES: ${{ needs.changes.outputs.rust_libraries }} FEATURES: ${{ needs.changes.outputs.rust_library_features }} @@ -317,15 +348,15 @@ jobs: for package in $LIBRARIES; do args+=(-p "$package"); done if [ -n "$FEATURES" ]; then args+=(--features "$FEATURES"); fi cargo test --locked --doc "${args[@]}" - rust-default-tests: name: Rust default-feature tests needs: changes - if: ${{ !cancelled() && (needs.changes.result != 'success' || (needs.changes.outputs.rust == 'true' && (needs.changes.outputs.rust_full != 'false' || contains(format(' {0} ', needs.changes.outputs.rust_libraries), ' celox ')))) }} + if: ${{ !cancelled() && needs.changes.outputs.fast_queue != 'true' && (needs.changes.result != 'success' || (needs.changes.outputs.rust == 'true' && (needs.changes.outputs.rust_full != 'false' || contains(format(' {0} ', needs.changes.outputs.rust_libraries), ' celox ')))) }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 with: + ref: ${{ inputs.validation_ref || github.sha }} submodules: recursive - uses: ./.github/actions/setup-rust - uses: Swatinem/rust-cache@v2 @@ -339,9 +370,8 @@ jobs: external-suites: name: External suite (${{ matrix.suite }}, ${{ matrix.tool }}) needs: changes - # Scheduled and manual runs compare even when change detection fails. A - # merge group that cuts a release also compares before it can merge. - if: ${{ !cancelled() && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || needs.changes.outputs.release == 'true') }} + # External comparisons belong to full validation, never the merge queue. + if: ${{ !cancelled() && needs.changes.outputs.full_validation == 'true' }} runs-on: ubuntu-latest timeout-minutes: 90 strategy: @@ -359,6 +389,7 @@ jobs: steps: - uses: actions/checkout@v7 with: + ref: ${{ inputs.validation_ref || github.sha }} submodules: recursive # Use the same locked tool versions as the retained exclusion evidence. @@ -438,11 +469,14 @@ jobs: common-cells: name: Upstream SystemVerilog testbench - if: ${{ !cancelled() && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') }} + needs: changes + if: ${{ !cancelled() && needs.changes.outputs.full_validation == 'true' }} runs-on: ubuntu-latest timeout-minutes: 30 steps: - uses: actions/checkout@v7 + with: + ref: ${{ inputs.validation_ref || github.sha }} - uses: ./.github/actions/setup-rust @@ -482,11 +516,13 @@ jobs: sv-tests: name: sv-tests conformance needs: changes - if: ${{ !cancelled() && (needs.changes.result != 'success' || (needs.changes.outputs.rust == 'true' && needs.changes.outputs.rust_sv_tests != 'false')) }} + if: ${{ !cancelled() && needs.changes.outputs.fast_queue != 'true' && (needs.changes.result != 'success' || (needs.changes.outputs.rust == 'true' && needs.changes.outputs.rust_sv_tests != 'false')) }} runs-on: ubuntu-latest timeout-minutes: 60 steps: - uses: actions/checkout@v7 + with: + ref: ${{ inputs.validation_ref || github.sha }} - uses: ./.github/actions/setup-rust @@ -569,6 +605,7 @@ jobs: steps: - uses: actions/checkout@v7 with: + ref: ${{ inputs.validation_ref || github.sha }} submodules: recursive - uses: ./.github/actions/setup-rust @@ -607,11 +644,12 @@ jobs: napi-wasm: name: NAPI WASM Build & Test needs: changes - if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.napi == 'true') }} + if: ${{ !cancelled() && needs.changes.outputs.fast_queue != 'true' && (needs.changes.result != 'success' || needs.changes.outputs.napi == 'true') }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 with: + ref: ${{ inputs.validation_ref || github.sha }} submodules: recursive - uses: ./.github/actions/setup-rust @@ -670,19 +708,19 @@ jobs: CHANGES_RESULT: ${{ needs.changes.result }} RUST_REQUIRED: ${{ needs.changes.outputs.rust }} RUST_RESULT: ${{ needs.rust-tests.result }} - DEFAULT_REQUIRED: ${{ needs.changes.result != 'success' || (needs.changes.outputs.rust == 'true' && (needs.changes.outputs.rust_full != 'false' || contains(format(' {0} ', needs.changes.outputs.rust_libraries), ' celox '))) }} + DEFAULT_REQUIRED: ${{ needs.changes.outputs.fast_queue != 'true' && (needs.changes.result != 'success' || (needs.changes.outputs.rust == 'true' && (needs.changes.outputs.rust_full != 'false' || contains(format(' {0} ', needs.changes.outputs.rust_libraries), ' celox ')))) }} DEFAULT_RESULT: ${{ needs.rust-default-tests.result }} - SV_TESTS_REQUIRED: ${{ needs.changes.outputs.rust != 'false' && needs.changes.outputs.rust_sv_tests != 'false' }} + SV_TESTS_REQUIRED: ${{ needs.changes.outputs.fast_queue != 'true' && needs.changes.outputs.rust != 'false' && needs.changes.outputs.rust_sv_tests != 'false' }} SV_TESTS_RESULT: ${{ needs.sv-tests.result }} - # Platform coverage is mandatory in queue and full validation runs. - ARM64_REQUIRED: ${{ needs.changes.outputs.queue != 'false' && needs.changes.outputs.rust != 'false' }} + # Platform coverage is mandatory in full validation, outside the queue. + ARM64_REQUIRED: ${{ needs.changes.outputs.full_validation != 'false' && needs.changes.outputs.rust != 'false' }} ARM64_RESULT: ${{ needs.arm64-backend.result }} NAPI_REQUIRED: ${{ needs.changes.outputs.napi }} NATIVE_RESULT: ${{ needs.napi-linux.result }} + WASM_REQUIRED: ${{ needs.changes.outputs.fast_queue != 'true' && needs.changes.outputs.napi != 'false' }} WASM_RESULT: ${{ needs.napi-wasm.result }} - # Only a release merge group gates on the comparisons. Full runs report - # them through report-full-validation instead. - RELEASE_REQUIRED: ${{ needs.changes.outputs.release }} + # Every full run requires external comparisons as well as Celox tests. + RELEASE_REQUIRED: ${{ needs.changes.outputs.full_validation }} EXTERNAL_RESULT: ${{ needs.external-suites.result }} steps: - name: Check tests and builds @@ -703,7 +741,7 @@ jobs: if [ "$NAPI_REQUIRED" != false ] || [ "$NATIVE_RESULT" != skipped ]; then test "$NATIVE_RESULT" = success fi - if [ "$NAPI_REQUIRED" != false ] || [ "$WASM_RESULT" != skipped ]; then + if [ "$WASM_REQUIRED" != false ] || [ "$WASM_RESULT" != skipped ]; then test "$WASM_RESULT" = success fi if [ "$RELEASE_REQUIRED" != false ]; then @@ -713,12 +751,13 @@ jobs: arm64-backend: name: ARM64 Backend Test needs: changes - # Full platform checks run once in the queue, not on every PR push. - if: ${{ !cancelled() && needs.changes.outputs.queue != 'false' && (needs.changes.result != 'success' || needs.changes.outputs.rust == 'true') }} + # Full platform checks run after landing and before publication. + if: ${{ !cancelled() && needs.changes.outputs.full_validation != 'false' && (needs.changes.result != 'success' || needs.changes.outputs.rust == 'true') }} runs-on: ubuntu-26.04-arm steps: - uses: actions/checkout@v7 with: + ref: ${{ inputs.validation_ref || github.sha }} submodules: recursive - uses: ./.github/actions/setup-rust @@ -758,11 +797,12 @@ jobs: napi-windows: name: NAPI Build (Windows) needs: changes - if: ${{ !cancelled() && needs.changes.outputs.queue != 'false' && (needs.changes.result != 'success' || needs.changes.outputs.napi == 'true') }} + if: ${{ !cancelled() && needs.changes.outputs.full_validation != 'false' && (needs.changes.result != 'success' || needs.changes.outputs.napi == 'true') }} runs-on: windows-latest steps: - uses: actions/checkout@v7 with: + ref: ${{ inputs.validation_ref || github.sha }} submodules: recursive - uses: ./.github/actions/setup-rust @@ -796,11 +836,12 @@ jobs: napi-linux-arm64: name: NAPI Build (Linux ARM64 GNU) needs: changes - if: ${{ !cancelled() && needs.changes.outputs.queue != 'false' && (needs.changes.result != 'success' || needs.changes.outputs.napi_arm64 == 'true') }} + if: ${{ !cancelled() && needs.changes.outputs.full_validation != 'false' && (needs.changes.result != 'success' || needs.changes.outputs.napi_arm64 == 'true') }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 with: + ref: ${{ inputs.validation_ref || github.sha }} submodules: recursive - uses: ./.github/actions/setup-rust @@ -844,6 +885,7 @@ jobs: steps: - uses: actions/checkout@v7 with: + ref: ${{ inputs.validation_ref || github.sha }} submodules: recursive - uses: pnpm/action-setup@v6 @@ -885,11 +927,12 @@ jobs: js-windows: name: JS Test (Windows) needs: [changes, napi-windows] - if: ${{ !cancelled() && needs.changes.outputs.queue != 'false' && (needs.changes.result != 'success' || needs.changes.outputs.javascript == 'true') }} + if: ${{ !cancelled() && needs.changes.outputs.full_validation != 'false' && (needs.changes.result != 'success' || needs.changes.outputs.javascript == 'true') }} runs-on: windows-latest steps: - uses: actions/checkout@v7 with: + ref: ${{ inputs.validation_ref || github.sha }} submodules: recursive - uses: pnpm/action-setup@v6 @@ -917,12 +960,13 @@ jobs: playground-browser: name: Playground Browser Test needs: [changes, napi-wasm] - if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.javascript == 'true' || needs.changes.outputs.napi == 'true') }} + if: ${{ !cancelled() && needs.changes.outputs.fast_queue != 'true' && (needs.changes.result != 'success' || needs.changes.outputs.javascript == 'true' || needs.changes.outputs.napi == 'true') }} runs-on: ubuntu-latest timeout-minutes: 15 steps: - uses: actions/checkout@v7 with: + ref: ${{ inputs.validation_ref || github.sha }} submodules: recursive - uses: pnpm/action-setup@v6 @@ -974,11 +1018,11 @@ jobs: docs: changed.docs === "true", lint: [changed.rust, changed.javascript, changed.scripts].includes("true"), rust: [changed.rust, changed.napi].includes("true"), - "napi-windows": changed.napi === "true", - "napi-linux-arm64": changed.napi_arm64 === "true", + "napi-windows": changed.full_validation === "true" && changed.napi === "true", + "napi-linux-arm64": changed.full_validation === "true" && changed.napi_arm64 === "true", "js-ubuntu": changed.javascript === "true", - "js-windows": changed.javascript === "true", - "playground-browser": [changed.napi, changed.javascript].includes("true"), + "js-windows": changed.full_validation === "true" && changed.javascript === "true", + "playground-browser": changed.fast_queue !== "true" && [changed.napi, changed.javascript].includes("true"), }; if (Object.entries(required).some(([name, required]) => required && jobs[name].result !== "success") || jobs.changes.result !== "success" || jobs.changes.outputs.queue !== "true" || @@ -987,12 +1031,48 @@ jobs: } ' - # Report daily/manual runs independently of merge queue validation. + # Fail closed: skipped full coverage cannot qualify a release. + full-validation: + name: Release qualification + needs: + [ + changes, + queue-validation, + docs, + lint, + rust-tests, + rust-default-tests, + sv-tests, + external-suites, + common-cells, + napi-linux, + napi-wasm, + rust, + arm64-backend, + napi-windows, + napi-linux-arm64, + js-ubuntu, + js-windows, + playground-browser, + ] + if: ${{ always() && needs.changes.outputs.full_validation == 'true' }} + runs-on: ubuntu-latest + env: + NEEDS: ${{ toJSON(needs) }} + steps: + - name: Require every full-validation job + run: | + node --input-type=module -e ' + const jobs = JSON.parse(process.env.NEEDS); + if (Object.values(jobs).some(job => job.result !== "success")) process.exit(1); + ' + report-full-validation: name: Report full validation needs: [ changes, + full-validation, queue-validation, docs, lint, @@ -1011,7 +1091,7 @@ jobs: js-windows, playground-browser, ] - if: ${{ !cancelled() && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && (github.ref_name == 'master' || github.ref_name == 'develop') }} + if: ${{ !cancelled() && inputs.validation_ref == '' && (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && (github.ref_name == 'master' || github.ref_name == 'develop') }} runs-on: ubuntu-latest permissions: contents: read @@ -1019,6 +1099,7 @@ jobs: steps: - uses: actions/checkout@v7 with: + ref: ${{ inputs.validation_ref || github.sha }} sparse-checkout: scripts - name: Open, update, or close the full CI issue diff --git a/.github/workflows/publish-crates.yml b/.github/workflows/publish-crates.yml index 1854ecf87d2..54b0e53e36d 100644 --- a/.github/workflows/publish-crates.yml +++ b/.github/workflows/publish-crates.yml @@ -76,6 +76,24 @@ jobs: - name: Check synchronized release versions run: node scripts/check-release-version.mjs + qualify: + name: Verify release branch qualification + needs: validate + runs-on: ubuntu-latest + timeout-minutes: 12 + permissions: + contents: read + actions: read + steps: + - uses: actions/checkout@v7 + with: + ref: ${{ github.sha }} + - name: Require the successful candidate run + env: + GH_TOKEN: ${{ github.token }} + CANDIDATE_SHA: ${{ github.sha }} + run: node scripts/check-release-qualification.mjs + package: name: Package and test needs: validate @@ -111,7 +129,7 @@ jobs: publish: name: Publish to crates.io - needs: [validate, package] + needs: [validate, package, qualify] runs-on: ubuntu-latest environment: crates-io permissions: diff --git a/.github/workflows/release-candidate.yml b/.github/workflows/release-candidate.yml new file mode 100644 index 00000000000..fe577c580a0 --- /dev/null +++ b/.github/workflows/release-candidate.yml @@ -0,0 +1,83 @@ +name: Release Candidate + +on: + push: + branches: [release] + workflow_dispatch: + inputs: + validation_only: + description: Qualify a recovery SHA without creating a stable release + type: boolean + default: false + +# A newer RC must not cancel qualification of a running candidate. +concurrency: + group: release-candidate + cancel-in-progress: false + +permissions: + contents: read + +jobs: + candidate: + name: Resolve release candidate + if: github.ref == 'refs/heads/release' + runs-on: ubuntu-latest + outputs: + sha: ${{ steps.candidate.outputs.sha }} + tag: ${{ steps.candidate.outputs.tag }} + steps: + - uses: actions/checkout@v7 + with: + ref: ${{ github.sha }} + fetch-depth: 0 + - name: Validate candidate identity + id: candidate + run: | + git merge-base --is-ancestor HEAD origin/master + node scripts/check-release-version.mjs + tag="v$(tr -d '\r\n' < VERSION)" + [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] + echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + echo "tag=$tag" >> "$GITHUB_OUTPUT" + + qualify: + name: Qualify release candidate + needs: candidate + uses: ./.github/workflows/ci.yml + permissions: + contents: read + issues: write + with: + validation_ref: ${{ needs.candidate.outputs.sha }} + secrets: inherit + + publish: + name: Promote qualified candidate + if: inputs.validation_only != true + needs: [candidate, qualify] + runs-on: ubuntu-latest + steps: + - name: Create release app token + id: release-token + uses: actions/create-github-app-token@v3 + with: + app-id: ${{ vars.RELEASE_APP_ID }} + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + permission-pull-requests: write + permission-issues: write + permission-actions: write + permission-contents: write + permission-workflows: write + + - uses: actions/checkout@v7 + with: + ref: ${{ needs.candidate.outputs.sha }} + fetch-depth: 0 + + - name: Publish the qualified candidate + env: + GH_TOKEN: ${{ steps.release-token.outputs.token }} + CANDIDATE_SHA: ${{ needs.candidate.outputs.sha }} + RELEASE_TAG: ${{ needs.candidate.outputs.tag }} + run: node scripts/promote-release-candidate.mjs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eb1f128ed34..5452365a188 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -59,48 +59,10 @@ jobs: token: ${{ steps.release-token.outputs.token }} config-file: release-please-config.json manifest-file: .release-please-manifest.json - # Keep tag/Release creation active when a frozen PR has merged. + # Version PRs land on master; only the release branch publishes. + skip-github-release: true skip-github-pull-request: ${{ steps.release-pr.outputs.frozen == 'true' }} - # A merge queue can push several merged PRs together. The release tag - # then points at an earlier commit than github.sha. Publish the tag that - # release-please actually created, including on scheduled/manual runs. - - name: Queue package publication for this release - if: steps.release.outputs.release_created == 'true' - env: - GH_TOKEN: ${{ steps.release-token.outputs.token }} - RELEASE_TAG: ${{ steps.release.outputs.tag_name }} - shell: bash - run: | - release_tag="$RELEASE_TAG" - if [[ ! "$release_tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "Expected a v-prefixed stable release tag, got $release_tag." >&2 - exit 1 - fi - - published_tag="$( - gh release view "$release_tag" \ - --repo "$GITHUB_REPOSITORY" \ - --json tagName,isDraft,isPrerelease \ - --jq 'select(.isDraft == false and .isPrerelease == false) | .tagName' - )" - if [ "$published_tag" != "$release_tag" ]; then - echo "Published GitHub Release $release_tag was not found." >&2 - exit 1 - fi - - jq -n \ - --arg tag "$release_tag" \ - '{event_type: "napi-release", client_payload: {tag: $tag}}' \ - | gh api \ - --method POST \ - "repos/$GITHUB_REPOSITORY/dispatches" \ - --input - - - gh workflow run publish-crates.yml \ - --repo "$GITHUB_REPOSITORY" \ - --ref "$release_tag" - queue-release: name: Queue weekly release needs: release-please diff --git a/.github/workflows/stage-release-candidate.yml b/.github/workflows/stage-release-candidate.yml new file mode 100644 index 00000000000..f54b65074a2 --- /dev/null +++ b/.github/workflows/stage-release-candidate.yml @@ -0,0 +1,47 @@ +name: Stage Release Candidate + +on: + pull_request: + types: [closed] + branches: [master] + +# Each merged release PR must reach staging. Do not put these one-shot events +# in a concurrency group: even cancel-in-progress: false replaces pending runs. +# The non-force push below prevents an older event from rewinding release. +permissions: {} + +jobs: + stage-candidate: + name: Stage release candidate + if: >- + github.event_name == 'pull_request' && github.event.pull_request.merged == true && + github.event.pull_request.head.repo.full_name == github.repository && + github.event.pull_request.head.ref == 'release-please--branches--master--components--celox' + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Create release app token + id: release-token + uses: actions/create-github-app-token@v3 + with: + app-id: ${{ vars.RELEASE_APP_ID }} + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + permission-contents: write + permission-workflows: write + + - uses: actions/checkout@v7 + with: + ref: ${{ github.event.pull_request.merge_commit_sha }} + fetch-depth: 0 + token: ${{ steps.release-token.outputs.token }} + + - name: Advance release to the merged candidate + env: + CANDIDATE_SHA: ${{ github.event.pull_request.merge_commit_sha }} + run: | + test "$(git rev-parse HEAD)" = "$CANDIDATE_SHA" + node scripts/check-release-version.mjs + # No force push: release contains only successive master candidates. + git push origin "$CANDIDATE_SHA:refs/heads/release" + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index def9181d534..999956839cf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -89,7 +89,8 @@ CI keeps the normal test profile and existing dependency cache: sharing a Cargo profile alone does not share artifacts when the executor and workspace resolve different dependency features. Ordinary Cargo test commands retain the embedded, in-process path. CI's Rust Tests job prepares the executor once and uses it for -full workspace runs and scoped runs that include Celox. Scopes without Celox +full workspace runs and scoped PR runs that include Celox. The merge queue +runs a small integration set directly, without building the all-backend executor. Scopes without Celox skip that build. The default-branch cache warmer builds both executor and test dependencies under the same cache key; preparation failures fail the test job. Cocotb runs through nextest with the exact packages, features and targets of its @@ -140,7 +141,7 @@ Daily CI uses `--fresh` and runs the complete corpus afresh. ## Compilation scaling in CodSpeed -Normal PR and merge-queue CI retains small nested-write semantic regressions on +Affected PR and full CI retain small nested-write semantic regressions on interpreter, native and Cranelift backends in both two-state and four-state modes, wide-value latch checks, and a small sorter compilation smoke test. The 257/512-bit per-bit graph cases and sorter sizes 4/8/16/32 are measured by @@ -223,9 +224,8 @@ mixed Rust changes and unknown paths retain their existing coverage. Pull requests use `scripts/ci-changes.mjs` to select jobs and scope Rust tests -by affected crates. Windows and ARM64 checks run in Mergify queue draft PRs, -legacy merge groups, and daily/manual full runs. Queue drafts run the full Celox Rust -workspace when Rust is affected. Mergify checks up to five batches concurrently +by affected crates. Windows and ARM64 checks run during release/daily/manual full validation. Queue drafts and legacy merge groups +use the bounded integration checks described below. Mergify checks up to five batches concurrently across three queue rules. Parallel mode separates independent file scopes while retaining combined-tree validation for overlapping scopes: @@ -273,13 +273,17 @@ marker chain, so a stack branch without it is still refused. Lydite tests use the independent change-selected and daily cadence described below, including on Mergify queue draft PRs. The `Queue validation` merge condition requires the selected checks in `ci.yml` to pass; -ordinary PR checks cannot satisfy it. The `ci:full` label opts a PR into the -same coverage on its next push. Unrelated paths may still skip jobs. +ordinary PR checks cannot satisfy it. The queue checks the combined tree with +format/script checks, default workspace compilation, a bounded native/SV test +set, and affected Linux NAPI/JS integration. It does not rerun the complete +backend matrix, sv-tests, default-feature/doctests, WASI/browser, Windows, +ARM64 or external simulator comparisons. The `ci:full` label opts a PR into +full coverage on its next push. Unrelated paths may still skip queue jobs. - Enable both Merge Queue and Workflow Automation in Mergify; the latter runs the label-based queue rule. -- Version-only Release Please PRs defer product tests to the queue, where the - release manifest change requires full validation including external suites. +- Version-only Release Please PRs use the same lightweight queue. Their merged SHA advances `release`; full product + qualification there gates all release publication instead. - Add `merge-ready` to request automatic queueing, or comment `@mergifyio queue` for an ordinary PR. A failed queue entry receives `dequeued`; investigate it, remove that label, and request queueing again. There is no automatic retry loop. @@ -299,8 +303,9 @@ same coverage on its next push. Unrelated paths may still skip jobs. validates the combined tree instead of updating every original PR. Required status checks remain enabled. Keep the `Queue validation` merge condition. - `merge_group` remains supported for rollback to GitHub's native queue. -- The queue validates the tree before it lands, so pushes to `master` and - `develop` do not run CI again. Daily full runs keep those branches' caches warm. +- Ordinary master pushes do not launch another full matrix. Heavy validation + runs on `release` candidates and at the daily/manual cadence, so ordinary + development does not continuously compete with the queue for those runners. - `sync-develop.yml` opens or updates the master-to-develop synchronization pull request once a day (22:07 UTC) rather than on every master push. Dispatch it to sync sooner. @@ -387,25 +392,26 @@ Ordinary PRs also scope Rust compilation and execution: and downstream consumers do not select this separate release-mode build. - Python/cocotb setup runs only when VPI tests are selected. -Queue drafts, merge groups, releases, `ci:full`, and daily/manual full runs -retain the existing workspace tests, lint, documentation, sv-tests and platform -coverage. Cargo manifest, lockfile, toolchain, unknown-path and failed scope -analysis changes fall back to broad validation. Required checks permit skips +Release qualification, `ci:full` and daily/manual full runs +retain workspace tests, lint, documentation, sv-tests and platform coverage. +On ordinary PRs, Cargo manifest, lockfile, toolchain, unknown-path and failed +scope analysis changes fall back to broad validation. Queue drafts keep their +bounded integration set even for these changes. Required checks permit skips only when explicitly unneeded and still reject failures and cancellations. Local validation uses the behavior-based matrix above. | Cadence | Coverage | | --- | --- | +| On a candidate push to `release` | Full CI on the fixed candidate SHA, followed by stable tag/GitHub Release creation and package dispatch only after success. Stable publishers verify this successful branch run, including manual retries and recovery tags. | | Daily at 01:17 UTC (10:17 JST) | Full `ci.yml` on the default branch, with every change-classifier output enabled. Includes native/WASI NAPI, JS/browser tests, ARM64, script tests, and all ordinary Celox workspace tests. | | Daily from `nightly.yml` at 02:43 UTC (11:43 JST) | Dispatch the same full CI on `develop`, with detection of its Veryl dependency lane. Queue nightly packages and the small pinned/HEAD Heliodor Linux boot compatibility checks. | | Daily at 01:47 UTC (10:47 JST) | `bench.yml` measures Rust, Verilator, and TypeScript on one host and publishes master history. Manual dispatch supports branch measurements. | | Daily at 02:17 UTC (11:17 JST) | `codspeed.yml` measures compile time on the default branch using CPU simulation. Execution failures and CodSpeed performance-check failures open or update a branch issue; the next healthy run closes it. Manual dispatch supports branch measurements. PRs, merge groups, and pushes do not run CodSpeed. | | Daily at 02:37 UTC (11:37 JST) | `heliodor-bench.yml` runs the complete master Linux suite on x86-64 and AArch64. Explicit manual selections retain focused suite runs and ARM64 profiling. PRs do not run this workflow; its tooling tests run in `Lint & Format` with the other script tests. | -| Every daily/manual full CI run | Run the pinned upstream `common_cells` Gray code SV TB through `celox run --project`, plus an assertion negative control. Logs are retained for 14 days and failures feed the Full CI issue. See [the reproduction instructions](conformance/common-cells/README.md). | +| Every full CI run | Run the pinned upstream `common_cells` Gray code SV TB through `celox run --project`, plus an assertion negative control. Logs are retained for 14 days and failures feed the Full CI issue. See [the reproduction instructions](conformance/common-cells/README.md). | | Every full CI run | Run every shared Veryl and SystemVerilog case against both Verilator and Icarus, with locked Nix tools. Run the live adapter tests normally marked ignored because they need external tools. Preserve reports and per-case diagnostics as artifacts for 14 days, including on failure; matrix failures do not cancel the other comparisons. | | Affected pull requests and merge groups; daily at 03:41 UTC (12:41 JST); on demand | `lydite-checks.yml` owns Lydite Rust tests, proof, conformance, editor, and mutation gates. Unrelated changes skip these jobs. Bridge gates are disabled; daily and manual runs enable only core lanes and report failures in an issue. | | On demand | Dispatch `ci.yml` on the desired branch to run full CI and external comparisons, regardless of its diff. | -| Pull requests that cut a release | A `master` pull request or legacy merge group whose diff changes `.release-please-manifest.json` (only the release pull request does there; syncing it into `develop` is not a release) runs full CI and the external comparisons. `Rust Test & NAPI Build` then requires the comparisons to pass, so a release cannot merge after only change-based checks. Daily and manual full runs do not gate on the comparisons; their failures reach the full CI issue below. A `master` pull request or legacy merge group whose diff cannot be determined is treated the same way. | Full runs have a separate concurrency group so ordinary pushes cannot cancel them. Scheduled and dispatched full runs on `master` and `develop` end with @@ -422,6 +428,49 @@ endings, including checkout-dependent Verilator padding; wording and source locations must match. Improvements may pass without updating the baseline. Baseline changes require review rather than automatic acceptance of a new run. +Release Please on `master` only updates the version PR; it cannot create tags +or GitHub releases. A dedicated `stage-release-candidate.yml` handles each +merged version PR without a concurrency group, so master pushes and other PR +closures cannot replace a pending staging event. The release App advances the `release` +branch to its exact merge commit without force-pushing. The App-authenticated +push starts `release-candidate.yml` on that branch, independently of the master +queue. The branch is a sequence of master release candidates, not a development +branch. A normal master merge never advances it. + +The candidate workflow passes its fixed SHA to full CI. All checkouts use that +SHA, and all required jobs must succeed. Only then may the promotion job create +the stable tag and GitHub Release, followed by package publication dispatches. +Promotion rejects superseded candidates, candidates that are not merged release +PRs, and tags pointing at a different SHA. Retrying an existing release is +allowed only for the same qualified SHA. Release notes come from GitHub's +release-note generator; the version PR still updates the checked-in changelog. + +Both stable publishers verify that `release-candidate.yml` succeeded on the +`release` branch at their exact build SHA. They wait briefly for the dispatching +candidate workflow to finish, rather than rerunning the full suite. A failed, +cancelled, skipped, unrelated-branch or different-SHA run cannot authorize +publication. npm downloads only `bindings-*` release artifacts. Nightly and +independent Aplite publication retain their existing policies. + +For a numbered crate recovery tag, advance `release` to the recovery commit +(which must be on master), then dispatch Release Candidate on `release` with +`validation_only=true`. This runs full qualification without creating or moving +a stable tag. Publish the numbered recovery tag only after that run succeeds. + +After this workflow change lands on `master`, migrate its GitHub ruleset: + +```sh +node scripts/configure-merge-checks.mjs # inspect the proposed ruleset +node scripts/configure-merge-checks.mjs --apply # requires repository administration access +``` + +The migration removes the Windows NAPI, Windows JS and ARM64 NAPI required +checks and adds `Queue validation`. It preserves the other checks, enforcement, +branch conditions and bypass policy. It refuses to apply before the queue and +publisher changes exist on `master`. Mergify still requires a genuinely +successful `Queue validation`; it does not receive a bypass. Before this +migration, the old platform requirements can still impede queue admission. + Scheduled workflows begin using this configuration after it reaches the default branch; the develop dispatch also requires the updated `ci.yml` on `develop`. diff --git a/scripts/check-release-qualification.mjs b/scripts/check-release-qualification.mjs new file mode 100644 index 00000000000..603b750597c --- /dev/null +++ b/scripts/check-release-qualification.mjs @@ -0,0 +1,28 @@ +import { execFileSync } from "node:child_process"; +import { pathToFileURL } from "node:url"; + +export function qualificationState(runs, sha) { + const candidates = runs.filter(run => run.head_sha === sha && run.head_branch === "release" && ["push", "workflow_dispatch"].includes(run.event)); + if (candidates.some(run => run.status === "completed" && run.conclusion === "success")) return "success"; + if (candidates.some(run => ["queued", "in_progress", "waiting", "pending", "requested"].includes(run.status))) return "pending"; + return "missing"; +} + +export async function requireQualification({ sha, runs, now = Date.now, sleep = ms => new Promise(resolve => setTimeout(resolve, ms)), timeout = 600_000 }) { + if (!/^[0-9a-f]{40}$/.test(sha)) throw new Error("Expected an immutable release SHA"); + const deadline = now() + timeout; + for (;;) { + const state = qualificationState(await runs(), sha); + if (state === "success") return; + if (state !== "pending") throw new Error("No successful Release Candidate run for this release SHA"); + if (now() >= deadline) throw new Error("Release Candidate workflow did not finish successfully before the deadline"); + await sleep(10_000); + } +} + +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + const repository = process.env.GITHUB_REPOSITORY; + const sha = process.env.CANDIDATE_SHA; + if (!/^[\w.-]+\/[\w.-]+$/.test(repository)) throw new Error("Invalid repository"); + await requireQualification({ sha, runs: () => JSON.parse(execFileSync("gh", ["api", `repos/${repository}/actions/workflows/release-candidate.yml/runs?head_sha=${sha}&branch=release&per_page=100`], { encoding: "utf8" })).workflow_runs }); +} diff --git a/scripts/check-release-qualification.test.mjs b/scripts/check-release-qualification.test.mjs new file mode 100644 index 00000000000..ff2a1f6e4f6 --- /dev/null +++ b/scripts/check-release-qualification.test.mjs @@ -0,0 +1,21 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { qualificationState, requireQualification } from "./check-release-qualification.mjs"; +const sha = "a".repeat(40); +const good = { head_sha: sha, head_branch: "release", event: "push", status: "completed", conclusion: "success" }; +test("only a successful release-branch run at the exact SHA authorizes publication", () => { + assert.equal(qualificationState([good], sha), "success"); + for (const changes of [{ head_sha: "b".repeat(40) }, { head_branch: "master" }, { event: "pull_request" }, { conclusion: "failure" }, { conclusion: "cancelled" }, { conclusion: "skipped" }]) { + assert.equal(qualificationState([{ ...good, ...changes }], sha), "missing"); + } +}); +test("publication waits for its dispatching candidate workflow to finish", async () => { + let calls = 0; + await requireQualification({ sha, runs: () => [++calls === 1 ? { ...good, status: "in_progress", conclusion: null } : good], sleep: async () => {} }); + assert.equal(calls, 2); +}); +test("missing, failed and timed-out qualification cannot publish", async () => { + await assert.rejects(requireQualification({ sha, runs: () => [] }), /No successful/); + let time = 0; + await assert.rejects(requireQualification({ sha, runs: () => [{ ...good, status: "in_progress" }], now: () => time++, timeout: 1, sleep: async () => {} }), /deadline/); +}); diff --git a/scripts/ci-changes.mjs b/scripts/ci-changes.mjs index 1af4a631c18..85277ce00bf 100644 --- a/scripts/ci-changes.mjs +++ b/scripts/ci-changes.mjs @@ -112,18 +112,6 @@ export function isVersionOnlyRelease(files) { ); } -// On master, only the release pull request changes the release manifest, so a -// PR or legacy merge group carrying it gets full validation before merging -// instead of the change-based subset. Syncing master into develop carries the -// same change without releasing anything. An undeterminable diff fails open. -export function isReleaseMergeGroup({ event, baseRef, files }) { - return ( - ["merge_group", "pull_request"].includes(event) && - baseRef === "refs/heads/master" && - (files === null || cutsRelease(files)) - ); -} - export function classifyFiles(files, { releasePlease = false } = {}) { const affected = { docs: false, @@ -286,13 +274,8 @@ if ( : changedFiles(process.argv[2] ?? "", process.argv[3] ?? ""); const queue = process.env.QUEUE_VALIDATION === "true" || (process.env.QUEUE_VALIDATION !== "false" && process.env.GITHUB_EVENT_NAME !== "pull_request"); - const release = queue && isReleaseMergeGroup({ - event: process.env.GITHUB_EVENT_NAME, - baseRef: process.env.MERGE_GROUP_BASE_REF, - files, - }); const affected = - files === null || release + files === null ? { ...ALL_AFFECTED, heliodor_arm64: true } : { ...classifyFiles(files, { releasePlease: !queue && process.env.RELEASE_PLEASE_PR === "true" }), @@ -300,12 +283,12 @@ if ( }; writeOutputs({ queue, + full_validation: scheduledFull, + fast_queue: queue && !scheduledFull, ...affected, - release, ...rustScopeOutputs( process.env.GITHUB_EVENT_NAME === "pull_request" && - !queue && - !release && + !scheduledFull && affected.rust ? files : null, @@ -321,8 +304,8 @@ export function celoxRustTestScope(files, packages) { ); } -// Queue drafts, merge groups, releases and daily runs keep the Celox -// workspace. Lydite tests run independently in lydite-checks.yml. +// Full validation keeps the Celox workspace; PR and queue lint use change scopes. +// Lydite tests run independently in lydite-checks.yml. export function rustScopeOutputs(files) { let scope = { full: true }; let checks; diff --git a/scripts/ci-changes.test.mjs b/scripts/ci-changes.test.mjs index 16f53c40c24..ccff9ec85d4 100644 --- a/scripts/ci-changes.test.mjs +++ b/scripts/ci-changes.test.mjs @@ -11,7 +11,6 @@ import { affectsHeliodorArm64, classifyFiles, cutsRelease, - isReleaseMergeGroup, rustScopeOutputs, } from "./ci-changes.mjs"; @@ -159,8 +158,9 @@ test("full validation overrides even an empty valid diff", () => { { ...all, queue: true, + full_validation: true, + fast_queue: false, heliodor_arm64: true, - release: false, // The whole Rust workspace, with no package scope or filter. rust_full: true, rust_packages: false, @@ -216,7 +216,7 @@ function runClassifier( const [name, value] = line.split("="); return [name, value === "true"]; }) - .filter(([name]) => !name.startsWith("rust_") && name !== "queue"), + .filter(([name]) => !name.startsWith("rust_") && !["queue", "full_validation", "fast_queue"].includes(name)), ); } @@ -233,50 +233,20 @@ test("only the release manifest marks a release", () => { ); }); -test("only master merge groups that change the release manifest are releases", () => { - const manifest = [".release-please-manifest.json"]; - const master = { event: "merge_group", baseRef: "refs/heads/master" }; - assert.equal(isReleaseMergeGroup({ ...master, files: manifest }), true); - assert.equal(isReleaseMergeGroup({ ...master, files: null }), true); - assert.equal(isReleaseMergeGroup({ ...master, files: ["README.md"] }), false); - // Syncing a release into develop carries the manifest but tags nothing. - for (const files of [manifest, null]) { - assert.equal( - isReleaseMergeGroup({ - event: "merge_group", - baseRef: "refs/heads/develop", - files, - }), - false, - ); - } - for (const event of ["push", "schedule"]) { - assert.equal( - isReleaseMergeGroup({ - event, - baseRef: "refs/heads/master", - files: manifest, - }), - false, - ); - } -}); - -test("merge groups with an unknown diff are treated as releases", () => { +test("unknown queue diffs select all paths without running release qualification", () => { assert.deepEqual(runClassifier("", "", MASTER_GROUP), { ...all, heliodor_arm64: true, - release: true, }); // Other events still run every path, but without the release gate. assert.deepEqual( runClassifier("", "", { GITHUB_EVENT_NAME: "pull_request" }), - { ...all, heliodor_arm64: true, release: false }, + { ...all, heliodor_arm64: true }, ); }); // CI checks out a single commit, so build the history this test needs. -test("a merge group that changes the release manifest is a release", (t) => { +test("release manifest changes no longer trigger full queue validation", (t) => { const repository = mkdtempSync(join(tmpdir(), "celox-ci-changes-")); t.after(() => rmSync(repository, { recursive: true, force: true })); const git = (...args) => @@ -297,9 +267,9 @@ test("a merge group that changes the release manifest is a release", (t) => { const base = commitManifest("0.1.0"); const release = commitManifest("0.2.0"); const classify = (env) => - runClassifier(base, release, env, repository).release; + runClassifier(base, release, env, repository).rust; - assert.equal(classify(MASTER_GROUP), true); + assert.equal(classify(MASTER_GROUP), false); assert.equal(classify({ GITHUB_EVENT_NAME: "pull_request" }), false); assert.equal( classify({ @@ -319,7 +289,6 @@ test("other merge groups are not releases", () => { assert.deepEqual(runClassifier(head, head, MASTER_GROUP), { ...none, heliodor_arm64: false, - release: false, }); }); @@ -494,32 +463,14 @@ test("generic Rust changes do not schedule ARM64 Heliodor on pull requests", () ); }); -test("queue drafts on master run release gates even with an unknown diff", () => { - for (const files of [[".release-please-manifest.json"], null]) { - assert.equal( - isReleaseMergeGroup({ - event: "pull_request", - baseRef: "refs/heads/master", - files, - }), - true, - ); - assert.equal( - isReleaseMergeGroup({ - event: "pull_request", - baseRef: "refs/heads/develop", - files, - }), - false, - ); - } +test("queue drafts do not run release gates even with an unknown diff", () => { assert.deepEqual( runClassifier("", "", { GITHUB_EVENT_NAME: "pull_request", MERGE_GROUP_BASE_REF: "refs/heads/master", QUEUE_VALIDATION: "true", }), - { ...all, heliodor_arm64: true, release: true }, + { ...all, heliodor_arm64: true }, ); }); @@ -565,7 +516,7 @@ test("PR branches behind their base ignore unmerged base changes", (t) => { assert.deepEqual(changedFilesBetween(base, head, repository), ["CONTRIBUTING.md"]); assert.deepEqual( runClassifier(base, head, { GITHUB_EVENT_NAME: "pull_request" }, repository), - { ...none, docs: true, heliodor_arm64: false, release: false }, + { ...none, docs: true, heliodor_arm64: false }, ); }); diff --git a/scripts/ci-workflow.test.mjs b/scripts/ci-workflow.test.mjs index ce4381e8131..13c03a9e382 100644 --- a/scripts/ci-workflow.test.mjs +++ b/scripts/ci-workflow.test.mjs @@ -31,7 +31,7 @@ test("the required gate rejects failures and only accepts explicitly optional sk ); assert.match( gate, - /ARM64_REQUIRED: \$\{\{ needs\.changes\.outputs\.queue != 'false' && needs\.changes\.outputs\.rust != 'false' \}\}/, + /ARM64_REQUIRED: \$\{\{ needs\.changes\.outputs\.full_validation != 'false' && needs\.changes\.outputs\.rust != 'false' \}\}/, ); assert.match(gate, /ARM64_RESULT: \$\{\{ needs\.arm64-backend\.result \}\}/); const script = gate.match(/ run: \|\n([\s\S]*)/)[1]; @@ -47,6 +47,7 @@ test("the required gate rejects failures and only accepts explicitly optional sk ARM64_RESULT: "success", NAPI_REQUIRED: "true", NATIVE_RESULT: "success", + WASM_REQUIRED: "true", WASM_RESULT: "success", RELEASE_REQUIRED: "false", EXTERNAL_RESULT: "skipped", @@ -123,6 +124,7 @@ test("the required gate rejects failures and only accepts explicitly optional sk const rustOnly = { ...success, NAPI_REQUIRED: "false", + WASM_REQUIRED: "false", NATIVE_RESULT: "skipped", WASM_RESULT: "skipped", }; @@ -184,15 +186,7 @@ test("scheduled and manual validation run all paths and external suites", () => assert.match(external, /needs: changes\n/); assert.match( external, - /if: \$\{\{ !cancelled\(\) && \(github\.event_name == 'schedule' \|\| github\.event_name == 'workflow_dispatch' \|\| needs\.changes\.outputs\.release == 'true'\)/, - ); - assert.match( - job("changes"), - /release: \$\{\{ steps\.classify\.outputs\.release \}\}/, - ); - assert.match( - job("changes"), - /MERGE_GROUP_BASE_REF: .*github\.event\.merge_group\.base_ref.*github\.base_ref/, + /if: \$\{\{ !cancelled\(\) && needs\.changes\.outputs\.full_validation == 'true'/, ); assert.match(job("changes"), /RELEASE_PLEASE_PR: .*github\.event\.pull_request\.head\.repo\.full_name == github\.repository/); assert.match(job("changes"), /QUEUE_VALIDATION: .*startsWith\(github\.head_ref, 'mergify\/merge-queue\/'\)/); @@ -254,17 +248,17 @@ test("Rust changes validate dependency exclusions even when script jobs are omit ); }); -test("queue CI retains the whole workspace and ordinary PRs use scoped tests", () => { +test("full validation retains the whole workspace; the queue uses bounded integration tests", () => { const rust = job("rust-tests"); assert.match(job("changes"), /QUEUE_VALIDATION: .*startsWith\(github\.head_ref, 'mergify\/merge-queue\/'\)/); // Anything but an explicit scope, including a failed detection, runs all. assert.match( rust, - /name: Run workspace tests with CI features\n id: workspace-tests\n if: needs\.changes\.outputs\.rust_full != 'false'\n/, + /name: Run workspace tests with CI features\n id: workspace-tests\n if: needs\.changes\.outputs\.fast_queue != 'true' && \(needs\.changes\.outputs\.rust_full != 'false'\)\n/, ); assert.match( rust, - /name: Run the tests this pull request can affect\n id: scoped-tests\n if: needs\.changes\.outputs\.rust_full == 'false' && /, + /name: Run the tests this pull request can affect\n id: scoped-tests\n if: needs\.changes\.outputs\.fast_queue != 'true' && \(needs\.changes\.outputs\.rust_full == 'false' && /, ); assert.match( job("changes"), @@ -287,14 +281,14 @@ test("artifact consumers wait for their producer rather than the Rust test gate" assert.match(browser, /name: napi-wasm32-wasi/); }); -test("landed commits are not re-validated by a push run", () => { +test("master pushes do not compete with the queue for full-matrix runners", () => { const triggers = workflow.match(/^on:\n([\s\S]*?)\n\S/m)[1]; assert.doesNotMatch(triggers, /^\s+push:/m); assert.match(triggers, /^\s+merge_group:/m); assert.match(triggers, /^\s+schedule:/m); }); -test("platform jobs are deferred to queue validation", () => { +test("platform jobs are deferred to full validation", () => { const platform = [ "arm64-backend", "napi-windows", @@ -302,7 +296,7 @@ test("platform jobs are deferred to queue validation", () => { "js-windows", ]; for (const name of platform) { - assert.match(job(name), /\n if: \$\{\{ !cancelled\(\) && needs\.changes\.outputs\.queue != 'false' && \(/, name); + assert.match(job(name), /\n if: \$\{\{ !cancelled\(\) && needs\.changes\.outputs\.full_validation != 'false' && \(/, name); } // Linux jobs still give pull requests their feedback. for (const name of [ @@ -333,7 +327,7 @@ test("full runs on long-lived branches report every job's result", () => { assert.deepEqual([...needs].sort(), [...jobs].sort()); assert.match( report, - /if: \$\{\{ !cancelled\(\) && \(github\.event_name == 'schedule' \|\| github\.event_name == 'workflow_dispatch'\) && \(github\.ref_name == 'master' \|\| github\.ref_name == 'develop'\)/, + /if: \$\{\{ !cancelled\(\) && inputs\.validation_ref == '' && \(github\.event_name == 'push' \|\| github\.event_name == 'schedule' \|\| github\.event_name == 'workflow_dispatch'\) && \(github\.ref_name == 'master' \|\| github\.ref_name == 'develop'\)/, ); assert.match(report, /issues: write/); assert.match(report, /NEEDS: \$\{\{ toJSON\(needs\) \}\}/); @@ -345,7 +339,7 @@ test("queue validation rejects missing coverage, producer failures and detection assert.match(gate, /if: \$\{\{ !cancelled\(\) && needs\.changes\.outputs\.queue != 'false'/); const script = gate.match(/ run: \|\n([\s\S]*)/)[1]; const needs = Object.fromEntries(["lint", "rust", "napi-windows", "napi-linux-arm64", "js-ubuntu", "js-windows", "playground-browser", "docs"].map(name => [name, { result: "success" }])); - needs.changes = { result: "success", outputs: { queue: "true", rust: "true", napi: "true", napi_arm64: "true", javascript: "true", scripts: "true", docs: "true" } }; + needs.changes = { result: "success", outputs: { queue: "true", full_validation: "true", fast_queue: "false", rust: "true", napi: "true", napi_arm64: "true", javascript: "true", scripts: "true", docs: "true" } }; const passes = (value) => spawnSync("bash", ["-e", "-c", script], { env: { ...process.env, NEEDS: JSON.stringify(value) } }).status === 0; assert.equal(passes(needs), true); for (const name of Object.keys(needs)) { @@ -462,7 +456,7 @@ test("CI prepares one executor for full runs and scopes containing Celox", () => const rust = job("rust-tests"); const step = rust.split(" - name: Build the optimized vtest executor\n")[1] .split("\n #")[0]; - assert.match(step, /if: needs.changes.outputs.rust_full != 'false' \|\| contains\(format\(' \{0\} ', needs.changes.outputs.rust_packages\), ' celox '\)/); + assert.match(step, /if: needs.changes.outputs.fast_queue != 'true' && \(needs.changes.outputs.rust_full != 'false' \|\| contains\(format\(' \{0\} ', needs.changes.outputs.rust_packages\), ' celox '\)/); assert.match(step, /run: node scripts\/run-vtest.mjs --prepare-ci/); assert.ok(rust.indexOf("Build the optimized vtest executor") < rust.indexOf("Run workspace tests")); assert.match(rust, /cargo nextest run[^\n]*\n[^\n]*celox-test-suite\/runtime-cases/); @@ -561,7 +555,7 @@ test("full Clippy validation excludes the disabled bridge", () => { test("upstream SV TB runs on full CI and feeds failure reporting", () => { const upstream = job("common-cells"); - assert.match(upstream, /github.event_name == 'schedule' \|\| github.event_name == 'workflow_dispatch'/); + assert.match(upstream, /needs.changes.outputs.full_validation == 'true'/); assert.doesNotMatch(upstream, /continue-on-error/); assert.match(upstream, /conformance\/common-cells\/revision/); assert.match(upstream, /cargo build --locked -p celox-vpi --features systemverilog --bin celox/); diff --git a/scripts/configure-merge-checks.mjs b/scripts/configure-merge-checks.mjs new file mode 100644 index 00000000000..58ba2649106 --- /dev/null +++ b/scripts/configure-merge-checks.mjs @@ -0,0 +1,57 @@ +import { execFileSync } from "node:child_process"; +import { pathToFileURL } from "node:url"; + +const DEFERRED_CHECKS = new Set([ + "NAPI Build (Linux ARM64 GNU)", + "NAPI Build (Windows)", + "JS Test (Windows)", +]); + +// Preserve the ruleset's enforcement, bypass actors, branch selectors and all +// unrelated checks. Queue validation still rejects failures in its producers. +export function lightweightRuleset(ruleset) { + const result = structuredClone(ruleset); + const checks = result.rules.find(rule => rule.type === "required_status_checks"); + if (!checks) throw new Error("Missing required status checks rule"); + const previous = checks.parameters.required_status_checks; + const integration = previous.find(check => check.context === "Lint & Format"); + if (!integration) throw new Error("Missing GitHub Actions lint check"); + checks.parameters.required_status_checks = previous.filter(check => !DEFERRED_CHECKS.has(check.context)); + if (!previous.some(check => check.context === "Queue validation")) { + checks.parameters.required_status_checks.push({ + context: "Queue validation", + integration_id: integration.integration_id, + }); + } + return Object.fromEntries(["name", "target", "enforcement", "bypass_actors", "conditions", "rules"] + .filter(key => key in result).map(key => [key, result[key]])); +} + +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + const args = process.argv.slice(2); + if (args.some(arg => arg !== "--apply")) throw new Error("Usage: node scripts/configure-merge-checks.mjs [--apply]"); + const repository = process.env.GITHUB_REPOSITORY || "celox-sim/celox"; + const api = (path, options = []) => JSON.parse(execFileSync("gh", ["api", `repos/${repository}/${path}`, ...options], { encoding: "utf8" })); + const rulesets = api("rulesets"); + const master = rulesets.find(rule => rule.name === "master"); + if (!master) throw new Error("master ruleset not found"); + const current = api(`rulesets/${master.id}`); + const desired = lightweightRuleset(current); + console.log(JSON.stringify(desired, null, 2)); + if (args.includes("--apply")) { + // Do not remove existing required checks before the replacement is deployed. + const source = path => Buffer.from(api(`contents/${path}?ref=master`).content, "base64").toString(); + const ci = source(".github/workflows/ci.yml"); + if (!ci.includes("name: Run merge queue integration tests") || !ci.includes("name: Release qualification")) { + throw new Error("Merge the release-validation workflow change before applying the ruleset migration"); + } + for (const path of [".github/workflows/ci-napi.yml", ".github/workflows/publish-crates.yml"]) { + if (!source(path).includes("name: Verify release branch qualification")) { + throw new Error(`${path} does not yet require release qualification`); + } + } + execFileSync("gh", ["api", "--method", "PUT", `repos/${repository}/rulesets/${master.id}`, "--input", "-"], { + input: JSON.stringify(desired), stdio: ["pipe", "inherit", "inherit"], + }); + } +} diff --git a/scripts/configure-merge-checks.test.mjs b/scripts/configure-merge-checks.test.mjs new file mode 100644 index 00000000000..ddff2c873d0 --- /dev/null +++ b/scripts/configure-merge-checks.test.mjs @@ -0,0 +1,32 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { lightweightRuleset } from "./configure-merge-checks.mjs"; + +test("migration removes only deferred platforms, preserves enforcement and adds the queue gate", () => { + const input = { + id: 123, name: "master", target: "branch", enforcement: "active", + bypass_actors: [{ actor_id: 42, actor_type: "Integration", bypass_mode: "always" }], + conditions: { ref_name: { include: ["refs/heads/master"], exclude: [] } }, + rules: [{ type: "non_fast_forward" }, { type: "required_status_checks", parameters: { + strict_required_status_checks_policy: false, + required_status_checks: ["Lint & Format", "Rust Test & NAPI Build", "Conventional Commit title", "NAPI Build (Windows)", "JS Test (Windows)", "NAPI Build (Linux ARM64 GNU)", "Custom audit"] + .map(context => ({ context, integration_id: 15368 })), + } }], + }; + const before = structuredClone(input); + const actual = lightweightRuleset(input); + assert.deepEqual(input, before); + assert.equal(actual.enforcement, "active"); + assert.deepEqual(actual.bypass_actors, input.bypass_actors); + assert.deepEqual(actual.conditions, input.conditions); + assert.deepEqual(actual.rules[0], input.rules[0]); + assert.deepEqual(actual.rules[1].parameters.required_status_checks.map(check => check.context), + ["Lint & Format", "Rust Test & NAPI Build", "Conventional Commit title", "Custom audit", "Queue validation"]); + assert.deepEqual(lightweightRuleset(actual), actual); + assert.equal(actual.id, undefined); +}); + +test("unexpected rulesets are rejected instead of guessing required checks", () => { + assert.throws(() => lightweightRuleset({ rules: [] }), /Missing required/); + assert.throws(() => lightweightRuleset({ rules: [{ type: "required_status_checks", parameters: { required_status_checks: [] } }] }), /Missing GitHub Actions/); +}); diff --git a/scripts/promote-release-candidate.mjs b/scripts/promote-release-candidate.mjs new file mode 100644 index 00000000000..7d661203cd4 --- /dev/null +++ b/scripts/promote-release-candidate.mjs @@ -0,0 +1,54 @@ +import { execFileSync } from "node:child_process"; +import { pathToFileURL } from "node:url"; + +export async function promoteCandidate({ github, sha, tag }) { + if (!/^[0-9a-f]{40}$/.test(sha) || !/^v[0-9]+\.[0-9]+\.[0-9]+$/.test(tag)) throw new Error("Invalid candidate identity"); + if (await github.branchSha() !== sha) throw new Error("Candidate was superseded on release; do not publish it"); + const pull = await github.releasePull(sha); + if (!pull) throw new Error("Candidate is not a merged master release pull request"); + const tagged = await github.tagSha(tag); + if (tagged && tagged !== sha) throw new Error("Release tag points at a different candidate"); + const release = await github.release(tag); + if (release) { + if (release.draft || release.prerelease || tagged !== sha) throw new Error("Existing release is not the qualified stable candidate"); + } else { + await github.createRelease(tag, sha); + } + // Retry publication only for this immutable, qualified tag. + await github.dispatchPackages(tag); + await github.markTagged(pull.number); +} + +function cli(args, input) { + return execFileSync("gh", args, { encoding: "utf8", input, stdio: ["pipe", "pipe", "pipe"] }).trim(); +} +export function githubClient(repository) { + if (!/^[\w.-]+\/[\w.-]+$/.test(repository)) throw new Error("Invalid repository"); + const api = (path, optional = false) => { + try { return JSON.parse(cli(["api", `repos/${repository}/${path}`])); } + catch (error) { + if (optional && /\(HTTP 404\)/.test(String(error.stderr))) return null; + throw error; + } + }; + return { + branchSha: () => api("git/ref/heads/release").object.sha, + releasePull: sha => api(`commits/${sha}/pulls`).find(pr => pr.merged_at && pr.merge_commit_sha === sha && pr.base.ref === "master" && pr.head.ref === "release-please--branches--master--components--celox" && pr.head.repo?.full_name === repository), + tagSha: tag => { + let object = api(`git/ref/tags/${tag}`, true)?.object; + for (let depth = 0; object?.type === "tag" && depth < 10; depth++) object = api(`git/tags/${object.sha}`).object; + if (object && object.type !== "commit") throw new Error("Invalid release tag object"); + return object?.sha ?? null; + }, + release: tag => api(`releases/tags/${tag}`, true), + createRelease: (tag, sha) => cli(["release", "create", tag, "--repo", repository, "--target", sha, "--title", tag, "--generate-notes"]), + dispatchPackages: tag => { + cli(["api", "--method", "POST", `repos/${repository}/dispatches`, "--input", "-"], JSON.stringify({ event_type: "napi-release", client_payload: { tag } })); + cli(["workflow", "run", "publish-crates.yml", "--repo", repository, "--ref", tag]); + }, + markTagged: number => cli(["pr", "edit", String(number), "--repo", repository, "--remove-label", "autorelease: pending", "--add-label", "autorelease: tagged"]), + }; +} +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + await promoteCandidate({ github: githubClient(process.env.GITHUB_REPOSITORY), sha: process.env.CANDIDATE_SHA, tag: process.env.RELEASE_TAG }); +} diff --git a/scripts/release-pr-update.test.mjs b/scripts/release-pr-update.test.mjs index e55150bd494..6e6a7fc517c 100644 --- a/scripts/release-pr-update.test.mjs +++ b/scripts/release-pr-update.test.mjs @@ -95,7 +95,7 @@ test("a failed lookup stops the workflow instead of permitting a rewrite", () => assert.equal(result.output, ""); }); -test("freeze suppresses only PR writes, preserving release creation on every event", () => { +test("master updates release PRs but never creates tags or GitHub releases", () => { const action = workflow .split(" - name: Create release or update release pull request\n")[1] .split(" - name: Queue package publication for this release\n")[0]; @@ -105,6 +105,6 @@ test("freeze suppresses only PR writes, preserving release creation on every eve action, /skip-github-pull-request: \$\{\{ steps\.release-pr\.outputs\.frozen == 'true' \}\}/, ); - assert.doesNotMatch(action, /skip-github-release:|\n if:/); + assert.match(action, /skip-github-release: true/); assert.doesNotMatch(guard, /github\.event_name|\n if:/); }); diff --git a/scripts/release-publication.test.mjs b/scripts/release-publication.test.mjs index 104bce766f7..a0dbf363e5d 100644 --- a/scripts/release-publication.test.mjs +++ b/scripts/release-publication.test.mjs @@ -1,127 +1,72 @@ import assert from "node:assert/strict"; -import { spawnSync } from "node:child_process"; -import { - existsSync, - mkdtempSync, - readFileSync, - rmSync, - writeFileSync, -} from "node:fs"; -import { tmpdir } from "node:os"; -import { join } from "node:path"; +import { readFileSync } from "node:fs"; import test from "node:test"; - -const workflow = readFileSync( - new URL("../.github/workflows/release.yml", import.meta.url), - "utf8", -); -const publication = workflow - .split(" - name: Queue package publication for this release\n")[1] - .split("\n queue-release:")[0]; -const script = publication - .split(" run: |\n")[1] - .split("\n") - .map((line) => line.replace(/^ /, "")) - .join("\n"); - -function dispatch({ tag = "v0.8.2", publishedTag = tag } = {}) { - const directory = mkdtempSync(join(tmpdir(), "celox-release-publication-")); - const callsPath = join(directory, "calls.jsonl"); - writeFileSync( - join(directory, "gh"), - `#!/usr/bin/env node -const fs = require("node:fs"); -const args = process.argv.slice(2); -const input = args[0] === "api" ? fs.readFileSync(0, "utf8") : ""; -fs.appendFileSync(process.env.CALLS_PATH, JSON.stringify({ args, input }) + "\\n"); -if (args[0] === "release") console.log(process.env.PUBLISHED_TAG); -`, - { mode: 0o755 }, - ); - try { - const result = spawnSync("bash", ["-e", "-o", "pipefail", "-c", script], { - cwd: directory, - env: { - ...process.env, - PATH: `${directory}:${process.env.PATH}`, - RELEASE_TAG: tag, - PUBLISHED_TAG: publishedTag, - CALLS_PATH: callsPath, - GITHUB_REPOSITORY: "celox-sim/celox", - // A batched merge push ends at a commit after the release tag. - GITHUB_SHA: "259c946c7465644bb856f286295170453958ce78", - }, - encoding: "utf8", - }); - const calls = existsSync(callsPath) - ? readFileSync(callsPath, "utf8").trim().split("\n").map(JSON.parse) - : []; - return { ...result, calls }; - } finally { - rmSync(directory, { recursive: true, force: true }); - } +import { promoteCandidate } from "./promote-release-candidate.mjs"; +const sha = "a".repeat(40), tag = "v0.11.0"; +function fixture(overrides = {}) { + const calls = []; + return { calls, github: { + branchSha: async () => sha, + releasePull: async () => ({ number: 7 }), + tagSha: async () => null, + release: async () => null, + createRelease: async (...args) => calls.push(["create", ...args]), + dispatchPackages: async (...args) => calls.push(["dispatch", ...args]), + markTagged: async (...args) => calls.push(["tagged", ...args]), + ...overrides, + } }; } - -test("publication runs only for a newly created root release on any event", () => { - assert.match( - workflow, - /id: release\n\s+uses: googleapis\/release-please-action@v5/, - ); - assert.match( - publication, - /if: steps\.release\.outputs\.release_created == 'true'/, - ); - assert.match( - publication, - /RELEASE_TAG: \$\{\{ steps\.release\.outputs\.tag_name \}\}/, - ); - assert.doesNotMatch(publication, /github\.event_name/); +test("promotion creates the tag/release at the qualified SHA before dispatch", async () => { + const f = fixture(); await promoteCandidate({ ...f, sha, tag }); + assert.deepEqual(f.calls, [["create", tag, sha], ["dispatch", tag], ["tagged", 7]]); }); - -test("dispatches both publishers for the created tag after a batched merge", () => { - const result = dispatch(); - assert.equal(result.status, 0, result.stderr); - assert.equal(result.calls.length, 3); - assert.deepEqual(result.calls[0].args.slice(0, 3), [ - "release", - "view", - "v0.8.2", - ]); - assert.deepEqual(result.calls[1].args, [ - "api", - "--method", - "POST", - "repos/celox-sim/celox/dispatches", - "--input", - "-", - ]); - assert.deepEqual(JSON.parse(result.calls[1].input), { - event_type: "napi-release", - client_payload: { tag: "v0.8.2" }, - }); - assert.deepEqual(result.calls[2].args, [ - "workflow", - "run", - "publish-crates.yml", - "--repo", - "celox-sim/celox", - "--ref", - "v0.8.2", - ]); +test("superseded, unrelated and conflicting candidates cannot publish", async () => { + for (const overrides of [ + { branchSha: () => "b".repeat(40) }, { releasePull: () => null }, + { tagSha: () => "b".repeat(40) }, + { tagSha: () => sha, release: () => ({ draft: true }) }, + { tagSha: () => sha, release: () => ({ prerelease: true }) }, + { branchSha: () => { throw new Error("API failure"); } }, + ]) { + const f = fixture(overrides); + await assert.rejects(promoteCandidate({ ...f, sha, tag })); assert.deepEqual(f.calls, []); + } }); - -test("does not dispatch publishers when the stable GitHub release is missing", () => { - const result = dispatch({ publishedTag: "" }); - assert.notEqual(result.status, 0); - assert.equal(result.calls.length, 1); - assert.match(result.stderr, /Published GitHub Release v0.8.2 was not found/); +test("an exact existing release can resume package dispatch", async () => { + const f = fixture({ tagSha: () => sha, release: () => ({ draft: false, prerelease: false }) }); + await promoteCandidate({ ...f, sha, tag }); + assert.deepEqual(f.calls, [["dispatch", tag], ["tagged", 7]]); +}); +test("release creation failure cannot dispatch packages", async () => { + const f = fixture({ createRelease: () => { throw new Error("creation failed"); } }); + await assert.rejects(promoteCandidate({ ...f, sha, tag })); assert.deepEqual(f.calls, []); +}); +test("only release branch qualification can create the public release", () => { + const master = readFileSync(new URL("../.github/workflows/release.yml", import.meta.url), "utf8"); + const stage = readFileSync(new URL("../.github/workflows/stage-release-candidate.yml", import.meta.url), "utf8"); + const rc = readFileSync(new URL("../.github/workflows/release-candidate.yml", import.meta.url), "utf8"); + assert.match(master, /skip-github-release: true/); + assert.doesNotMatch(master, /release_created|release create|napi-release/); + assert.match(stage, /git push origin "\$CANDIDATE_SHA:refs\/heads\/release"/); + assert.match(stage, /ref: \$\{\{ github.event.pull_request.merge_commit_sha \}\}/); + assert.match(rc, /branches: \[release\]/); + assert.match(rc, /if: github.ref == 'refs\/heads\/release'/); + assert.match(rc, /validation_ref: \$\{\{ needs.candidate.outputs.sha \}\}/); + assert.match(rc, /needs: \[candidate, qualify\]/); + assert.doesNotMatch(rc, /continue-on-error/); }); -test("rejects missing and non-stable release tags", () => { - for (const tag of ["", "v0.8.2-rc.1", "master"]) { - const result = dispatch({ tag }); - assert.notEqual(result.status, 0); - assert.deepEqual(result.calls, []); - assert.match(result.stderr, /Expected a v-prefixed stable release tag/); - } + +test("one-shot candidate staging cannot be coalesced with release management or other closures", () => { + const management = readFileSync(new URL("../.github/workflows/release.yml", import.meta.url), "utf8"); + const stage = readFileSync(new URL("../.github/workflows/stage-release-candidate.yml", import.meta.url), "utf8"); + assert.doesNotMatch(management, /^ pull_request:|^ stage-candidate:/m); + assert.match(management, /group: release-management/); + assert.match(stage, /pull_request:\n types: \[closed\]\n branches: \[master\]/); + // Neither workflow-level nor job-level concurrency may discard a pending RC. + assert.doesNotMatch(stage, /^\s*concurrency:/m); + assert.match(stage, /github.event.pull_request.merged == true/); + assert.match(stage, /github.event.pull_request.head.repo.full_name == github.repository/); + assert.match(stage, /github.event.pull_request.head.ref == 'release-please--branches--master--components--celox'/); + assert.doesNotMatch(stage, /git push[^\n]*(?:--force|\+)/); }); diff --git a/scripts/release-validation.test.mjs b/scripts/release-validation.test.mjs new file mode 100644 index 00000000000..724a04064e0 --- /dev/null +++ b/scripts/release-validation.test.mjs @@ -0,0 +1,100 @@ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { spawnSync } from "node:child_process"; +import test from "node:test"; + +const workflow = readFileSync(new URL("../.github/workflows/ci.yml", import.meta.url), "utf8"); +function job(text, name) { + const parts = text.split(/^ ([\w-]+):\n/m); + const index = parts.indexOf(name); + assert.ok(index >= 0, name); + return parts[index + 1]; +} +function runGate(name, needs) { + const script = job(workflow, name).split(" run: |\n")[1]; + return spawnSync("bash", ["-e", "-c", script], { env: { ...process.env, NEEDS: JSON.stringify(needs) } }).status; +} + +test("qualification fails on every missing, skipped, failed or cancelled required job", () => { + const names = job(workflow, "full-validation").match(/needs:\s*\[([^\]]+)\]/)[1] + .split(",").map(name => name.trim()).filter(Boolean); + for (const required of ["rust-tests", "rust-default-tests", "sv-tests", "external-suites", "common-cells", "arm64-backend", "js-windows", "napi-wasm", "playground-browser"]) { + assert.ok(names.includes(required), required); + } + const needs = Object.fromEntries(names.map(name => [name, { result: "success" }])); + assert.equal(runGate("full-validation", needs), 0); + for (const name of names) { + for (const result of ["skipped", "failure", "cancelled", ""]) { + assert.notEqual(runGate("full-validation", { ...needs, [name]: { result } }), 0, `${name}: ${result}`); + } + } +}); + +test("queue accepts deferred coverage but rejects any failed queue producer", () => { + const needs = Object.fromEntries(["lint", "rust", "js-ubuntu", "docs"].map(name => [name, { result: "success" }])); + for (const name of ["napi-windows", "napi-linux-arm64", "js-windows", "playground-browser"]) needs[name] = { result: "skipped" }; + needs.changes = { result: "success", outputs: { queue: "true", fast_queue: "true", full_validation: "false", rust: "true", napi: "true", napi_arm64: "true", javascript: "true", docs: "true" } }; + assert.equal(runGate("queue-validation", needs), 0); + for (const name of ["lint", "rust", "js-ubuntu", "docs", "changes"]) { + for (const result of ["failure", "cancelled", "skipped"]) { + assert.notEqual(runGate("queue-validation", { ...needs, [name]: { ...needs[name], result } }), 0); + } + } +}); + +test("every full-validation checkout uses the requested immutable source", () => { + const checkouts = [...workflow.matchAll(/uses: actions\/checkout@v7\n([\s\S]*?)(?=\n -|\n [\w-]+:)/g)]; + assert.ok(checkouts.length > 10); + for (const [, checkout] of checkouts) assert.match(checkout, /ref: \$\{\{ inputs.validation_ref \|\| github.sha \}\}/); + assert.match(workflow, /FULL_VALIDATION: .*inputs.validation_ref != ''/); +}); + +test("both stable publishers verify release-branch qualification of their actual build SHA", () => { + for (const [file, source] of [["publish-crates.yml", "github.sha"], ["ci-napi.yml", "needs.validate-release.outputs.build_sha"]]) { + const text = readFileSync(new URL(`../.github/workflows/${file}`, import.meta.url), "utf8"); + const qualification = job(text, "qualify"); + assert.match(qualification, /run: node scripts\/check-release-qualification.mjs/); + assert.ok(qualification.includes(`CANDIDATE_SHA: \${{ ${source} }}`)); + assert.match(job(text, "publish"), /needs: \[[^\]]*qualify\]/); + if (file === "ci-napi.yml") { + assert.match(job(text, "publish"), /needs.qualify.result == 'success'/); + assert.match(job(text, "publish"), /startsWith\(inputs.channel, 'nightly-'\) && needs.qualify.result == 'skipped'/); + // Debug artifacts from qualification must never enter npm packages. + assert.match(job(text, "publish"), /pattern: bindings-\*/); + } + } +}); + +test("queue integration tests run before reports are collected and keep normal failure handling", () => { + const rust = job(workflow, "rust-tests"); + const smoke = rust.split(" - name: Run merge queue integration tests")[1].split(" - name:")[0]; + assert.match(smoke, /if: needs.changes.outputs.fast_queue == 'true'/); + assert.match(smoke, /cargo nextest run --locked -p celox --features systemverilog --profile ci/); + assert.doesNotMatch(smoke, /no-tests=pass|continue-on-error/); + assert.ok(rust.indexOf("Run merge queue integration tests") < rust.indexOf("Collect Rust test reports")); + assert.match(rust, /test_step_outcome: .*steps.queue-tests.outcome/); +}); + +test("classification keeps PRs, fast queue and full qualification distinct", () => { + const classifier = new URL("./ci-changes.mjs", import.meta.url); + for (const [queue, full, expectedFast] of [["false", "false", "false"], ["true", "false", "true"], ["true", "true", "false"]]) { + const result = spawnSync(process.execPath, [classifier.pathname, "", ""], { + env: { ...process.env, GITHUB_EVENT_NAME: "pull_request", QUEUE_VALIDATION: queue, FULL_VALIDATION: full, GITHUB_OUTPUT: "" }, encoding: "utf8", + }); + assert.equal(result.status, 0, result.stderr); + const outputs = Object.fromEntries(result.stdout.trim().split("\n").map(line => line.split("="))); + assert.equal(outputs.full_validation, full); + assert.equal(outputs.fast_queue, expectedFast); + // Unknown diffs still request all product paths; queue mode only narrows execution. + assert.equal(outputs.rust, "true"); + assert.equal(outputs.napi, "true"); + } +}); + +test("qualification names every CI producer, including future additions", () => { + const producers = [...workflow.split(/^jobs:\n/m)[1].matchAll(/^ ([\w-]+):\n/gm)] + .map(match => match[1]).filter(name => !["report-full-validation", "full-validation"].includes(name)); + const required = job(workflow, "full-validation").match(/needs:\s*\[([^\]]+)\]/)[1] + .split(",").map(name => name.trim()).filter(Boolean); + assert.deepEqual(required.sort(), producers.sort()); +});