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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
307 changes: 270 additions & 37 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,75 @@ concurrency:
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
manifest_digest: ${{ steps.manifest.outputs.digest }}
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_PRERELEASE: ${{ github.event.release.prerelease }}
RELEASE_COMMIT: ${{ github.sha }}
RELEASE_ALLOWED_SIGNERS: ${{ vars.RELEASE_ALLOWED_SIGNERS }}

steps:
- name: Check out the release tag
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
ref: refs/tags/${{ github.event.release.tag_name }}
fetch-depth: 0

- name: Fetch the protected release branch
run: git fetch --no-tags origin main:refs/remotes/origin/main

- name: Configure approved release signers
- name: Authenticate the release tag

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Duplicate tag-authentication Bash blocks (nit)

Concrete failure: Identical 30-line Authenticate the release tag Bash is duplicated in prepare and publish. A future edit that updates one block (e.g., regex, allowed_signers handling) and not the other silently desynchronizes the two gates, allowing a tag that passes prepare to fail (or worse, pass with weaker checks) in publish.

Evidence: publish.yml:29-64 and publish.yml:172-210 are verbatim copies except for env. No shared composite action or uses: abstraction.

Checked: Full publish.yml via read_file; tests/publish-workflow.test.ts:11-33 asserts both contain the same strings but cannot prevent drift.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping both checks inline is intentional: prepare must authenticate before checkout, while publish must authenticate without any checkout. Moving this logic into repository files would cross those execution boundaries; structure tests assert the complete checks in both jobs.

shell: bash
run: |
set -euo pipefail
if [[ "${RELEASE_PRERELEASE}" != "false" ]]; then
echo "::error::Only stable releases may publish packages"
exit 1
fi
if [[ ! "${RELEASE_TAG}" =~ ^v(0\.[1-9][0-9]*|[1-9][0-9]*\.[0-9]+)\.[0-9]+$ ]]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tag-format authority duplicated as a bash regex that rejects v0.0.x (nit)

