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
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,17 @@ jobs:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Enable Corepack
run: corepack enable
- 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: ${{ matrix.node-version }}
cache: pnpm

- name: Activate pnpm
run: corepack enable

- name: Install dependencies
run: pnpm install --frozen-lockfile

Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ jobs:
registry-url: https://registry.npmjs.org
package-manager-cache: false

- name: Enable Corepack
run: corepack enable

- name: Use the reviewed npm release
run: npm install --global npm@11.18.0

Expand All @@ -126,4 +123,4 @@ jobs:
path: .release

- name: Publish verified prepared tarballs
run: pnpm run release:publish -- --expected-release-commit "${RELEASE_COMMIT}" --manifest .release/package-manifest.json
run: node scripts/release-packages.mjs publish --expected-release-commit "${RELEASE_COMMIT}" --manifest .release/package-manifest.json
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Contributing to Scheduler

Scheduler requires Node.js 22 or newer.
Scheduler is developed on Node.js 22 and 24 (the CI gate). Those releases
bundle Corepack. Official Node 25+ builds do not, so they are not a
documented local toolchain.

```sh
corepack enable
pnpm install --frozen-lockfile
pnpm run format:check
pnpm run check
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ The first consumers are:

## Development

Use Node.js 22 or 24. Those releases bundle Corepack; official Node 25+
builds do not, so they are not a documented local toolchain.

```sh
corepack enable
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
pnpm install --frozen-lockfile
pnpm run format:check
pnpm run check
Expand Down
14 changes: 9 additions & 5 deletions docs/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
There are exactly two publication paths:

1. a one-time manual bootstrap of `@pegma/scheduler@0.0.0` and
`@pegma/scheduler-cloudflare@0.0.0` (**done**; dist-tag `bootstrap` only); and
`@pegma/scheduler-cloudflare@0.0.0` (**done**; dist-tag `bootstrap` only;
that immutable pre-pnpm tag remains an npm-era receipt); and
2. every advertised release, beginning with `0.1.0` (**published**), through the
environment-protected GitHub OIDC workflow in
[`.github/workflows/publish.yml`](../.github/workflows/publish.yml).
Expand Down Expand Up @@ -34,8 +35,8 @@ before tagging. Never unpublish and reuse a version.

## Normal OIDC releases (`0.1.0` and later)

1. Land a reviewed PR that sets both public packages (and lockfile / fixture
pins) to the same stable version, and updates release notes.
1. Land a reviewed PR that sets both public packages (and `pnpm-lock.yaml` /
fixture pins) to the same stable version, and updates release notes.
2. After merge to `main`, create a **protected signed annotated** tag:

