forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprerelease.ts
More file actions
122 lines (109 loc) · 3.92 KB
/
Copy pathprerelease.ts
File metadata and controls
122 lines (109 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* Publish a prerelease to npm (publish-only, no build/test/bump).
*
* Version bumping is handled by bump-prerelease.ts in the secrets-free CI
* build job. Build and test also run there. This script receives pre-built,
* correctly-versioned artifacts and only performs the npm publish step.
*
* Always publishes with the "canary" dist-tag.
*
* Usage: tsx scripts/release/prerelease.ts --scope <scope from release.config.json> [--dry-run]
*/
import { spawnSync } from "child_process";
import { getPackagesForScope } from "./lib/versions.js";
import { ROOT, loadConfig } from "./lib/config.js";
import type { ReleaseScope } from "./lib/config.js";
import { emitGithubOutputs } from "./lib/github-output.js";
function run(cmd: string, args: string[], opts?: { cwd?: string }) {
const result = spawnSync(cmd, args, {
cwd: opts?.cwd ?? ROOT,
stdio: "inherit",
encoding: "utf8",
});
if (result.status !== 0) {
throw new Error(`Command failed: ${cmd} ${args.join(" ")}`);
}
return result;
}
// Valid scopes come from release.config.json — the single source of truth.
const VALID_SCOPES = Object.keys(loadConfig().scopes);
function main() {
const argv = process.argv.slice(2);
const dryRun = argv.includes("--dry-run");
const scopeIdx = argv.indexOf("--scope");
const scope = (
scopeIdx !== -1 ? argv[scopeIdx + 1] : null
) as ReleaseScope | null;
if (!scope || !VALID_SCOPES.includes(scope)) {
console.error(
`Usage: prerelease.ts --scope <${VALID_SCOPES.join("|")}> [--dry-run]`,
);
process.exit(1);
}
const config = loadConfig();
const distTag = config.prereleaseTag;
// Read the version from package.json — already bumped by bump-prerelease.ts
// in the CI build job.
const packages = getPackagesForScope(scope);
if (packages.length === 0) {
console.error(
`No packages found for scope "${scope}" — refusing to emit a version for a publish that did nothing.`,
);
process.exit(1);
}
const publishVersion = packages[0].pkg.version;
if (!publishVersion) {
console.error(
`Package ${packages[0].name} has no version field; refusing to publish.`,
);
process.exit(1);
}
console.log(`Scope: ${scope}`);
console.log(`Publishing version: ${publishVersion}`);
console.log(`Dist tag: ${distTag}`);
if (dryRun) {
console.log("\n[DRY RUN] Would publish these packages:");
for (const p of packages) {
console.log(` ${p.name}@${p.pkg.version}`);
}
// Emitting in dry-run is safe — the publish workflow gates both the
// publish step and the verify guard on `inputs.dry-run != true`, so this
// only serves local/e2e verification of the output contract.
emitGithubOutputs({ version: publishVersion, scope });
console.log("\n[DRY RUN] Exiting.");
return;
}
// NOTE: Version bumping is handled by bump-prerelease.ts in the CI build
// job (no secrets). Build and test also run there.
// The publish job receives pre-built artifacts via download-artifact.
// We intentionally do NOT rebuild/retest here to keep NPM_TOKEN out
// of the build process tree.
// Publish each package via pnpm pack + npx npm@11 (OIDC-aware)
console.log("\nPublishing packages...");
for (const p of packages) {
console.log(
` Publishing ${p.name}@${p.pkg.version} with tag ${distTag}...`,
);
run("pnpm", ["pack"], { cwd: p.dir });
const tarball = `${p.name.replace("@", "").replace("/", "-")}-${p.pkg.version}.tgz`;
run(
"npx",
[
"--yes",
"npm@11.15.0",
"publish",
tarball,
"--tag",
distTag,
"--access",
"public",
],
{ cwd: p.dir },
);
}
// The workflow's "Verify publish step emitted version" guard and the
// prerelease summary read these from steps.publish.outputs.
emitGithubOutputs({ version: publishVersion, scope });
console.log(`\nPrerelease published: ${publishVersion} (tag: ${distTag})`);
}
main();