The workflow's bash regex ^v(0\.[1-9][0-9]*|[1-9][0-9]*\.[0-9]+)\.[0-9]+$ is now the only tag validation in the CI lane (the script's --require-release-tag flag was dropped), and it rejects v0.0.x outright while permitting v0.1.0 and v1.0.0. Two costs: a legitimate v0.0.x hotfix release can never publish through this workflow if the project ever needs one, and the format rules now live in two places (this regex and the script's STABLE_SEMVER/validateReleaseTag) that can drift — a tag shape the script accepts could be permanently refused by CI or vice versa.

Proof gap: STABLE_SEMVER and validateReleaseTag definitions in scripts/release-packages.mjs were not re-read in this pass to confirm the exact divergence.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The normal release lane intentionally rejects the complete 0.0.x bootstrap range, as documented in RELEASING.md and enforced by isNormalReleaseVersion. The workflow expression matches that established release contract.

echo "::error::RELEASE_TAG must be a stable supported version"
exit 1
fi
if [[ ! "${RELEASE_COMMIT}" =~ ^[0-9a-fA-F]{40}$ ]]; then
echo "::error::RELEASE_COMMIT must be an exact commit"
exit 1
fi
if [[ -z "${RELEASE_ALLOWED_SIGNERS}" ]]; then
echo "::error::RELEASE_ALLOWED_SIGNERS must contain the reviewed SSH allowed-signers entries"
echo "::error::RELEASE_ALLOWED_SIGNERS must contain reviewed entries"
exit 1
fi
allowed_signers="${RUNNER_TEMP}/release-allowed-signers"
release_repo="$(mktemp -d "${RUNNER_TEMP}/release-git.XXXXXX")"
trap 'rm -rf "${release_repo}"' EXIT
git init --bare "${release_repo}"
git -C "${release_repo}" remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
allowed_signers="${release_repo}/allowed-signers"
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
umask 077
printf '%s\n' "${RELEASE_ALLOWED_SIGNERS}" > "${allowed_signers}"
git config --local gpg.format ssh
git config --local gpg.ssh.allowedSignersFile "${allowed_signers}"
chmod 0600 "${allowed_signers}"
git -C "${release_repo}" config gpg.format ssh
git -C "${release_repo}" config gpg.ssh.allowedSignersFile "${allowed_signers}"
git -C "${release_repo}" fetch --no-tags origin \
refs/heads/main:refs/remotes/origin/main \
"+refs/tags/${RELEASE_TAG}:refs/tags/${RELEASE_TAG}"
[[ "$(git -C "${release_repo}" cat-file -t "refs/tags/${RELEASE_TAG}")" == "tag" ]]
git -C "${release_repo}" verify-tag "refs/tags/${RELEASE_TAG}"
tag_commit="$(git -C "${release_repo}" rev-parse "refs/tags/${RELEASE_TAG}^{commit}")"
[[ "${tag_commit}" == "${RELEASE_COMMIT,,}" ]]
git -C "${release_repo}" merge-base --is-ancestor \
"${RELEASE_COMMIT}" refs/remotes/origin/main

- name: Check out the release commit
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
ref: ${{ github.sha }}
persist-credentials: false
fetch-depth: 0

- name: Set up pnpm
uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
with:
version: 10.34.5

- name: Set up Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
with:
node-version: 24.18.0
registry-url: https://registry.npmjs.org
package-manager-cache: false

- name: Enable Corepack
run: corepack enable
cache: pnpm

- name: Use the reviewed npm release
run: npm install --global npm@11.18.0
run: npm install --global npm@11.18.0 --ignore-scripts --registry https://registry.npmjs.org/

- name: Install dependencies
run: pnpm install --frozen-lockfile
Expand All @@ -71,56 +99,261 @@ jobs:
- name: Run tests
run: pnpm test

- name: Prepare and verify release tarballs
run: pnpm run release:pack -- --require-clean --require-main-ancestor --require-release-tag --expected-release-commit "${RELEASE_COMMIT}" --output .release
- name: Prepare release tarballs
run: pnpm run release:pack -- --require-clean --output .release

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 release:pack invoked without tag flags; manifest.releaseTag population in CI unverified (risk)

Every stable release could fail at the publish job if tag detection in the pack script is gated on the flags this PR removed. The prepare step now runs pnpm run release:pack -- --require-clean --output .release, dropping --require-release-tag --require-main-ancestor --expected-release-commit "${RELEASE_COMMIT}". The bash auth step re-verifies the tag/commit separately, but whether prepareRelease still populates manifest.releaseTag without --require-release-tag is not established by the diff: the publish step requires manifest.releaseTag === RELEASE_TAG and calls manifest.releaseTag.slice(1), so if tag detection is gated on the removed flag, manifest.releaseTag is undefined and every release fails at publish (fail-closed but release-blocking). Additionally, the script-side tag validation (validateReleaseTag, exercised only by the new unit tests) no longer runs in the CI release lane at all.

Proof gap: the releaseTag derivation and option handling inside prepareRelease in scripts/release-packages.mjs were outside the shown hunks, and I could not confirm whether detection is unconditional.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RELEASE_TAG is read unconditionally from the job environment during repository validation, so package-manifest.json receives the tag without this flag. require-release-tag only enables checkout-based tag verification, which is intentionally replaced by the earlier bare-repository check.


- name: Record the package manifest digest
id: manifest
shell: bash
run: |
set -euo pipefail
digest="$(sha256sum .release/package-manifest.json | cut -d ' ' -f 1)"
[[ "${digest}" =~ ^[0-9a-f]{64}$ ]]
printf 'digest=%s\n' "${digest}" >> "${GITHUB_OUTPUT}"

- name: Upload the prepared release
id: upload
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: scheduler-release-${{ github.run_id }}
path: .release/
if-no-files-found: error
include-hidden-files: true
include-hidden-files: false
overwrite: true
retention-days: 30

- name: Record the prepared artifact digest
run: echo "Prepared artifact SHA-256 ${{ steps.upload.outputs.artifact-digest }}" >> "${GITHUB_STEP_SUMMARY}"
smoke:
needs: prepare
runs-on: ubuntu-latest
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
permissions:
contents: read

steps:
- name: Set up Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
with:
node-version: 24.18.0
package-manager-cache: false

- name: Use the reviewed npm release
run: npm install --global npm@11.18.0 --ignore-scripts --registry https://registry.npmjs.org/

- name: Download the prepared release
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: scheduler-release-${{ github.run_id }}
path: .release

- name: Install and import the prepared packages
shell: bash
env:
MANIFEST_DIGEST: ${{ needs.prepare.outputs.manifest_digest }}
run: |
set -euo pipefail
smoke_dir="$(mktemp -d "${RUNNER_TEMP}/release-smoke.XXXXXX")"
trap 'rm -rf "${smoke_dir}"' EXIT
printf '%s\n' '{"name":"release-smoke","private":true,"type":"module"}' > "${smoke_dir}/package.json"
release_manifest="${GITHUB_WORKSPACE}/.release/package-manifest.json"
tarball_list="${RUNNER_TEMP}/release-tarballs"
export RELEASE_MANIFEST="${release_manifest}"
node --input-type=module > "${tarball_list}" <<'NODE'
import { createHash, timingSafeEqual } from "node:crypto";
import { readFile } from "node:fs/promises";
import { dirname, resolve } from "node:path";
const equal = (left, right) => {
const a = Buffer.from(left);
const b = Buffer.from(right);
return a.length === b.length && timingSafeEqual(a, b);
};
const manifestBytes = await readFile(process.env.RELEASE_MANIFEST);
const digest = createHash("sha256").update(manifestBytes).digest("hex");
if (!equal(digest, process.env.MANIFEST_DIGEST ?? "")) throw new Error("package manifest digest does not match");
const manifest = JSON.parse(manifestBytes.toString("utf8"));
if (!Array.isArray(manifest.packages) || manifest.packages.length === 0) throw new Error("package manifest inventory is invalid");
for (const record of manifest.packages) {
if (!Array.isArray(record.imports) || record.imports.length === 0) throw new Error(`${record.name} import inventory is invalid`);
const tarball = resolve(dirname(process.env.RELEASE_MANIFEST), record.tarball);
const bytes = await readFile(tarball);
const sha256 = createHash("sha256").update(bytes).digest("hex");
const integrity = `sha512-${createHash("sha512").update(bytes).digest("base64")}`;
if (!equal(sha256, record.sha256) || !equal(integrity, record.integrity)) throw new Error(`${record.name} package digest does not match`);
console.log(tarball);
}
NODE
mapfile -t tarballs < "${tarball_list}"
[[ "${#tarballs[@]}" -gt 0 ]]
npm install --prefix "${smoke_dir}" --ignore-scripts --no-audit --no-fund \
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
--package-lock=false --registry https://registry.npmjs.org/ "${tarballs[@]}"
cd "${smoke_dir}"
node --input-type=module <<'NODE'
import { readFile } from "node:fs/promises";
const manifest = JSON.parse(await readFile(process.env.RELEASE_MANIFEST, "utf8"));
for (const record of manifest.packages) {
for (const specifier of record.imports) await import(specifier);
}
NODE

publish:
needs: prepare
needs: [prepare, smoke]
runs-on: ubuntu-latest
environment: npm-publish
permissions:
contents: read
id-token: write
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_PRERELEASE: ${{ github.event.release.prerelease }}
RELEASE_COMMIT: ${{ github.sha }}
RELEASE_ALLOWED_SIGNERS: ${{ vars.RELEASE_ALLOWED_SIGNERS }}

steps:
- name: Check out the exact release tag
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
ref: refs/tags/${{ github.event.release.tag_name }}
fetch-depth: 1
- name: Authenticate the release tag
shell: bash
run: |
set -euo pipefail
if [[ "${RELEASE_PRERELEASE}" != "false" ]]; then
echo "::error::Only stable releases may publish packages"
exit 1
fi
if [[ ! "${RELEASE_TAG}" =~ ^v(0\.[1-9][0-9]*|[1-9][0-9]*\.[0-9]+)\.[0-9]+$ ]]; then
echo "::error::RELEASE_TAG must be a stable supported version"
exit 1
fi
if [[ ! "${RELEASE_COMMIT}" =~ ^[0-9a-fA-F]{40}$ ]]; then
echo "::error::RELEASE_COMMIT must be an exact commit"
exit 1
fi
if [[ -z "${RELEASE_ALLOWED_SIGNERS}" ]]; then
echo "::error::RELEASE_ALLOWED_SIGNERS must contain reviewed entries"
exit 1
fi
release_repo="$(mktemp -d "${RUNNER_TEMP}/release-git.XXXXXX")"
trap 'rm -rf "${release_repo}"' EXIT
git init --bare "${release_repo}"
git -C "${release_repo}" remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
allowed_signers="${release_repo}/allowed-signers"
umask 077
printf '%s\n' "${RELEASE_ALLOWED_SIGNERS}" > "${allowed_signers}"
chmod 0600 "${allowed_signers}"
git -C "${release_repo}" config gpg.format ssh
git -C "${release_repo}" config gpg.ssh.allowedSignersFile "${allowed_signers}"
git -C "${release_repo}" fetch --no-tags origin \
refs/heads/main:refs/remotes/origin/main \
"+refs/tags/${RELEASE_TAG}:refs/tags/${RELEASE_TAG}"
[[ "$(git -C "${release_repo}" cat-file -t "refs/tags/${RELEASE_TAG}")" == "tag" ]]
git -C "${release_repo}" verify-tag "refs/tags/${RELEASE_TAG}"
tag_commit="$(git -C "${release_repo}" rev-parse "refs/tags/${RELEASE_TAG}^{commit}")"
[[ "${tag_commit}" == "${RELEASE_COMMIT,,}" ]]
git -C "${release_repo}" merge-base --is-ancestor \
"${RELEASE_COMMIT}" refs/remotes/origin/main

- name: Set up Node.js and the npm registry
- name: Set up Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
with:
node-version: 24.18.0
registry-url: https://registry.npmjs.org
package-manager-cache: false

- name: Use the reviewed npm release
run: npm install --global npm@11.18.0
run: npm install --global npm@11.18.0 --ignore-scripts --registry https://registry.npmjs.org/

- name: Download the prepared release
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: scheduler-release-${{ github.run_id }}
path: .release

- name: Publish verified prepared tarballs
run: node scripts/release-packages.mjs publish --expected-release-commit "${RELEASE_COMMIT}" --manifest .release/package-manifest.json
- name: Verify and publish the prepared packages
env:
MANIFEST_DIGEST: ${{ needs.prepare.outputs.manifest_digest }}
run: |
node --input-type=module <<'NODE'
import { spawnSync } from "node:child_process";
import { createHash, timingSafeEqual } from "node:crypto";
import { lstat, mkdtemp, readFile, readdir, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { resolve } from "node:path";

const fail = (message) => { throw new Error(message); };
const equal = (left, right) => {
const a = Buffer.from(left);
const b = Buffer.from(right);
return a.length === b.length && timingSafeEqual(a, b);
};
const releaseDirectory = resolve(".release");
const manifestPath = resolve(releaseDirectory, "package-manifest.json");
const manifestBytes = await readFile(manifestPath);
const digest = createHash("sha256").update(manifestBytes).digest("hex");
if (!equal(digest, process.env.MANIFEST_DIGEST ?? "")) fail("package manifest digest does not match");
const manifest = JSON.parse(manifestBytes.toString("utf8"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Two-package inventory hardcoded in workflow smoke imports, publish script, and docs (risk)

Adding a third package to RELEASE_PACKAGES in scripts/release-packages.mjs breaks or silently weakens the workflow. The package inventory is now duplicated by hand in three places: the smoke job's import eval (@​pegma/scheduler, @​pegma/scheduler-cloudflare), the publish job's inline const names = ["@​pegma/scheduler", "@​pegma/scheduler-cloudflare"], and docs/RELEASING.md. Concrete failure: after adding a package, the publish job's names comparison fails every release until the workflow is edited (fail-closed, releases blocked), while the smoke job keeps importing only the two listed packages, so the new package's runtime import is never smoke-tested (fail-open).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dbbd90c removes hardcoded smoke imports by consuming the sealed import inventory. The publication job intentionally retains the reviewed two-package allowlist required for this repository; adding a package must update that explicit release boundary and fail closed until reviewed.

const names = ["@pegma/scheduler", "@pegma/scheduler-cloudflare"];
const releaseCommit = (process.env.RELEASE_COMMIT ?? "").toLowerCase();
if (manifest.schemaVersion !== 1 || manifest.gitCommit !== releaseCommit ||
manifest.releaseTag !== process.env.RELEASE_TAG || !Array.isArray(manifest.packages) ||
JSON.stringify(manifest.packages.map(({ name }) => name)) !== JSON.stringify(names)) {
fail("package manifest inventory is invalid");
}
const expectedFiles = ["package-manifest.json"];
const directories = ["scheduler", "scheduler-cloudflare"];
for (const [index, record] of manifest.packages.entries()) {
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
const expectedTarball = `${names[index].slice(1).replace("/", "-")}-${record.version}.tgz`;
if (record.directory !== directories[index] || record.tarball !== expectedTarball ||
!/^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/.test(record.version) ||
record.publish !== (record.version === manifest.releaseTag.slice(1)) ||
!/^[0-9a-f]{64}$/.test(record.sha256) || !/^[0-9a-f]{40}$/.test(record.shasum) ||
!/^sha512-[A-Za-z0-9+/]+={0,2}$/.test(record.integrity) ||
!Array.isArray(record.files) || !Array.isArray(record.imports) || record.imports.length === 0) {
fail(`${record.name} package metadata is invalid`);
}
expectedFiles.push(record.tarball);
}
const entries = await readdir(releaseDirectory, { withFileTypes: true });
if (JSON.stringify(entries.map(({ name }) => name).sort()) !== JSON.stringify(expectedFiles.sort())) {
fail("release artifact inventory is invalid");
}
for (const entry of entries) {
const metadata = await lstat(resolve(releaseDirectory, entry.name));
if (entry.name.startsWith(".") || !entry.isFile() || !metadata.isFile() || metadata.isSymbolicLink()) {
fail("release artifact entries must be regular visible files");
}
}
for (const record of manifest.packages) {
const tarball = resolve(releaseDirectory, record.tarball);
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
const bytes = await readFile(tarball);
const sha256 = createHash("sha256").update(bytes).digest("hex");
const shasum = createHash("sha1").update(bytes).digest("hex");
const integrity = `sha512-${createHash("sha512").update(bytes).digest("base64")}`;
if (!equal(sha256, record.sha256) || !equal(shasum, record.shasum) ||
!equal(integrity, record.integrity)) {
fail(`${record.name} package digest does not match`);
}
}

const publishDirectory = await mkdtemp(resolve(process.env.RUNNER_TEMP ?? tmpdir(), "npm-publish."));
const configDirectory = await mkdtemp(resolve(process.env.RUNNER_TEMP ?? tmpdir(), "npm-config."));
const userConfig = resolve(configDirectory, "userconfig");
const globalConfig = resolve(configDirectory, "globalconfig");
await writeFile(userConfig, "", { mode: 0o600 });
await writeFile(globalConfig, "", { mode: 0o600 });
const environment = Object.fromEntries(Object.entries(process.env).filter(([key]) =>
["CI", "PATH", "HOME", "RUNNER_TEMP", "SYSTEMROOT"].includes(key) || key.startsWith("TMP") ||
key.startsWith("GITHUB_") || key.startsWith("ACTIONS_ID_TOKEN_")));
environment.NPM_CONFIG_USERCONFIG = userConfig;
environment.NPM_CONFIG_GLOBALCONFIG = globalConfig;
const npm = (args, allowMissing = false) => {
const result = spawnSync("npm", args, { cwd: publishDirectory, encoding: "utf8", env: environment });
if (result.error) throw result.error;
if (result.status !== 0 && !(allowMissing && /\bE404\b/.test(`${result.stdout}\n${result.stderr}`))) {
fail(`npm ${args[0]} failed: ${result.stderr.trim()}`);
}
return result;
};
for (const record of manifest.packages.filter(({ publish }) => publish)) {
const specifier = `${record.name}@${record.version}`;
const viewed = npm(["view", specifier, "dist.integrity", "--json", "--registry", "https://registry.npmjs.org/", "--ignore-scripts"], true);
if (viewed.status === 0) {
const registryIntegrity = JSON.parse(viewed.stdout);
if (!equal(registryIntegrity, record.integrity)) fail(`${specifier} registry digest differs`);
continue;
}
npm(["publish", resolve(releaseDirectory, record.tarball), "--tag", "latest", "--registry", "https://registry.npmjs.org/", "--access", "public", "--provenance", "--ignore-scripts"]);
}
NODE
Loading
Loading