```sh
Expand All @@ -54,8 +55,11 @@ before tagging. Never unpublish and reuse a version.
4. The workflow:
- verifies the signed tag against `RELEASE_ALLOWED_SIGNERS`;
- runs the full gate;
- packs both packages with `pnpm run release:pack`;
- publishes exact tarballs with provenance via OIDC (`pnpm run release:publish`).
- packs both packages with `pnpm run release:pack` (npm CLI for `pack` /
registry `view`);
- publishes exact tarballs with provenance via OIDC
(`node scripts/release-packages.mjs publish`). The OIDC job does not
download Corepack pnpm.

Local helpers (never substitute for the OIDC lane for advertised releases):

Expand Down
11 changes: 11 additions & 0 deletions scripts/release-packages.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ export function parsePnpmLockfileImporters(
Record<string, Record<string, { specifier?: string; version?: string }>>
>;

export function resolvedVersionSatisfies(
version: string,
specifier: string,
): boolean;

export function lockDependencyMatches(
lockDependency: { specifier?: string; version?: string } | undefined,
specifier: string,
options?: { workspace?: boolean },
): boolean;

export function isNormalReleaseVersion(version: string): boolean;

export function parseArguments(
Expand Down
165 changes: 145 additions & 20 deletions scripts/release-packages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,17 @@ function run(command, arguments_, options = {}) {
return result;
}

/** `pnpm run` sets npm_execpath to pnpm; pack/view/publish must still be npm. */
function npmEnvironment(env = process.env) {
const isolated = { ...env };
delete isolated.npm_execpath;
return isolated;
}

function runNpm(arguments_, options = {}) {
return run(process.platform === "win32" ? "npm.cmd" : "npm", arguments_, {
...options,
env: npmEnvironment(options.env ?? process.env),
shell: process.platform === "win32",
});
}
Expand All @@ -101,14 +109,14 @@ function runPnpm(arguments_, options = {}) {
});
}

function unquoteYamlKey(key) {
function unquoteYamlScalar(value) {
if (
(key.startsWith("'") && key.endsWith("'")) ||
(key.startsWith('"') && key.endsWith('"'))
(value.startsWith("'") && value.endsWith("'")) ||
(value.startsWith('"') && value.endsWith('"'))
) {
return key.slice(1, -1);
return value.slice(1, -1);
}
return key;
return value;
}

/** Reads pnpm-lock.yaml importers without a YAML dependency. */
Expand All @@ -135,7 +143,7 @@ export function parsePnpmLockfileImporters(text) {

const importerMatch = /^ {2}(\S[^:]*):$/u.exec(line);
if (importerMatch !== null) {
currentPath = unquoteYamlKey(importerMatch[1]);
currentPath = unquoteYamlScalar(importerMatch[1]);
importers[currentPath] = {};
currentSection = null;
currentDep = null;
Expand All @@ -155,7 +163,7 @@ export function parsePnpmLockfileImporters(text) {

const depMatch = /^ {6}([^:]+):$/u.exec(line);
if (depMatch !== null && currentPath !== null && currentSection !== null) {
currentDep = unquoteYamlKey(depMatch[1]);
currentDep = unquoteYamlScalar(depMatch[1]);
importers[currentPath][currentSection][currentDep] = {};
continue;
}
Expand All @@ -168,12 +176,122 @@ export function parsePnpmLockfileImporters(text) {
currentDep !== null
) {
importers[currentPath][currentSection][currentDep][fieldMatch[1]] =
fieldMatch[2];
unquoteYamlScalar(fieldMatch[2]);
}
}
return importers;
}

function parseSemverTriple(version) {
const match = STABLE_SEMVER.exec(version);
if (match === null) {
return null;
}
return [Number(match[1]), Number(match[2]), Number(match[3])];
}

function leadingResolvedSemver(version) {
const full = /^(\d+)\.(\d+)\.(\d+)/u.exec(version);
if (full !== null) {
return [Number(full[1]), Number(full[2]), Number(full[3])];
}
const majorMinor = /^(\d+)\.(\d+)(?![.\d])/u.exec(version);
if (majorMinor !== null) {
return [Number(majorMinor[1]), Number(majorMinor[2]), 0];
}
const major = /^(\d+)(?![.\d])/u.exec(version);
if (major !== null) {
return [Number(major[1]), 0, 0];
}
return null;
}

function compareSemver(left, right) {
for (let index = 0; index < 3; index += 1) {
if (left[index] !== right[index]) {
return left[index] < right[index] ? -1 : 1;
}
}
return 0;
}

function caretUpperBound([major, minor, patch]) {
if (major > 0) {
return [major + 1, 0, 0];
}
if (minor > 0) {
return [0, minor + 1, 0];
}
return [0, 0, patch + 1];
}

function tildeUpperBound([major, minor]) {
return [major, minor + 1, 0];
}

function inHalfOpenRange(resolved, lower, upper) {
return (
compareSemver(resolved, lower) >= 0 && compareSemver(resolved, upper) < 0
);
}

/** Exact pins must match; ranges accept a resolved version in the specifier. */
export function resolvedVersionSatisfies(version, specifier) {
if (STABLE_SEMVER.test(specifier)) {
return version === specifier || version.startsWith(`${specifier}(`);
}
if (specifier === "*" || specifier === "x" || specifier === "X") {
return leadingResolvedSemver(version) !== null;
}
const resolved = leadingResolvedSemver(version);
if (resolved === null) {
return false;
}
if (specifier.startsWith("^")) {
const lower = parseSemverTriple(specifier.slice(1));
return (
lower !== null && inHalfOpenRange(resolved, lower, caretUpperBound(lower))
);
}
if (specifier.startsWith("~")) {
const lower = parseSemverTriple(specifier.slice(1));
return (
lower !== null && inHalfOpenRange(resolved, lower, tildeUpperBound(lower))
);
}
const majorOnly = /^(\d+)$/u.exec(specifier);
if (majorOnly !== null) {
const lower = [Number(majorOnly[1]), 0, 0];
return inHalfOpenRange(resolved, lower, [lower[0] + 1, 0, 0]);
}
const majorMinor = /^(\d+)\.(\d+)$/u.exec(specifier);
if (majorMinor !== null) {
const lower = [Number(majorMinor[1]), Number(majorMinor[2]), 0];
return inHalfOpenRange(resolved, lower, tildeUpperBound(lower));
}
return false;
}

/**
* Each lockfile importer entry must carry that dependency's own specifier and
* a resolved version that satisfies it. Independent substring matches can
* accept a swapped pin; exact-equality on ranges rejects a valid lockfile.
*/
export function lockDependencyMatches(lockDependency, specifier, options = {}) {
if (
lockDependency === undefined ||
unquoteYamlScalar(lockDependency.specifier ?? "") !== specifier ||
typeof lockDependency.version !== "string"
) {
return false;
}
const version = unquoteYamlScalar(lockDependency.version);
if (options.workspace === true) {
return version.startsWith("link:");
}
return resolvedVersionSatisfies(version, specifier);
}

function gitCommand() {
return process.platform === "win32" ? "git.exe" : "git";
}
Expand Down Expand Up @@ -265,22 +383,29 @@ async function validatePackage(root, definition, lockfile) {
}
for (const section of DEPENDENCY_SECTIONS) {
for (const [name, version] of Object.entries(manifest[section] ?? {})) {
if (!RELEASE_NAMES.has(name)) {
continue;
const workspace = RELEASE_NAMES.has(name);
if (workspace) {
const dependency = RELEASE_PACKAGES.find(
(entry) => entry.name === name,
);
const dependencyManifest = await readJson(
join(root, "packages", dependency.directory, "package.json"),
);
if (version !== dependencyManifest.version) {
fail(
`${definition.name} must pin ${name} to its exact workspace version`,
);
}
}
const dependency = RELEASE_PACKAGES.find((entry) => entry.name === name);
const dependencyManifest = await readJson(
join(root, "packages", dependency.directory, "package.json"),
);
const lockDependency = lockEntry[section]?.[name];
if (
version !== dependencyManifest.version ||
lockDependency?.specifier !== version ||
typeof lockDependency?.version !== "string" ||
!lockDependency.version.startsWith("link:")
!lockDependencyMatches(lockEntry[section]?.[name], version, {
workspace,
})
) {
fail(
`${definition.name} must pin ${name} to its exact workspace version`,
workspace
? `${definition.name} must pin ${name} to its exact workspace version`
: `${definition.name} ${name}@${version} is not synchronized with pnpm-lock.yaml`,
);
}
}
Expand Down
Loading