Repository navigation
fix(release): publish in dependency order, fail closed on unpublished internal deps #538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
a821fcf
fix(release): order publish by dependency and fail closed on unpublis…
khaliqgant a740d31
fix(release): treat caret/tilde pins of the release version as in-rel…
khaliqgant 5b28e42
docs(release): list accepted pin forms in assert-internal-deps comment
khaliqgant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Fail-closed publish gate for internal @relayfile/* dependencies. | ||
| * | ||
| * The publish matrix runs in parallel, so nothing orders a dependent after the | ||
| * package it pins. On 2026-10-06 (run 37396747701, attempt 1) @relayfile/sdk | ||
| * and every other dependent published while @relayfile/core@0.10.73 failed its | ||
| * post-publish verification, leaving `npm install` of sdk@latest unresolvable | ||
| * (ETARGET) until core was re-run. | ||
| * | ||
| * Before a package may be published, every internal dependency it pins | ||
| * (dependencies, optionalDependencies, peerDependencies) must either | ||
| * | ||
| * - already resolve on the registry (`npm view name@spec version`), or | ||
| * - be produced by this same release (a pin on a release-set package in | ||
| * bare, ^, ~ or = form of the release version, per rangeTargetsVersion), | ||
| * in which case we WAIT for it to appear on the registry, because | ||
| * publishing first would reopen the gap. | ||
| * | ||
| * Anything else, or a wait that times out, is a hard failure: a dependent is | ||
| * never published unless its dependencies are verifiably installable. | ||
| */ | ||
|
|
||
| import { execFile } from "node:child_process"; | ||
| import { existsSync, readFileSync, realpathSync } from "node:fs"; | ||
| import { join, resolve } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import { RELEASE_PACKAGE_PATHS } from "./resolve-release-baseline.mjs"; | ||
| import { rangeTargetsVersion } from "./regenerate-release-lockfiles.mjs"; | ||
|
|
||
| export const INTERNAL_SCOPE = "@relayfile/"; | ||
| export const DEP_FIELDS = [ | ||
| "dependencies", | ||
| "optionalDependencies", | ||
| "peerDependencies", | ||
| ]; | ||
| export const DEFAULT_TIMEOUT_MS = 20 * 60 * 1000; | ||
| export const DEFAULT_POLL_MS = 15 * 1000; | ||
|
|
||
| /** @returns {{name:string, spec:string, field:string}[]} */ | ||
| export function internalDeps(pkg) { | ||
| const out = []; | ||
| for (const field of DEP_FIELDS) { | ||
| for (const [name, spec] of Object.entries(pkg[field] ?? {})) { | ||
| if (name.startsWith(INTERNAL_SCOPE)) out.push({ name, spec, field }); | ||
| } | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| /** name -> version for every package this release publishes. */ | ||
| export function loadReleaseSet(repoRoot) { | ||
| const set = new Map(); | ||
| for (const rel of RELEASE_PACKAGE_PATHS) { | ||
| if (rel === "package.json") continue; | ||
| const file = join(repoRoot, rel); | ||
| if (!existsSync(file)) continue; | ||
| const pkg = JSON.parse(readFileSync(file, "utf8")); | ||
| if (pkg.name) set.set(pkg.name, pkg.version); | ||
| } | ||
| return set; | ||
| } | ||
|
|
||
| export function npmViewResolves(name, spec) { | ||
| return new Promise((done) => { | ||
| execFile( | ||
| "npm", | ||
| ["view", `${name}@${spec}`, "version", "--json"], | ||
| { timeout: 30000, env: { ...process.env, NPM_CONFIG_FETCH_RETRIES: "1" } }, | ||
| (error, stdout) => done(!error && stdout.trim().length > 0), | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); | ||
|
|
||
| /** | ||
| * @returns {Promise<{ok:boolean, problems:string[]}>} | ||
| */ | ||
| export async function assertInternalDeps({ | ||
| pkg, | ||
| releaseSet, | ||
| dryRun = false, | ||
| resolves = npmViewResolves, | ||
| timeoutMs = DEFAULT_TIMEOUT_MS, | ||
| pollMs = DEFAULT_POLL_MS, | ||
| now = () => Date.now(), | ||
| wait = sleep, | ||
| log = () => {}, | ||
| }) { | ||
| const problems = []; | ||
| for (const { name, spec, field } of internalDeps(pkg)) { | ||
| const inSet = rangeTargetsVersion(spec, releaseSet.get(name) ?? ""); | ||
| if (await resolves(name, spec)) { | ||
| log(`ok ${name}@${spec} (${field}) is on the registry`); | ||
| continue; | ||
| } | ||
| if (!inSet) { | ||
| problems.push( | ||
| `${pkg.name}@${pkg.version} pins ${name}@${spec} (${field}), which is not on the registry and is not published by this release`, | ||
| ); | ||
| continue; | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| } | ||
| if (dryRun) { | ||
| log(`ok ${name}@${spec} (${field}) is in this release set (dry run, not waiting)`); | ||
| continue; | ||
| } | ||
| const deadline = now() + timeoutMs; | ||
| let found = false; | ||
| while (now() < deadline) { | ||
| log(`waiting for ${name}@${spec} to appear on the registry`); | ||
| await wait(pollMs); | ||
| if (await resolves(name, spec)) { | ||
| found = true; | ||
| break; | ||
| } | ||
| } | ||
| if (found) log(`ok ${name}@${spec} (${field}) appeared on the registry`); | ||
| else | ||
| problems.push( | ||
| `${pkg.name}@${pkg.version} must not publish: ${name}@${spec} (${field}) did not appear on the registry within ${Math.round(timeoutMs / 1000)}s`, | ||
| ); | ||
| } | ||
| return { ok: problems.length === 0, problems }; | ||
| } | ||
|
|
||
| function parseArgs(argv) { | ||
| const values = {}; | ||
| for (let i = 0; i < argv.length; i += 1) { | ||
| const arg = argv[i]; | ||
| if (!arg.startsWith("--")) throw new Error(`unexpected argument ${arg}`); | ||
| values[arg.slice(2)] = argv[++i]; | ||
| } | ||
| return values; | ||
| } | ||
|
|
||
| let entrypoint = ""; | ||
| try { | ||
| entrypoint = process.argv[1] ? realpathSync(resolve(process.argv[1])) : ""; | ||
| } catch { | ||
| entrypoint = ""; | ||
| } | ||
| if (entrypoint && entrypoint === realpathSync(fileURLToPath(import.meta.url))) { | ||
| const args = parseArgs(process.argv.slice(2)); | ||
| if (!args["package-dir"]) throw new Error("--package-dir is required"); | ||
| const repoRoot = resolve(args["repo-root"] ?? process.cwd()); | ||
| const pkg = JSON.parse( | ||
| readFileSync(join(resolve(args["package-dir"]), "package.json"), "utf8"), | ||
| ); | ||
| const result = await assertInternalDeps({ | ||
| pkg, | ||
| releaseSet: loadReleaseSet(repoRoot), | ||
| dryRun: args["dry-run"] === "true", | ||
| timeoutMs: args["timeout-ms"] | ||
| ? Number(args["timeout-ms"]) | ||
| : DEFAULT_TIMEOUT_MS, | ||
| log: (m) => console.log(m), | ||
| }); | ||
| if (!result.ok) { | ||
| for (const p of result.problems) console.error(`::error::${p}`); | ||
| process.exit(1); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.