From 3e16a3f590d4b5858cff571cc2214675cc1e995f Mon Sep 17 00:00:00 2001 From: mintaka Date: Tue, 10 Nov 2026 23:34:54 -0500 Subject: [PATCH 1/9] feat(ci): publish solid-virtual tarball to GitHub Releases (RIG-9272) The tag publisher now packs @rigelbuild/solid-virtual once, uploads the tarball and a SHA256SUMS file as a workflow artifact, and attaches both to a GitHub Release for the same vX.Y.Z-rigel.N tag. The release job runs only after the npm publish succeeds, so an asset never exists for an unpublished version. The packed tarball is the one npm received, with workspace:* already rewritten to the real virtual-core version. Co-authored-by: Matt Wilkinson --- .github/scripts/workflow-contract.test.mjs | 15 +++++++++ .github/workflows/publish-rigelbuild.yml | 39 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/.github/scripts/workflow-contract.test.mjs b/.github/scripts/workflow-contract.test.mjs index 8d770ec8d..ec6a9d7f4 100644 --- a/.github/scripts/workflow-contract.test.mjs +++ b/.github/scripts/workflow-contract.test.mjs @@ -37,6 +37,21 @@ passes( /needs\.resolve\.outputs\.publish == 'true'/.test(publisher) && /name: Resolve and validate release tag/.test(publisher), ) +passes( + 'GitHub Release job publishes the packed tarball after npm publish', + /github-release:\s*\n\s*name: GitHub Release\s*\n[\s\S]*?needs: \[resolve, publish\]/.test( + publisher, + ) && + /name: GitHub Release[\s\S]*?permissions:\s*\n[\s\S]*?contents: write/.test( + publisher, + ) && + /uses: actions\/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7\.0\.2/.test( + publisher, + ) && + /uses: actions\/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8\.0\.2/.test( + publisher, + ), +) const tempDir = mkdtempSync(join(tmpdir(), 'virtual-dispatch-')) try { const outputPath = join(tempDir, 'github-output') diff --git a/.github/workflows/publish-rigelbuild.yml b/.github/workflows/publish-rigelbuild.yml index ca245f182..01e8db15e 100644 --- a/.github/workflows/publish-rigelbuild.yml +++ b/.github/workflows/publish-rigelbuild.yml @@ -105,3 +105,42 @@ jobs: # provenance only from this env key, never from any .npmrc; the # clean name exports fine in Actions. pnpm_config_provenance: 'false' + - name: Pack the release tarball + run: | + mkdir -p "$RUNNER_TEMP/release" + pnpm --filter @rigelbuild/solid-virtual pack --pack-destination "$RUNNER_TEMP/release" + (cd "$RUNNER_TEMP/release" && sha256sum *.tgz > SHA256SUMS) + - name: Upload the release tarball + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: solid-virtual-tarball + path: ${{ runner.temp }}/release + if-no-files-found: error + github-release: + name: GitHub Release + # Runs only after npm publish succeeds, so an asset never exists for an unpublished version. + needs: [resolve, publish] + if: github.repository_owner == 'RigelBuild' && needs.resolve.outputs.publish == 'true' + runs-on: ubuntu-latest + permissions: + # Creating the release and uploading its asset is the only write this job makes. + contents: write + steps: + - name: Download the release tarball + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: solid-virtual-tarball + path: release + - name: Create or refresh the GitHub Release + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ github.ref_name }} + REPOSITORY: ${{ github.repository }} + run: | + set -euo pipefail + if gh release view "$TAG" --repo "$REPOSITORY" >/dev/null 2>&1; then + echo "release $TAG already exists; refreshing assets" + else + gh release create "$TAG" --repo "$REPOSITORY" --verify-tag --title "$TAG" --notes "Release $TAG of @rigelbuild/solid-virtual." + fi + gh release upload "$TAG" release/*.tgz release/SHA256SUMS --clobber --repo "$REPOSITORY" From 1e553b29636d4ddd4405afdf4d7bda4fbc151709 Mon Sep 17 00:00:00 2001 From: mintaka Date: Wed, 11 Nov 2026 00:14:50 -0500 Subject: [PATCH 2/9] ci(hooks): gate publish workflow YAML on pre-push Add a minimal hk pre-push step that parses the tag publisher workflow with yq. It mirrors the devenv release-workflow check so a malformed publisher is caught before push. Co-authored-by: Matt Wilkinson --- hk.pkl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 hk.pkl diff --git a/hk.pkl b/hk.pkl new file mode 100644 index 000000000..e3e86893c --- /dev/null +++ b/hk.pkl @@ -0,0 +1,15 @@ +// Git hooks managed by hk (https://hk.jdx.dev). +amends "package://github.com/jdx/hk/releases/download/v2.11.1/hk@2.11.1#/Config.pkl" + +default_branch = "rigel-release" + +hooks { + ["pre-push"] { + steps { + ["publish-workflow-yaml"] = new Step { + glob = List(".github/workflows/publish-rigelbuild.yml") + check = "yq -e '.jobs | keys' {{files}} >/dev/null" + } + } + } +} From 74e0c9fb38c1a9e02df12f8d4c06931e8677846e Mon Sep 17 00:00:00 2001 From: mintaka Date: Wed, 11 Nov 2026 00:50:31 -0500 Subject: [PATCH 3/9] fix(ci): pack the release tarball once and publish that file The tarball is packed before npm publish, uploaded as an artifact, and that exact file is published. The GitHub Release asset is then the npm tarball byte for byte, and a failure after npm accepts the version leaves the asset to attach. The contract test now asserts pack, upload, then publish order, a single contents: write held by the release job, and --verify-tag. The hook runs the node contract tests over the workflow and script globs. The header comment names the release job. Co-authored-by: Matt Wilkinson --- .github/scripts/workflow-contract.test.mjs | 18 ++++++++++---- .github/workflows/publish-rigelbuild.yml | 28 ++++++++++++---------- hk.pkl | 6 ++--- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/.github/scripts/workflow-contract.test.mjs b/.github/scripts/workflow-contract.test.mjs index ec6a9d7f4..4bb4f9592 100644 --- a/.github/scripts/workflow-contract.test.mjs +++ b/.github/scripts/workflow-contract.test.mjs @@ -38,19 +38,27 @@ passes( /name: Resolve and validate release tag/.test(publisher), ) passes( - 'GitHub Release job publishes the packed tarball after npm publish', + 'release tarball is packed and uploaded before npm publish, and the release attaches it', /github-release:\s*\n\s*name: GitHub Release\s*\n[\s\S]*?needs: \[resolve, publish\]/.test( publisher, ) && - /name: GitHub Release[\s\S]*?permissions:\s*\n[\s\S]*?contents: write/.test( - publisher, - ) && + publisher.indexOf('name: Pack the release tarball') < + publisher.indexOf('name: Upload the release tarball') && + publisher.indexOf('name: Upload the release tarball') < + publisher.indexOf('name: Publish @rigelbuild/solid-virtual') && + /pnpm publish "\$tarball" --tag "\$TAG"/.test(publisher) && /uses: actions\/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7\.0\.2/.test( publisher, ) && /uses: actions\/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8\.0\.2/.test( publisher, - ), + ) && + /gh release create "\$TAG" --repo "\$REPOSITORY" --verify-tag/.test(publisher), +) +passes( + 'exactly one contents: write, held by the github-release job', + publisher.match(/contents: write/g).length === 1 && + /github-release:[\s\S]*?contents: write/.test(publisher), ) const tempDir = mkdtempSync(join(tmpdir(), 'virtual-dispatch-')) try { diff --git a/.github/workflows/publish-rigelbuild.yml b/.github/workflows/publish-rigelbuild.yml index 01e8db15e..9fb88c529 100644 --- a/.github/workflows/publish-rigelbuild.yml +++ b/.github/workflows/publish-rigelbuild.yml @@ -7,6 +7,7 @@ name: Publish (RigelBuild) # dist-tag from the version (prerelease -> next, GA -> latest). It reuses the # monorepo install/build/test tooling; only the changesets *publish step* is # bypassed, since it cannot scope a single renamed package's publish here. +# A github-release job then attaches the same packed tarball and SHA256SUMS to the tag's GitHub Release. permissions: contents: read @@ -75,6 +76,19 @@ jobs: else echo "tag=latest" >> "$GITHUB_OUTPUT" fi + - name: Pack the release tarball + # Pack once, then publish that exact file: the release asset is the npm tarball byte for byte. + run: | + mkdir -p "$RUNNER_TEMP/release" + pnpm --filter @rigelbuild/solid-virtual pack --pack-destination "$RUNNER_TEMP/release" + (cd "$RUNNER_TEMP/release" && sha256sum *.tgz > SHA256SUMS) + - name: Upload the release tarball + # Uploaded before publish so a failure after npm accepts the version still leaves the asset to attach. + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: solid-virtual-tarball + path: ${{ runner.temp }}/release + if-no-files-found: error - name: Publish @rigelbuild/solid-virtual # Auth is the NPM_TOKEN secret (custodied via the orion Pulumi github # stack per DL-015), not OIDC trusted publishing — hence the ignored @@ -95,7 +109,8 @@ jobs: # Create the user npmrc mode-600 at creation (umask in a subshell), so # the token file is never briefly world-readable. ( umask 077 && printf '//registry.npmjs.org/:_authToken=%s\n' "$NPM_TOKEN" > "$HOME/.npmrc" ) - pnpm publish --filter @rigelbuild/solid-virtual --tag "$TAG" --no-git-checks + tarball=$(ls "$RUNNER_TEMP"/release/*.tgz) + pnpm publish "$tarball" --tag "$TAG" --no-git-checks env: TAG: ${{ steps.disttag.outputs.tag }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} @@ -105,17 +120,6 @@ jobs: # provenance only from this env key, never from any .npmrc; the # clean name exports fine in Actions. pnpm_config_provenance: 'false' - - name: Pack the release tarball - run: | - mkdir -p "$RUNNER_TEMP/release" - pnpm --filter @rigelbuild/solid-virtual pack --pack-destination "$RUNNER_TEMP/release" - (cd "$RUNNER_TEMP/release" && sha256sum *.tgz > SHA256SUMS) - - name: Upload the release tarball - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - with: - name: solid-virtual-tarball - path: ${{ runner.temp }}/release - if-no-files-found: error github-release: name: GitHub Release # Runs only after npm publish succeeds, so an asset never exists for an unpublished version. diff --git a/hk.pkl b/hk.pkl index e3e86893c..e6fbff00b 100644 --- a/hk.pkl +++ b/hk.pkl @@ -6,9 +6,9 @@ default_branch = "rigel-release" hooks { ["pre-push"] { steps { - ["publish-workflow-yaml"] = new Step { - glob = List(".github/workflows/publish-rigelbuild.yml") - check = "yq -e '.jobs | keys' {{files}} >/dev/null" + ["fork-release-contracts"] = new Step { + glob = List(".github/workflows/**", ".github/scripts/**") + check = "node .github/scripts/workflow-contract.test.mjs && node .github/scripts/release-tag.test.mjs" } } } From 4ff2dbbd90ee210f2863db8a2bd45fb06a56ebe7 Mon Sep 17 00:00:00 2001 From: mintaka Date: Wed, 11 Nov 2026 00:55:46 -0500 Subject: [PATCH 4/9] fix(ci): assert release ordering indexes and reword upload comment The contract test stores the pack, upload, and publish indexes and asserts each is found before comparing order, so a deleted or renamed step fails the test. The contents: write count is null-safe. The upload comment now states only what the ordering guarantees: the asset is the file npm receives, and no step runs after publish. Co-authored-by: Matt Wilkinson --- .github/scripts/workflow-contract.test.mjs | 14 +++++++++----- .github/workflows/publish-rigelbuild.yml | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/scripts/workflow-contract.test.mjs b/.github/scripts/workflow-contract.test.mjs index 4bb4f9592..a036bc218 100644 --- a/.github/scripts/workflow-contract.test.mjs +++ b/.github/scripts/workflow-contract.test.mjs @@ -37,15 +37,19 @@ passes( /needs\.resolve\.outputs\.publish == 'true'/.test(publisher) && /name: Resolve and validate release tag/.test(publisher), ) +const packAt = publisher.indexOf('name: Pack the release tarball') +const uploadAt = publisher.indexOf('name: Upload the release tarball') +const publishAt = publisher.indexOf('name: Publish @rigelbuild/solid-virtual') passes( 'release tarball is packed and uploaded before npm publish, and the release attaches it', /github-release:\s*\n\s*name: GitHub Release\s*\n[\s\S]*?needs: \[resolve, publish\]/.test( publisher, ) && - publisher.indexOf('name: Pack the release tarball') < - publisher.indexOf('name: Upload the release tarball') && - publisher.indexOf('name: Upload the release tarball') < - publisher.indexOf('name: Publish @rigelbuild/solid-virtual') && + packAt >= 0 && + uploadAt >= 0 && + publishAt >= 0 && + packAt < uploadAt && + uploadAt < publishAt && /pnpm publish "\$tarball" --tag "\$TAG"/.test(publisher) && /uses: actions\/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7\.0\.2/.test( publisher, @@ -57,7 +61,7 @@ passes( ) passes( 'exactly one contents: write, held by the github-release job', - publisher.match(/contents: write/g).length === 1 && + (publisher.match(/contents: write/g) ?? []).length === 1 && /github-release:[\s\S]*?contents: write/.test(publisher), ) const tempDir = mkdtempSync(join(tmpdir(), 'virtual-dispatch-')) diff --git a/.github/workflows/publish-rigelbuild.yml b/.github/workflows/publish-rigelbuild.yml index 9fb88c529..1b6ad923c 100644 --- a/.github/workflows/publish-rigelbuild.yml +++ b/.github/workflows/publish-rigelbuild.yml @@ -83,7 +83,7 @@ jobs: pnpm --filter @rigelbuild/solid-virtual pack --pack-destination "$RUNNER_TEMP/release" (cd "$RUNNER_TEMP/release" && sha256sum *.tgz > SHA256SUMS) - name: Upload the release tarball - # Uploaded before publish so a failure after npm accepts the version still leaves the asset to attach. + # Uploaded before publish, so the asset is the same file npm receives. No step runs after publish here. uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: solid-virtual-tarball From 3f52f0ed165cfd87a5be0a4213514311914c2efb Mon Sep 17 00:00:00 2001 From: mintaka Date: Wed, 11 Nov 2026 01:14:17 -0500 Subject: [PATCH 5/9] style(ci): format contract test with prettier Wrap the verify-tag assertion as prettier 3.7 formats it, so the autofix job stops rewriting .github/. Co-authored-by: Matt Wilkinson --- .github/scripts/workflow-contract.test.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/scripts/workflow-contract.test.mjs b/.github/scripts/workflow-contract.test.mjs index a036bc218..dcd26cd45 100644 --- a/.github/scripts/workflow-contract.test.mjs +++ b/.github/scripts/workflow-contract.test.mjs @@ -57,7 +57,9 @@ passes( /uses: actions\/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8\.0\.2/.test( publisher, ) && - /gh release create "\$TAG" --repo "\$REPOSITORY" --verify-tag/.test(publisher), + /gh release create "\$TAG" --repo "\$REPOSITORY" --verify-tag/.test( + publisher, + ), ) passes( 'exactly one contents: write, held by the github-release job', From 29e6943a3b4c6d4a89a8a62d2a5ede102b78af72 Mon Sep 17 00:00:00 2001 From: mintaka Date: Wed, 11 Nov 2026 02:26:12 -0500 Subject: [PATCH 6/9] chore(ci): revert the GitHub Release upload from the tag publisher Matt ruled on RIG-9386: @rigelbuild/solid-virtual stays an npm dependency, with no flake pin and no release asset. This restores the publisher and its contract test to rigel-release, so this PR carries only hk.pkl. Refs RIG-9386 Co-authored-by: Matt Wilkinson --- .github/scripts/workflow-contract.test.mjs | 29 -------------- .github/workflows/publish-rigelbuild.yml | 45 +--------------------- 2 files changed, 1 insertion(+), 73 deletions(-) diff --git a/.github/scripts/workflow-contract.test.mjs b/.github/scripts/workflow-contract.test.mjs index dcd26cd45..8d770ec8d 100644 --- a/.github/scripts/workflow-contract.test.mjs +++ b/.github/scripts/workflow-contract.test.mjs @@ -37,35 +37,6 @@ passes( /needs\.resolve\.outputs\.publish == 'true'/.test(publisher) && /name: Resolve and validate release tag/.test(publisher), ) -const packAt = publisher.indexOf('name: Pack the release tarball') -const uploadAt = publisher.indexOf('name: Upload the release tarball') -const publishAt = publisher.indexOf('name: Publish @rigelbuild/solid-virtual') -passes( - 'release tarball is packed and uploaded before npm publish, and the release attaches it', - /github-release:\s*\n\s*name: GitHub Release\s*\n[\s\S]*?needs: \[resolve, publish\]/.test( - publisher, - ) && - packAt >= 0 && - uploadAt >= 0 && - publishAt >= 0 && - packAt < uploadAt && - uploadAt < publishAt && - /pnpm publish "\$tarball" --tag "\$TAG"/.test(publisher) && - /uses: actions\/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7\.0\.2/.test( - publisher, - ) && - /uses: actions\/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8\.0\.2/.test( - publisher, - ) && - /gh release create "\$TAG" --repo "\$REPOSITORY" --verify-tag/.test( - publisher, - ), -) -passes( - 'exactly one contents: write, held by the github-release job', - (publisher.match(/contents: write/g) ?? []).length === 1 && - /github-release:[\s\S]*?contents: write/.test(publisher), -) const tempDir = mkdtempSync(join(tmpdir(), 'virtual-dispatch-')) try { const outputPath = join(tempDir, 'github-output') diff --git a/.github/workflows/publish-rigelbuild.yml b/.github/workflows/publish-rigelbuild.yml index 1b6ad923c..ca245f182 100644 --- a/.github/workflows/publish-rigelbuild.yml +++ b/.github/workflows/publish-rigelbuild.yml @@ -7,7 +7,6 @@ name: Publish (RigelBuild) # dist-tag from the version (prerelease -> next, GA -> latest). It reuses the # monorepo install/build/test tooling; only the changesets *publish step* is # bypassed, since it cannot scope a single renamed package's publish here. -# A github-release job then attaches the same packed tarball and SHA256SUMS to the tag's GitHub Release. permissions: contents: read @@ -76,19 +75,6 @@ jobs: else echo "tag=latest" >> "$GITHUB_OUTPUT" fi - - name: Pack the release tarball - # Pack once, then publish that exact file: the release asset is the npm tarball byte for byte. - run: | - mkdir -p "$RUNNER_TEMP/release" - pnpm --filter @rigelbuild/solid-virtual pack --pack-destination "$RUNNER_TEMP/release" - (cd "$RUNNER_TEMP/release" && sha256sum *.tgz > SHA256SUMS) - - name: Upload the release tarball - # Uploaded before publish, so the asset is the same file npm receives. No step runs after publish here. - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - with: - name: solid-virtual-tarball - path: ${{ runner.temp }}/release - if-no-files-found: error - name: Publish @rigelbuild/solid-virtual # Auth is the NPM_TOKEN secret (custodied via the orion Pulumi github # stack per DL-015), not OIDC trusted publishing — hence the ignored @@ -109,8 +95,7 @@ jobs: # Create the user npmrc mode-600 at creation (umask in a subshell), so # the token file is never briefly world-readable. ( umask 077 && printf '//registry.npmjs.org/:_authToken=%s\n' "$NPM_TOKEN" > "$HOME/.npmrc" ) - tarball=$(ls "$RUNNER_TEMP"/release/*.tgz) - pnpm publish "$tarball" --tag "$TAG" --no-git-checks + pnpm publish --filter @rigelbuild/solid-virtual --tag "$TAG" --no-git-checks env: TAG: ${{ steps.disttag.outputs.tag }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} @@ -120,31 +105,3 @@ jobs: # provenance only from this env key, never from any .npmrc; the # clean name exports fine in Actions. pnpm_config_provenance: 'false' - github-release: - name: GitHub Release - # Runs only after npm publish succeeds, so an asset never exists for an unpublished version. - needs: [resolve, publish] - if: github.repository_owner == 'RigelBuild' && needs.resolve.outputs.publish == 'true' - runs-on: ubuntu-latest - permissions: - # Creating the release and uploading its asset is the only write this job makes. - contents: write - steps: - - name: Download the release tarball - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 - with: - name: solid-virtual-tarball - path: release - - name: Create or refresh the GitHub Release - env: - GH_TOKEN: ${{ github.token }} - TAG: ${{ github.ref_name }} - REPOSITORY: ${{ github.repository }} - run: | - set -euo pipefail - if gh release view "$TAG" --repo "$REPOSITORY" >/dev/null 2>&1; then - echo "release $TAG already exists; refreshing assets" - else - gh release create "$TAG" --repo "$REPOSITORY" --verify-tag --title "$TAG" --notes "Release $TAG of @rigelbuild/solid-virtual." - fi - gh release upload "$TAG" release/*.tgz release/SHA256SUMS --clobber --repo "$REPOSITORY" From 5f530ba29e9366d81f4eb19de98fb6f9f492e68f Mon Sep 17 00:00:00 2001 From: mintaka Date: Wed, 11 Nov 2026 02:35:51 -0500 Subject: [PATCH 7/9] ci(pr): pin Test job runner to ubuntu-24.04 (RIG-9206) Co-authored-by: Matt Wilkinson From 7b41922811b9fe3535e4927c4a6c9b7a1f8183b4 Mon Sep 17 00:00:00 2001 From: mintaka Date: Wed, 11 Nov 2026 02:35:58 -0500 Subject: [PATCH 8/9] ci(pr): pin Test job runner to ubuntu-24.04 The ubuntu-latest image moved to 26.04, which Playwright does not support for chromium. The Test job fails at browser install on every PR. Pinning the runner keeps the Test job on a supported image until Playwright catches up. Stacked on virtual#10 (RIG-9272 chain) so the hk pre-push gate sees hk.pkl. Refs RIG-9206 Co-authored-by: Matt Wilkinson --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index db6bb3617..5ec456c2b 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -16,7 +16,7 @@ permissions: jobs: test: name: Test - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 From b8b7377cf6423268c376bde0629cff5832889014 Mon Sep 17 00:00:00 2001 From: mintaka Date: Wed, 11 Nov 2026 03:01:35 -0500 Subject: [PATCH 9/9] fix(ci): scrub hook GIT_DIR from fork release tests and pin hk base (RIG-9272) A pre-push hook in a linked worktree exports GIT_DIR. Both fork release test scripts spread process.env into every child git call, so their scratch-repo writes landed in the real repo. Build one child env with GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, and GIT_COMMON_DIR removed, and pass it to every spawn. Add a sentinel regression test that fails without the scrub. Set hk default_branch to origin/rigel-release. The local rigel-release branch does not exist in a worktree, so hk fell back to an empty-tree base. Refs RIG-9272 Co-authored-by: Matt Wilkinson --- .github/scripts/release-tag.test.mjs | 54 ++++++++++++++++++-- .github/scripts/workflow-contract.test.mjs | 57 +++++++++++++++++++--- hk.pkl | 2 +- 3 files changed, 103 insertions(+), 10 deletions(-) diff --git a/.github/scripts/release-tag.test.mjs b/.github/scripts/release-tag.test.mjs index d98f62270..08bee7ac4 100644 --- a/.github/scripts/release-tag.test.mjs +++ b/.github/scripts/release-tag.test.mjs @@ -11,6 +11,36 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { fileURLToPath } from 'node:url' +// A pre-push hook in a linked worktree exports GIT_DIR. Simulate that with a +// sentinel repo, then build the child env once without the hook's git +// variables. Every spawn in this file uses that env, so the sentinel must +// stay unchanged. +const sentinel = mkdtempSync(join(tmpdir(), 'virtual-git-sentinel-')) +process.env.GIT_DIR = join(sentinel, '.git') +const hookGitVars = [ + 'GIT_DIR', + 'GIT_WORK_TREE', + 'GIT_INDEX_FILE', + 'GIT_COMMON_DIR', +] +const childEnv = { ...process.env } +for (const key of hookGitVars) delete childEnv[key] +const sentinelGit = (args) => { + const result = spawnSync('git', args, { + cwd: sentinel, + encoding: 'utf8', + env: childEnv, + }) + assert.equal(result.status, 0, result.stderr) + return result.stdout.trim() +} +sentinelGit(['init', '-q', '-b', 'sentinel']) +sentinelGit(['config', 'user.name', 'sentinel']) +sentinelGit(['config', 'user.email', 'sentinel@example.invalid']) +sentinelGit(['commit', '-q', '--allow-empty', '-m', 'sentinel']) +sentinelGit(['tag', 'sentinel-tag']) +const sentinelRefs = sentinelGit(['for-each-ref']) + const script = fileURLToPath(new URL('./release-tag.mjs', import.meta.url)) const dir = mkdtempSync(join(tmpdir(), 'virtual-release-tag-')) const repo = join(dir, 'repo') @@ -48,17 +78,24 @@ console.error('unexpected gh call:', args); process.exit(2); `, ) -const chmod = spawnSync('chmod', ['+x', join(bin, 'gh')], { encoding: 'utf8' }) +const chmod = spawnSync('chmod', ['+x', join(bin, 'gh')], { + encoding: 'utf8', + env: childEnv, +}) assert.equal(chmod.status, 0, chmod.stderr) const env = { - ...process.env, + ...childEnv, PATH: `${bin}:${process.env.PATH}`, GH_LOG: ghLog, GH_MARKER: ghMarker, } function git(args) { - const result = spawnSync('git', args, { cwd: repo, encoding: 'utf8' }) + const result = spawnSync('git', args, { + cwd: repo, + encoding: 'utf8', + env: childEnv, + }) assert.equal(result.status, 0, result.stderr) return result.stdout.trim() } @@ -84,6 +121,7 @@ try { const init = spawnSync('git', ['init', '-q', '-b', 'rigel-release'], { cwd: repo, encoding: 'utf8', + env: childEnv, }) assert.equal(init.status, 0, init.stderr) git(['config', 'user.name', 'test']) @@ -183,3 +221,13 @@ try { } finally { rmSync(dir, { recursive: true, force: true }) } +try { + assert.equal( + sentinelGit(['for-each-ref']), + sentinelRefs, + 'FAIL GIT_DIR leaked into child git', + ) + console.log('ok GIT_DIR from a hook leaves the sentinel repo unchanged') +} finally { + rmSync(sentinel, { recursive: true, force: true }) +} diff --git a/.github/scripts/workflow-contract.test.mjs b/.github/scripts/workflow-contract.test.mjs index 8d770ec8d..aac6cd555 100644 --- a/.github/scripts/workflow-contract.test.mjs +++ b/.github/scripts/workflow-contract.test.mjs @@ -11,6 +11,36 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { fileURLToPath } from 'node:url' +// A pre-push hook in a linked worktree exports GIT_DIR. Simulate that with a +// sentinel repo, then build the child env once without the hook's git +// variables. Every spawn in this file uses that env, so the sentinel must +// stay unchanged. +const sentinel = mkdtempSync(join(tmpdir(), 'virtual-git-sentinel-')) +process.env.GIT_DIR = join(sentinel, '.git') +const hookGitVars = [ + 'GIT_DIR', + 'GIT_WORK_TREE', + 'GIT_INDEX_FILE', + 'GIT_COMMON_DIR', +] +const childEnv = { ...process.env } +for (const key of hookGitVars) delete childEnv[key] +const sentinelGit = (args) => { + const result = spawnSync('git', args, { + cwd: sentinel, + encoding: 'utf8', + env: childEnv, + }) + assert.equal(result.status, 0, result.stderr) + return result.stdout.trim() +} +sentinelGit(['init', '-q', '-b', 'sentinel']) +sentinelGit(['config', 'user.name', 'sentinel']) +sentinelGit(['config', 'user.email', 'sentinel@example.invalid']) +sentinelGit(['commit', '-q', '--allow-empty', '-m', 'sentinel']) +sentinelGit(['tag', 'sentinel-tag']) +const sentinelRefs = sentinelGit(['for-each-ref']) + const scriptsDir = fileURLToPath(new URL('.', import.meta.url)) const root = fileURLToPath(new URL('../..', import.meta.url)) const publisherPath = join(root, '.github/workflows/publish-rigelbuild.yml') @@ -43,7 +73,7 @@ try { const dispatch = spawnSync(process.execPath, [resolverPath], { encoding: 'utf8', env: { - ...process.env, + ...childEnv, EVENT_NAME: 'workflow_dispatch', REF: 'refs/heads/rigel-release', GITHUB_OUTPUT: outputPath, @@ -82,13 +112,18 @@ passes( const guardDir = mkdtempSync(join(tmpdir(), 'virtual-publisher-guard-')) try { const runGit = (args) => { - const result = spawnSync('git', args, { cwd: guardDir, encoding: 'utf8' }) + const result = spawnSync('git', args, { + cwd: guardDir, + encoding: 'utf8', + env: childEnv, + }) assert.equal(result.status, 0, result.stderr) return result.stdout.trim() } const init = spawnSync('git', ['init', '-q', '-b', 'rigel-release'], { cwd: guardDir, encoding: 'utf8', + env: childEnv, }) assert.equal(init.status, 0, init.stderr) runGit(['config', 'user.name', 'test']) @@ -108,7 +143,7 @@ try { cwd: guardDir, encoding: 'utf8', env: { - ...process.env, + ...childEnv, EVENT_NAME: 'push', REF: 'refs/tags/v3.0.0-rigel.1', GITHUB_OUTPUT: join(guardDir, 'accepted-output'), @@ -128,7 +163,7 @@ try { cwd: guardDir, encoding: 'utf8', env: { - ...process.env, + ...childEnv, EVENT_NAME: 'push', REF: 'refs/tags/v3.0.0-rigel.2', GITHUB_OUTPUT: join(guardDir, 'rejected-output'), @@ -151,7 +186,7 @@ try { cwd: guardDir, encoding: 'utf8', env: { - ...process.env, + ...childEnv, EVENT_NAME: 'push', REF: 'refs/tags/v3.0.0-rigel.3', GITHUB_OUTPUT: join(guardDir, 'detached-output'), @@ -174,7 +209,7 @@ try { cwd: guardDir, encoding: 'utf8', env: { - ...process.env, + ...childEnv, EVENT_NAME: 'push', REF: 'refs/tags/v3.0.0-rc.1', GITHUB_OUTPUT: join(guardDir, 'bad-shape-output'), @@ -186,3 +221,13 @@ try { } finally { rmSync(guardDir, { recursive: true, force: true }) } +try { + assert.equal( + sentinelGit(['for-each-ref']), + sentinelRefs, + 'FAIL GIT_DIR leaked into child git', + ) + console.log('ok GIT_DIR from a hook leaves the sentinel repo unchanged') +} finally { + rmSync(sentinel, { recursive: true, force: true }) +} diff --git a/hk.pkl b/hk.pkl index e6fbff00b..9362031c6 100644 --- a/hk.pkl +++ b/hk.pkl @@ -1,7 +1,7 @@ // Git hooks managed by hk (https://hk.jdx.dev). amends "package://github.com/jdx/hk/releases/download/v2.11.1/hk@2.11.1#/Config.pkl" -default_branch = "rigel-release" +default_branch = "origin/rigel-release" hooks { ["pre-push"] {