@smoothbricks/cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +338 -88
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +136 -22
- package/dist/devenv/index.d.ts +10 -0
- package/dist/devenv/index.d.ts.map +1 -0
- package/dist/devenv/index.js +27 -0
- package/dist/lib/cli-package.d.ts +4 -0
- package/dist/lib/cli-package.d.ts.map +1 -0
- package/dist/lib/cli-package.js +15 -0
- package/dist/lib/devenv.d.ts +6 -0
- package/dist/lib/devenv.d.ts.map +1 -0
- package/dist/lib/devenv.js +82 -0
- package/dist/lib/run.d.ts +5 -0
- package/dist/lib/run.d.ts.map +1 -1
- package/dist/lib/run.js +13 -0
- package/dist/lib/workspace.d.ts +20 -1
- package/dist/lib/workspace.d.ts.map +1 -1
- package/dist/lib/workspace.js +87 -7
- package/dist/monorepo/commit-msg.d.ts +8 -1
- package/dist/monorepo/commit-msg.d.ts.map +1 -1
- package/dist/monorepo/commit-msg.js +85 -7
- package/dist/monorepo/index.d.ts +24 -2
- package/dist/monorepo/index.d.ts.map +1 -1
- package/dist/monorepo/index.js +136 -15
- package/dist/monorepo/lockfile.d.ts +5 -1
- package/dist/monorepo/lockfile.d.ts.map +1 -1
- package/dist/monorepo/lockfile.js +45 -5
- package/dist/monorepo/managed-files.d.ts +1 -1
- package/dist/monorepo/managed-files.d.ts.map +1 -1
- package/dist/monorepo/managed-files.js +28 -11
- package/dist/monorepo/nx-sync.d.ts +2 -1
- package/dist/monorepo/nx-sync.d.ts.map +1 -1
- package/dist/monorepo/nx-sync.js +8 -2
- package/dist/monorepo/package-hygiene.d.ts +6 -2
- package/dist/monorepo/package-hygiene.d.ts.map +1 -1
- package/dist/monorepo/package-hygiene.js +12 -4
- package/dist/monorepo/package-policy.d.ts +25 -2
- package/dist/monorepo/package-policy.d.ts.map +1 -1
- package/dist/monorepo/package-policy.js +1289 -27
- package/dist/monorepo/packed-manifest.d.ts +4 -0
- package/dist/monorepo/packed-manifest.d.ts.map +1 -0
- package/dist/monorepo/packed-manifest.js +51 -0
- package/dist/monorepo/packed-package.d.ts +3 -0
- package/dist/monorepo/packed-package.d.ts.map +1 -1
- package/dist/monorepo/packed-package.js +69 -31
- package/dist/monorepo/packs/index.d.ts +20 -1
- package/dist/monorepo/packs/index.d.ts.map +1 -1
- package/dist/monorepo/packs/index.js +240 -18
- package/dist/monorepo/publish-workflow.d.ts +82 -0
- package/dist/monorepo/publish-workflow.d.ts.map +1 -0
- package/dist/monorepo/publish-workflow.js +336 -0
- package/dist/monorepo/tool-validation.d.ts +22 -0
- package/dist/monorepo/tool-validation.d.ts.map +1 -0
- package/dist/monorepo/tool-validation.js +399 -0
- package/dist/nx/index.d.ts +24 -0
- package/dist/nx/index.d.ts.map +1 -0
- package/dist/nx/index.js +94 -0
- package/dist/nx-version-actions.cjs +25 -0
- package/dist/nx-version-actions.d.cts +6 -0
- package/dist/nx-version-actions.d.cts.map +1 -0
- package/dist/release/bootstrap-npm-packages.d.ts +19 -0
- package/dist/release/bootstrap-npm-packages.d.ts.map +1 -0
- package/dist/release/bootstrap-npm-packages.js +58 -0
- package/dist/release/candidates.d.ts +11 -0
- package/dist/release/candidates.d.ts.map +1 -0
- package/dist/release/candidates.js +181 -0
- package/dist/release/core.d.ts +51 -0
- package/dist/release/core.d.ts.map +1 -0
- package/dist/release/core.js +97 -0
- package/dist/release/github-release.d.ts +46 -0
- package/dist/release/github-release.d.ts.map +1 -0
- package/dist/release/github-release.js +97 -0
- package/dist/release/index.d.ts +39 -5
- package/dist/release/index.d.ts.map +1 -1
- package/dist/release/index.js +763 -130
- package/dist/release/npm-auth.d.ts +16 -0
- package/dist/release/npm-auth.d.ts.map +1 -0
- package/dist/release/npm-auth.js +39 -0
- package/dist/release/orchestration.d.ts +49 -0
- package/dist/release/orchestration.d.ts.map +1 -0
- package/dist/release/orchestration.js +113 -0
- package/dist/release/publish-plan.d.ts +17 -0
- package/dist/release/publish-plan.d.ts.map +1 -0
- package/dist/release/publish-plan.js +15 -0
- package/dist/release/retag-unpublished.d.ts +34 -0
- package/dist/release/retag-unpublished.d.ts.map +1 -0
- package/dist/release/retag-unpublished.js +77 -0
- package/managed/raw/git-format-staged.yml +54 -0
- package/managed/raw/tooling/git-hooks/commit-msg.sh +1 -1
- package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -7
- package/managed/templates/github/actions/setup-devenv/action.yml +1 -7
- package/managed/templates/github/workflows/ci.yml +3 -0
- package/package.json +37 -4
- package/src/cli.ts +193 -40
- package/src/devenv/index.test.ts +49 -0
- package/src/devenv/index.ts +38 -0
- package/src/lib/cli-package.ts +18 -0
- package/src/lib/devenv.test.ts +28 -0
- package/src/lib/devenv.ts +89 -0
- package/src/lib/run.ts +19 -0
- package/src/lib/workspace.ts +117 -7
- package/src/monorepo/__tests__/nx-version-actions.test.ts +75 -0
- package/src/monorepo/__tests__/publish-workflow.test.ts +322 -0
- package/src/monorepo/commit-msg.test.ts +45 -0
- package/src/monorepo/commit-msg.ts +107 -7
- package/src/monorepo/index.ts +181 -15
- package/src/monorepo/lockfile.ts +52 -7
- package/src/monorepo/managed-files.ts +43 -13
- package/src/monorepo/nx-sync.ts +9 -2
- package/src/monorepo/package-hygiene.test.ts +34 -0
- package/src/monorepo/package-hygiene.ts +26 -4
- package/src/monorepo/package-policy.test.ts +902 -0
- package/src/monorepo/package-policy.ts +1527 -25
- package/src/monorepo/packed-manifest.ts +67 -0
- package/src/monorepo/packed-package.ts +90 -31
- package/src/monorepo/packs/index.test.ts +189 -0
- package/src/monorepo/packs/index.ts +314 -19
- package/src/monorepo/publish-workflow.ts +422 -0
- package/src/monorepo/setup-test-tracing.test.ts +120 -0
- package/src/monorepo/tool-validation.test.ts +261 -0
- package/src/monorepo/tool-validation.ts +462 -0
- package/src/nx/index.test.ts +64 -0
- package/src/nx/index.ts +119 -0
- package/src/nx-version-actions.cts +36 -0
- package/src/release/__tests__/bootstrap-npm-packages.test.ts +127 -0
- package/src/release/__tests__/candidates.test.ts +217 -0
- package/src/release/__tests__/core-properties.test.ts +149 -0
- package/src/release/__tests__/core-scenarios.test.ts +187 -0
- package/src/release/__tests__/core.test.ts +73 -0
- package/src/release/__tests__/fixture-repo.test.ts +314 -0
- package/src/release/__tests__/github-release.test.ts +149 -0
- package/src/release/__tests__/helpers/fixture-repo.ts +114 -0
- package/src/release/__tests__/npm-auth.test.ts +120 -0
- package/src/release/__tests__/orchestration.test.ts +246 -0
- package/src/release/__tests__/publish-plan.test.ts +67 -0
- package/src/release/__tests__/retag-unpublished.test.ts +160 -0
- package/src/release/__tests__/trust-publisher.test.ts +133 -0
- package/src/release/bootstrap-npm-packages.ts +88 -0
- package/src/release/candidates.ts +225 -0
- package/src/release/core.ts +171 -0
- package/src/release/github-release.ts +134 -0
- package/src/release/index.ts +974 -138
- package/src/release/npm-auth.ts +93 -0
- package/src/release/orchestration.ts +196 -0
- package/src/release/publish-plan.ts +37 -0
- package/src/release/retag-unpublished.ts +122 -0
- package/managed/raw/.git-format-staged.yml +0 -47
- package/managed/templates/github/workflows/publish.yml +0 -136
package/dist/release/index.js
CHANGED
|
@@ -1,123 +1,215 @@
|
|
|
1
|
-
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { appendFile, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { createInterface } from 'node:readline/promises';
|
|
5
5
|
import { Writable } from 'node:stream';
|
|
6
6
|
import { $ } from 'bun';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { withDevenvEnv } from '../lib/devenv.js';
|
|
8
|
+
import { isRecord, readJsonObject, stringProperty } from '../lib/json.js';
|
|
9
|
+
import { decode, run, runResult, runStatus } from '../lib/run.js';
|
|
10
|
+
import { listReleasePackages, readPackageJson, repositoryInfo } from '../lib/workspace.js';
|
|
11
|
+
import { readPackedPackageJson, validatePackedWorkspaceDependencies } from '../monorepo/packed-manifest.js';
|
|
12
|
+
import { bootstrapNpmPackages, NPM_BOOTSTRAP_DIST_TAG, NPM_BOOTSTRAP_VERSION, } from './bootstrap-npm-packages.js';
|
|
13
|
+
import { autoReleaseCandidatePackages } from './candidates.js';
|
|
14
|
+
import { collectOwnedReleaseTagRecords, pendingReleaseTargets, releaseTag, } from './core.js';
|
|
15
|
+
import { createOrUpdateGithubRelease, renderNxProjectChangelogContents } from './github-release.js';
|
|
16
|
+
import { publishWithAuthDiagnostics } from './npm-auth.js';
|
|
17
|
+
import { completeReleaseAtHead as completeReleaseAtHeadWithShell, repairPendingTargets, runReleaseVersion, } from './orchestration.js';
|
|
18
|
+
import { retagUnpublished } from './retag-unpublished.js';
|
|
9
19
|
export async function releaseVersion(root, options) {
|
|
10
20
|
const bump = releaseBumpArg(options.bump);
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
nxArgs.push(`--projects=${projects}`, '--git-commit=true', '--git-tag=true', '--git-push=false');
|
|
28
|
-
if (options.dryRun) {
|
|
29
|
-
nxArgs.push('--dryRun');
|
|
30
|
-
}
|
|
31
|
-
await run('nx', nxArgs, root);
|
|
32
|
-
if (!options.dryRun) {
|
|
33
|
-
// Guard against future Nx/config regressions that leave release files, such
|
|
34
|
-
// as bun.lock, outside the release commit after tagging/pushing.
|
|
35
|
-
await assertCleanGitTree(root);
|
|
36
|
-
const headAfterVersioning = await gitHead(root);
|
|
37
|
-
if (headAfterVersioning === headBeforeVersioning) {
|
|
38
|
-
console.log('Nx did not create a release commit; skipping git push.');
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
await pushReleaseCommit(root);
|
|
42
|
-
}
|
|
21
|
+
const packages = releasePackages(root);
|
|
22
|
+
const result = await runReleaseVersion({
|
|
23
|
+
releasePackagesAtHead: () => releasePackagesAtHead(root, packages),
|
|
24
|
+
releaseVersionPackages: (releaseBump) => releaseVersionPackages(root, packages, releaseBump),
|
|
25
|
+
ensureLocalReleaseTags: (releasePackages) => ensureLocalReleaseTags(root, releasePackages),
|
|
26
|
+
gitHead: () => gitHead(root),
|
|
27
|
+
runNxReleaseVersion: (releasePackages, releaseBump, dryRun) => runNxReleaseVersion(root, releasePackageProjects(releasePackages), releaseBump, dryRun),
|
|
28
|
+
assertCleanGitTree: () => assertCleanGitTree(root),
|
|
29
|
+
}, { bump, dryRun: options.dryRun === true });
|
|
30
|
+
if (result.status === 'already-release-target') {
|
|
31
|
+
console.log('HEAD is already a release target; publish will complete any missing durable state.');
|
|
32
|
+
}
|
|
33
|
+
else if (result.status === 'no-release-needed') {
|
|
34
|
+
console.log('Nx did not create a release commit; no release needed.');
|
|
35
|
+
}
|
|
36
|
+
await writeReleaseGithubOutput(options.githubOutput, result.packages, result.mode);
|
|
43
37
|
}
|
|
44
38
|
export async function releasePublish(root, options) {
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const tags = options.tags ? options.tags.split(/\s+/).filter(Boolean) : await gitTagsAtHead(root);
|
|
64
|
-
if (tags.length === 0) {
|
|
65
|
-
throw new Error('No release tags found. Pass --tags or run from a tagged release commit.');
|
|
66
|
-
}
|
|
67
|
-
const latestFlag = npmTag === 'latest' ? 'true' : 'false';
|
|
68
|
-
for (const tag of tags) {
|
|
69
|
-
const exists = (await runStatus('gh', ['release', 'view', tag], root, true)) === 0;
|
|
70
|
-
if (exists) {
|
|
71
|
-
await run('gh', ['release', 'edit', tag, '--title', tag, `--latest=${latestFlag}`], root);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
await run('gh', ['release', 'create', tag, '--title', tag, '--generate-notes', `--latest=${latestFlag}`], root);
|
|
39
|
+
const bump = releaseBumpArg(options.bump);
|
|
40
|
+
const packages = await releasePackagesAtHead(root, releasePackages(root));
|
|
41
|
+
if (packages.length === 0) {
|
|
42
|
+
if (bump === 'auto') {
|
|
43
|
+
console.log('No release tags found at HEAD; no release to publish.');
|
|
44
|
+
const summary = {
|
|
45
|
+
sha: await gitHead(root),
|
|
46
|
+
dryRun: options.dryRun === true,
|
|
47
|
+
packages,
|
|
48
|
+
pushed: false,
|
|
49
|
+
published: [],
|
|
50
|
+
alreadyPublished: [],
|
|
51
|
+
githubReleases: [],
|
|
52
|
+
rerunRequired: false,
|
|
53
|
+
noRelease: true,
|
|
54
|
+
};
|
|
55
|
+
await writeReleaseSummary(summary);
|
|
56
|
+
return;
|
|
75
57
|
}
|
|
58
|
+
throw new Error('No release tags found at HEAD for current package versions. Run smoo release version first.');
|
|
76
59
|
}
|
|
60
|
+
const summary = await completeReleaseAtHeadWithShell(releaseCompletionShell(root), packages, options.dryRun === true, await newerCommitsRemain(root));
|
|
61
|
+
await writeReleaseSummary(summary);
|
|
62
|
+
}
|
|
63
|
+
export async function releaseRepairPending(root, options) {
|
|
64
|
+
const branch = await releaseBranch(root);
|
|
65
|
+
const remote = await releaseRemote(root, branch);
|
|
66
|
+
console.log(`Repair pending releases: fetching ${remote}/${branch} and tags.`);
|
|
67
|
+
await fetchReleaseRefs(root, remote, branch);
|
|
68
|
+
const remoteRef = `${remote}/${branch}`;
|
|
69
|
+
const restoreRef = (await gitRefExists(root, remoteRef)) ? remoteRef : await gitHead(root);
|
|
70
|
+
console.log(`Repair pending releases: planning from ${restoreRef}.`);
|
|
71
|
+
const targets = await listPendingReleaseTargets(root, restoreRef);
|
|
72
|
+
console.log(targets.length === 0
|
|
73
|
+
? 'Repair pending releases: no pending durable state repairs found.'
|
|
74
|
+
: `Repair pending releases: ${targets.length} release target${targets.length === 1 ? '' : 's'} need repair.`);
|
|
75
|
+
const summaries = await repairPendingTargets(releaseRepairShell(root), targets, restoreRef, options.dryRun === true);
|
|
76
|
+
await writeRepairSummary(summaries, options.dryRun === true);
|
|
77
77
|
}
|
|
78
78
|
export async function releaseTrustPublisher(root, options) {
|
|
79
79
|
const repository = githubRepositoryFromRootPackage(root);
|
|
80
80
|
const workflow = 'publish.yml';
|
|
81
|
-
|
|
81
|
+
await configureTrustedPublishers({
|
|
82
|
+
repository,
|
|
83
|
+
workflow,
|
|
84
|
+
listReleasePackages: () => listReleasePackages(root),
|
|
85
|
+
packageExists: (name) => npmPackageExists(root, name),
|
|
86
|
+
bootstrapNpmPackages: (bootstrapOptions) => bootstrapNpmPackages({
|
|
87
|
+
listReleasePackages: () => listReleasePackages(root),
|
|
88
|
+
packageExists: (name) => npmPackageExists(root, name),
|
|
89
|
+
login: () => runLatestNpm(root, ['login', '--auth-type=web']),
|
|
90
|
+
publishPlaceholder: (pkg, env) => publishPlaceholderPackage(root, pkg, env),
|
|
91
|
+
promptOtp: (packageName) => promptForNpmOtp(packageName),
|
|
92
|
+
log: (message) => console.log(message),
|
|
93
|
+
}, bootstrapOptions),
|
|
94
|
+
login: () => runLatestNpm(root, ['login', '--auth-type=web']),
|
|
95
|
+
trustPublisher: (pkg, dryRun, env) => {
|
|
96
|
+
const args = ['trust', 'github', pkg.name, '--file', workflow, '--repo', repository, '--yes'];
|
|
97
|
+
if (dryRun) {
|
|
98
|
+
args.push('--dry-run');
|
|
99
|
+
}
|
|
100
|
+
return runLatestNpmTrust(root, args, env);
|
|
101
|
+
},
|
|
102
|
+
promptOtp: (packageName) => promptForNpmOtp(packageName),
|
|
103
|
+
log: (message) => console.log(message),
|
|
104
|
+
error: (message) => console.error(message),
|
|
105
|
+
}, options);
|
|
106
|
+
}
|
|
107
|
+
export async function configureTrustedPublishers(shell, options) {
|
|
108
|
+
const packages = shell.listReleasePackages();
|
|
82
109
|
if (packages.length === 0) {
|
|
83
|
-
throw new Error('No
|
|
110
|
+
throw new Error('No owned release packages found.');
|
|
111
|
+
}
|
|
112
|
+
let bootstrapLoggedIn = false;
|
|
113
|
+
if (options.bootstrap) {
|
|
114
|
+
const bootstrapped = await shell.bootstrapNpmPackages({
|
|
115
|
+
dryRun: options.dryRun === true,
|
|
116
|
+
skipLogin: options.skipLogin === true,
|
|
117
|
+
otp: options.bootstrapOtp,
|
|
118
|
+
packages: [],
|
|
119
|
+
});
|
|
120
|
+
bootstrapLoggedIn = bootstrapped.length > 0 && !options.dryRun && !options.skipLogin;
|
|
84
121
|
}
|
|
85
122
|
if (!options.dryRun) {
|
|
86
|
-
const packageStates = await Promise.all(packages.map(async (pkg) => ((await
|
|
123
|
+
const packageStates = await Promise.all(packages.map(async (pkg) => ((await shell.packageExists(pkg.name)) ? null : pkg.name)));
|
|
87
124
|
const missingPackages = packageStates.filter((name) => name !== null);
|
|
88
125
|
if (missingPackages.length > 0) {
|
|
89
126
|
throw new Error('npm trusted publishing can only be configured after packages exist on the registry. ' +
|
|
90
|
-
'
|
|
127
|
+
'Run smoo release trust-publisher --bootstrap locally. ' +
|
|
91
128
|
`Missing packages: ${missingPackages.join(', ')}`);
|
|
92
129
|
}
|
|
93
130
|
}
|
|
94
|
-
if (!options.dryRun && !options.skipLogin) {
|
|
95
|
-
await
|
|
131
|
+
if (!options.dryRun && !options.skipLogin && !bootstrapLoggedIn) {
|
|
132
|
+
await shell.login();
|
|
96
133
|
}
|
|
134
|
+
const failedPackages = [];
|
|
97
135
|
for (const pkg of packages) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
136
|
+
shell.log(`${pkg.name}: trusting GitHub Actions ${shell.repository}/${shell.workflow}`);
|
|
137
|
+
while (true) {
|
|
138
|
+
const otp = options.dryRun ? undefined : (options.otp ?? (await shell.promptOtp(pkg.name)));
|
|
139
|
+
try {
|
|
140
|
+
const result = await shell.trustPublisher(pkg, options.dryRun === true, otp ? { NPM_CONFIG_OTP: otp } : undefined);
|
|
141
|
+
if (result === 'already-configured') {
|
|
142
|
+
shell.log(`${pkg.name}: npm trusted publisher is already configured; skipping.`);
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
shell.error(`${pkg.name}: npm trusted publisher setup failed.`);
|
|
148
|
+
shell.error(error instanceof Error ? error.message : String(error));
|
|
149
|
+
if (!options.dryRun) {
|
|
150
|
+
shell.error('npm OTP codes are single-use. Generate a fresh OTP before retrying this package.');
|
|
151
|
+
}
|
|
152
|
+
if (options.otp || options.dryRun) {
|
|
153
|
+
failedPackages.push(pkg.name);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
shell.error('Retrying this package. Press Ctrl-C to stop.');
|
|
157
|
+
}
|
|
102
158
|
}
|
|
103
|
-
const otp = options.dryRun ? undefined : (options.otp ?? (await promptForNpmOtp(pkg.name)));
|
|
104
|
-
await runLatestNpm(root, args, otp ? { NPM_CONFIG_OTP: otp } : undefined);
|
|
105
159
|
}
|
|
160
|
+
if (failedPackages.length > 0) {
|
|
161
|
+
shell.error(`Trusted publishing was not configured for: ${failedPackages.join(', ')}`);
|
|
162
|
+
if (options.otp) {
|
|
163
|
+
shell.error('Rerun smoo release trust-publisher without --otp to enter a fresh OTP for each failed package.');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export async function releaseBootstrapNpmPackages(root, options) {
|
|
168
|
+
await bootstrapNpmPackages({
|
|
169
|
+
listReleasePackages: () => listReleasePackages(root),
|
|
170
|
+
packageExists: (name) => npmPackageExists(root, name),
|
|
171
|
+
login: () => runLatestNpm(root, ['login', '--auth-type=web']),
|
|
172
|
+
publishPlaceholder: (pkg, env) => publishPlaceholderPackage(root, pkg, env),
|
|
173
|
+
promptOtp: (packageName) => promptForNpmOtp(packageName),
|
|
174
|
+
log: (message) => console.log(message),
|
|
175
|
+
}, {
|
|
176
|
+
dryRun: options.dryRun === true,
|
|
177
|
+
skipLogin: options.skipLogin === true,
|
|
178
|
+
otp: options.otp,
|
|
179
|
+
packages: options.packages ?? [],
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
export async function releaseRetagUnpublished(root, options) {
|
|
183
|
+
const toRef = options.to ?? 'HEAD';
|
|
184
|
+
const dispatch = options.dispatch === true;
|
|
185
|
+
const push = options.push === true || dispatch;
|
|
186
|
+
const branch = options.branch ?? (await releaseBranch(root));
|
|
187
|
+
const remote = options.remote ?? (push ? await releaseRemote(root, branch) : 'origin');
|
|
188
|
+
await retagUnpublished(releaseRetagShell(root, remote), {
|
|
189
|
+
tags: options.tags,
|
|
190
|
+
toRef,
|
|
191
|
+
push,
|
|
192
|
+
dispatch,
|
|
193
|
+
dryRun: options.dryRun === true,
|
|
194
|
+
branch,
|
|
195
|
+
workflow: 'publish.yml',
|
|
196
|
+
});
|
|
106
197
|
}
|
|
107
198
|
export async function printReleaseState(root) {
|
|
108
199
|
console.log(JSON.stringify(await getReleaseState(root), null, 2));
|
|
109
200
|
}
|
|
110
201
|
async function getReleaseState(root) {
|
|
111
|
-
|
|
202
|
+
return getReleaseStateForPackages(root, listReleasePackages(root));
|
|
203
|
+
}
|
|
204
|
+
async function getReleaseStateForPackages(root, packages) {
|
|
112
205
|
const states = await Promise.all(packages.map(async (pkg) => {
|
|
113
|
-
const published = await npmVersionExists(pkg.name, pkg.version);
|
|
206
|
+
const published = await npmVersionExists(root, pkg.name, pkg.version);
|
|
114
207
|
return { name: pkg.name, version: pkg.version, published };
|
|
115
208
|
}));
|
|
116
209
|
return { packages: states, allPublished: states.every((state) => state.published) };
|
|
117
210
|
}
|
|
118
|
-
async function listUnpublishedPackages(root) {
|
|
119
|
-
const
|
|
120
|
-
const states = await Promise.all(packages.map(async (pkg) => ({ pkg, published: await npmVersionExists(pkg.name, pkg.version) })));
|
|
211
|
+
async function listUnpublishedPackages(root, packages) {
|
|
212
|
+
const states = await Promise.all(packages.map(async (pkg) => ({ pkg, published: await npmVersionExists(root, pkg.name, pkg.version) })));
|
|
121
213
|
return states.filter((state) => !state.published).map((state) => state.pkg);
|
|
122
214
|
}
|
|
123
215
|
async function publishPackedPackage(root, pkg, tag, dryRun) {
|
|
@@ -126,16 +218,50 @@ async function publishPackedPackage(root, pkg, tag, dryRun) {
|
|
|
126
218
|
try {
|
|
127
219
|
console.log(`${pkg.name}@${pkg.version}: packing with bun pm pack`);
|
|
128
220
|
await run('bun', ['pm', 'pack', '--filename', tarball, '--ignore-scripts', '--quiet'], join(root, pkg.path));
|
|
129
|
-
await
|
|
130
|
-
// npm CLI owns authentication here: trusted publishing OIDC when configured
|
|
131
|
-
// or the temporary NODE_AUTH_TOKEN bootstrap path below before trust exists.
|
|
221
|
+
await assertPackedWorkspaceDependencies(root, tarball, pkg);
|
|
222
|
+
// npm CLI owns authentication here: trusted publishing OIDC when configured.
|
|
132
223
|
// Bun still produces the tarball so workspace:* dependencies are resolved the
|
|
133
224
|
// same way smoo validates packed packages before release.
|
|
134
225
|
const args = ['publish', tarball, '--access', 'public', '--tag', tag, '--provenance'];
|
|
135
226
|
if (dryRun) {
|
|
136
227
|
args.push('--dry-run');
|
|
137
228
|
}
|
|
138
|
-
await
|
|
229
|
+
await publishWithAuthDiagnostics(pkg, {
|
|
230
|
+
publish: () => runLatestNpmPublish(root, args),
|
|
231
|
+
versionExists: () => npmVersionExists(root, pkg.name, pkg.version),
|
|
232
|
+
log: (message) => console.log(message),
|
|
233
|
+
error: (message) => console.error(message),
|
|
234
|
+
appendSummary: async (markdown) => {
|
|
235
|
+
const summaryPath = process.env.GITHUB_STEP_SUMMARY;
|
|
236
|
+
if (summaryPath) {
|
|
237
|
+
await appendFile(summaryPath, `${markdown}\n\n`);
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
}, {
|
|
241
|
+
tokenPresent: npmAuthTokenPresent(),
|
|
242
|
+
repository: githubRepositoryFromRootPackage(root),
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
finally {
|
|
246
|
+
await rm(tempDir, { recursive: true, force: true });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function npmAuthTokenPresent() {
|
|
250
|
+
return Boolean(process.env.NODE_AUTH_TOKEN || process.env.NPM_TOKEN || process.env.NPM_CONFIG_USERCONFIG);
|
|
251
|
+
}
|
|
252
|
+
async function publishPlaceholderPackage(root, pkg, env) {
|
|
253
|
+
const tempDir = await mkdtemp(join(tmpdir(), 'smoo-npm-bootstrap-'));
|
|
254
|
+
try {
|
|
255
|
+
await writeFile(join(tempDir, 'package.json'), `${JSON.stringify({
|
|
256
|
+
name: pkg.name,
|
|
257
|
+
version: NPM_BOOTSTRAP_VERSION,
|
|
258
|
+
description: `Bootstrap placeholder for ${pkg.name}. Real releases are published by SmoothBricks CI.`,
|
|
259
|
+
license: stringProperty(pkg.json, 'license') ?? 'UNLICENSED',
|
|
260
|
+
repository: pkg.json.repository,
|
|
261
|
+
publishConfig: { access: 'public' },
|
|
262
|
+
}, null, 2)}\n`);
|
|
263
|
+
await writeFile(join(tempDir, 'README.md'), `# ${pkg.name}\n\nThis is a bootstrap placeholder. Real package versions are published by SmoothBricks release automation.\n`);
|
|
264
|
+
await runLatestNpm(root, ['publish', tempDir, '--access', 'public', '--tag', NPM_BOOTSTRAP_DIST_TAG], env);
|
|
139
265
|
}
|
|
140
266
|
finally {
|
|
141
267
|
await rm(tempDir, { recursive: true, force: true });
|
|
@@ -144,26 +270,108 @@ async function publishPackedPackage(root, pkg, tag, dryRun) {
|
|
|
144
270
|
function safeTarballPrefix(name) {
|
|
145
271
|
return name.replace(/^@/, '').replace(/[^a-zA-Z0-9._-]+/g, '-');
|
|
146
272
|
}
|
|
147
|
-
async function
|
|
148
|
-
const
|
|
273
|
+
async function assertPackedWorkspaceDependencies(root, tarball, pkg) {
|
|
274
|
+
const manifest = await readPackedPackageJson(root, tarball, pkg.name);
|
|
275
|
+
const failures = validatePackedWorkspaceDependencies(root, pkg, manifest);
|
|
276
|
+
if (failures.length > 0) {
|
|
277
|
+
throw new Error(failures.join('\n'));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function releasePackages(root) {
|
|
281
|
+
const packages = listReleasePackages(root);
|
|
282
|
+
if (packages.length === 0) {
|
|
283
|
+
throw new Error('No owned release packages found.');
|
|
284
|
+
}
|
|
285
|
+
return packages;
|
|
286
|
+
}
|
|
287
|
+
function releasePackageProjects(packages) {
|
|
288
|
+
return packages.map((pkg) => pkg.projectName).join(',');
|
|
289
|
+
}
|
|
290
|
+
async function releaseVersionPackages(root, packages, bump) {
|
|
291
|
+
if (bump !== 'auto') {
|
|
292
|
+
return packages;
|
|
293
|
+
}
|
|
294
|
+
return autoReleaseCandidatePackages({
|
|
295
|
+
gitRefExists: (ref) => gitRefExists(root, ref),
|
|
296
|
+
packageChangedFilesSince: (ref, packagePath) => packageChangedFilesSince(root, ref, packagePath),
|
|
297
|
+
packageJsonAtRef: (ref, packagePath) => packageJsonAtRef(root, ref, packagePath),
|
|
298
|
+
currentPackageJson: (packagePath) => currentPackageJson(root, packagePath),
|
|
299
|
+
packageBuildInputPatterns: (projectName, packagePath) => packageBuildInputPatterns(root, projectName, packagePath),
|
|
300
|
+
packageHasHistory: (packagePath) => packageHasHistory(root, packagePath),
|
|
301
|
+
}, packages);
|
|
302
|
+
}
|
|
303
|
+
async function runNxReleaseVersion(root, projects, bump, dryRun) {
|
|
304
|
+
// Nx owns local release mutation: package versions, bun.lock updates, the
|
|
305
|
+
// release commit, and annotated tags. smoo owns remote publication after the
|
|
306
|
+
// workflow validates the exact release commit Nx produced.
|
|
307
|
+
const nxArgs = ['release', 'version'];
|
|
308
|
+
if (bump !== 'auto') {
|
|
309
|
+
nxArgs.push(bump);
|
|
310
|
+
}
|
|
311
|
+
nxArgs.push(`--projects=${projects}`, '--git-commit=true', '--git-tag=true', '--git-push=false');
|
|
312
|
+
if (dryRun) {
|
|
313
|
+
nxArgs.push('--dry-run');
|
|
314
|
+
}
|
|
315
|
+
await run('nx', nxArgs, root);
|
|
316
|
+
}
|
|
317
|
+
async function releasePackagesAtHead(root, packages) {
|
|
318
|
+
return releasePackagesAtRef(root, packages, 'HEAD');
|
|
319
|
+
}
|
|
320
|
+
async function writeReleaseGithubOutput(outputPath, packages, mode) {
|
|
321
|
+
if (!outputPath) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
await appendFile(outputPath, `mode=${mode}\nprojects=${releasePackageProjects(packages)}\n`);
|
|
325
|
+
}
|
|
326
|
+
async function releasePackagesAtRef(root, packages, ref) {
|
|
327
|
+
const packagesAtRef = await Promise.all(packages.map(async (pkg) => releasePackageAtRef(root, pkg, ref)));
|
|
328
|
+
const presentPackages = packagesAtRef.filter((pkg) => pkg !== null);
|
|
329
|
+
const tags = new Set(await gitTagsAtRef(root, ref));
|
|
330
|
+
const taggedPackages = presentPackages.filter((pkg) => tags.has(releaseTag(pkg)));
|
|
331
|
+
if (taggedPackages.length > 0) {
|
|
332
|
+
return taggedPackages;
|
|
333
|
+
}
|
|
334
|
+
if (!(await isNxReleaseCommit(root, ref))) {
|
|
335
|
+
return [];
|
|
336
|
+
}
|
|
337
|
+
return releasePackagesChangedAtRef(root, presentPackages, ref);
|
|
338
|
+
}
|
|
339
|
+
async function releasePackageAtRef(root, pkg, ref) {
|
|
340
|
+
const version = await packageVersionAtRef(root, pkg.path, ref);
|
|
341
|
+
return version ? { ...pkg, version } : null;
|
|
342
|
+
}
|
|
343
|
+
async function packageVersionAtRef(root, packagePath, ref) {
|
|
344
|
+
const result = await $ `git show ${`${ref}:${packagePath}/package.json`}`.cwd(root).quiet().nothrow();
|
|
149
345
|
if (result.exitCode !== 0) {
|
|
150
|
-
|
|
346
|
+
return null;
|
|
151
347
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
348
|
+
try {
|
|
349
|
+
const parsed = JSON.parse(decode(result.stdout));
|
|
350
|
+
return isRecord(parsed) ? stringProperty(parsed, 'version') : null;
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
return null;
|
|
155
354
|
}
|
|
156
355
|
}
|
|
157
|
-
async function
|
|
158
|
-
const result = await $ `
|
|
159
|
-
return result.exitCode === 0 && decode(result.stdout).trim() ===
|
|
356
|
+
async function isNxReleaseCommit(root, ref) {
|
|
357
|
+
const result = await $ `git show -s --format=%s ${ref}`.cwd(root).quiet().nothrow();
|
|
358
|
+
return result.exitCode === 0 && decode(result.stdout).trim() === 'chore(release): publish';
|
|
160
359
|
}
|
|
161
|
-
async function
|
|
162
|
-
|
|
163
|
-
|
|
360
|
+
async function releasePackagesChangedAtRef(root, packages, ref) {
|
|
361
|
+
if (!(await gitRefExists(root, `${ref}^`))) {
|
|
362
|
+
return packages;
|
|
363
|
+
}
|
|
364
|
+
const changed = [];
|
|
365
|
+
for (const pkg of packages) {
|
|
366
|
+
const previousVersion = await packageVersionAtRef(root, pkg.path, `${ref}^`);
|
|
367
|
+
if (previousVersion !== pkg.version) {
|
|
368
|
+
changed.push(pkg);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return changed;
|
|
164
372
|
}
|
|
165
|
-
async function
|
|
166
|
-
const result = await $ `git tag --points-at
|
|
373
|
+
async function gitTagsAtRef(root, ref) {
|
|
374
|
+
const result = await $ `git tag --points-at ${ref}`.cwd(root).quiet().nothrow();
|
|
167
375
|
if (result.exitCode !== 0) {
|
|
168
376
|
return [];
|
|
169
377
|
}
|
|
@@ -172,6 +380,447 @@ async function gitTagsAtHead(root) {
|
|
|
172
380
|
.map((tag) => tag.trim())
|
|
173
381
|
.filter(Boolean);
|
|
174
382
|
}
|
|
383
|
+
async function previousReleaseTag(root, pkg, currentTag) {
|
|
384
|
+
const result = await $ `git tag --list ${`${pkg.name}@*`} --sort=-v:refname --merged ${currentTag}`
|
|
385
|
+
.cwd(root)
|
|
386
|
+
.quiet()
|
|
387
|
+
.nothrow();
|
|
388
|
+
if (result.exitCode !== 0) {
|
|
389
|
+
throw new Error(`Unable to list release tags for ${pkg.name}.`);
|
|
390
|
+
}
|
|
391
|
+
return (decode(result.stdout)
|
|
392
|
+
.split('\n')
|
|
393
|
+
.map((tag) => tag.trim())
|
|
394
|
+
.find((tag) => tag && tag !== currentTag) ?? null);
|
|
395
|
+
}
|
|
396
|
+
async function ensureLocalReleaseTags(root, packages) {
|
|
397
|
+
for (const pkg of packages) {
|
|
398
|
+
const tag = releaseTag(pkg);
|
|
399
|
+
if (await gitRefExists(root, `refs/tags/${tag}`)) {
|
|
400
|
+
if (!(await gitTagPointsAt(root, tag, 'HEAD'))) {
|
|
401
|
+
throw new Error(`Release tag ${tag} exists but does not point at HEAD.`);
|
|
402
|
+
}
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
await run('git', ['tag', '-a', tag, '-m', tag, 'HEAD'], root);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
async function pushReleaseRefs(root, packages) {
|
|
409
|
+
const branch = await releaseBranch(root);
|
|
410
|
+
const remote = await releaseRemote(root, branch);
|
|
411
|
+
await fetchReleaseRefs(root, remote, branch);
|
|
412
|
+
await ensureLocalReleaseTags(root, packages);
|
|
413
|
+
const refspecs = [];
|
|
414
|
+
const remoteRef = `${remote}/${branch}`;
|
|
415
|
+
const head = await gitHead(root);
|
|
416
|
+
if (!(await gitRefExists(root, remoteRef)) || !(await gitIsAncestor(root, head, remoteRef))) {
|
|
417
|
+
refspecs.push(`HEAD:refs/heads/${branch}`);
|
|
418
|
+
}
|
|
419
|
+
for (const pkg of packages) {
|
|
420
|
+
const tag = releaseTag(pkg);
|
|
421
|
+
if (!(await remoteReleaseTagExists(root, remote, tag))) {
|
|
422
|
+
refspecs.push(`refs/tags/${tag}:refs/tags/${tag}`);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (refspecs.length === 0) {
|
|
426
|
+
console.log('Release branch and tags are already present on the remote.');
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
await run('git', ['push', '--atomic', remote, ...refspecs], root);
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
function releaseCompletionShell(root) {
|
|
433
|
+
return {
|
|
434
|
+
gitHead: () => gitHead(root),
|
|
435
|
+
pushReleaseRefs: (packages) => pushReleaseRefs(root, packages),
|
|
436
|
+
listNpmMissingPackages: (packages) => listUnpublishedPackages(root, packages),
|
|
437
|
+
buildReleaseCandidate: (packages) => buildReleaseCandidate(root, packages),
|
|
438
|
+
publishPackage: async (pkg, distTag, dryRun) => {
|
|
439
|
+
const packageExists = dryRun ? true : await npmPackageExists(root, pkg.name);
|
|
440
|
+
if (!packageExists) {
|
|
441
|
+
throw new Error(missingNpmPackagePublishGuidance(pkg));
|
|
442
|
+
}
|
|
443
|
+
await publishPackedPackage(root, pkg, distTag, dryRun);
|
|
444
|
+
},
|
|
445
|
+
listGithubMissingPackages: (packages) => listMissingGithubReleasePackages(root, packages),
|
|
446
|
+
createGithubRelease: (pkg, dryRun) => createGithubRelease(root, pkg, dryRun),
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
function releaseRepairShell(root) {
|
|
450
|
+
return {
|
|
451
|
+
...releaseCompletionShell(root),
|
|
452
|
+
checkout: (ref) => run('git', ['switch', '--detach', ref], root),
|
|
453
|
+
withDevenvEnv: (runWithEnv) => withDevenvEnv(root, runWithEnv),
|
|
454
|
+
beforeRepairTarget: (target) => {
|
|
455
|
+
console.log(`::group::Repair pending release ${target.sha.slice(0, 12)} (${packageSummary(target.packages)})`);
|
|
456
|
+
},
|
|
457
|
+
afterRepairTarget: () => {
|
|
458
|
+
console.log('::endgroup::');
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
function releaseRetagShell(root, remote) {
|
|
463
|
+
return {
|
|
464
|
+
listReleasePackages: () => releasePackages(root),
|
|
465
|
+
resolveRef: (ref) => gitSha(root, ref),
|
|
466
|
+
resolveDispatchRef: (branch) => remoteBranchSha(root, remote, branch),
|
|
467
|
+
packageVersionAtRef: (packagePath, ref) => packageVersionAtRef(root, packagePath, ref),
|
|
468
|
+
npmVersionExists: (name, version) => npmVersionExists(root, name, version),
|
|
469
|
+
githubReleaseExists: (tag) => githubReleaseExists(root, tag),
|
|
470
|
+
remoteTagObject: (tag) => remoteReleaseTagObject(root, remote, tag),
|
|
471
|
+
createOrMoveTag: (tag, ref) => run('git', ['tag', '-fa', tag, '-m', tag, ref], root),
|
|
472
|
+
pushTags: (updates) => pushRetaggedReleaseTags(root, remote, updates),
|
|
473
|
+
dispatchPublishWorkflow: (workflow, branch) => run('gh', ['workflow', 'run', workflow, '--ref', branch, '-f', 'bump=auto', '-f', 'dry_run=false'], root),
|
|
474
|
+
log: (message) => console.log(message),
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
async function listPendingReleaseTargets(root, ref) {
|
|
478
|
+
const head = await gitHead(root);
|
|
479
|
+
return pendingReleaseTargets(await listOwnedReleaseTagRecords(root, ref), head);
|
|
480
|
+
}
|
|
481
|
+
async function listOwnedReleaseTagRecords(root, ref) {
|
|
482
|
+
const tags = await gitReleaseTagsByCreatorDate(root);
|
|
483
|
+
console.log(`Repair pending releases: scanning ${tags.length} local tag${tags.length === 1 ? '' : 's'}.`);
|
|
484
|
+
return collectOwnedReleaseTagRecords(releasePackages(root), ref, {
|
|
485
|
+
listReleaseTagsByCreatorDate: async () => tags,
|
|
486
|
+
isAncestor: (ancestor, descendant) => gitIsAncestor(root, ancestor, descendant),
|
|
487
|
+
packageVersionAtRef: (packagePath, tagRef) => packageVersionAtRef(root, packagePath, tagRef),
|
|
488
|
+
durableTagState: (pkg, tag) => durableReleaseTagState(root, pkg, tag),
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
async function durableReleaseTagState(root, pkg, tag) {
|
|
492
|
+
const packageVersion = `${pkg.name}@${pkg.version}`;
|
|
493
|
+
const start = Date.now();
|
|
494
|
+
console.log(`${packageVersion}: checking durable state (npm + GitHub Release ${tag}).`);
|
|
495
|
+
const [npmPublished, githubReleasePresent] = await Promise.all([
|
|
496
|
+
npmVersionExists(root, pkg.name, pkg.version),
|
|
497
|
+
githubReleaseExists(root, tag),
|
|
498
|
+
]);
|
|
499
|
+
console.log(`${packageVersion}: durable state npm=${yesNo(npmPublished)} github=${yesNo(githubReleasePresent)} (${Date.now() - start}ms).`);
|
|
500
|
+
return { npmPublished, githubReleaseExists: githubReleasePresent };
|
|
501
|
+
}
|
|
502
|
+
async function gitReleaseTagsByCreatorDate(root) {
|
|
503
|
+
const result = await $ `git for-each-ref --sort=-creatordate --format=${'%(refname:short)%09%(creatordate:unix)%09%(*objectname)%09%(objectname)'} refs/tags`
|
|
504
|
+
.cwd(root)
|
|
505
|
+
.quiet()
|
|
506
|
+
.nothrow();
|
|
507
|
+
if (result.exitCode !== 0) {
|
|
508
|
+
throw new Error('Unable to list release tags by creator date.');
|
|
509
|
+
}
|
|
510
|
+
return decode(result.stdout)
|
|
511
|
+
.split('\n')
|
|
512
|
+
.map((line) => line.trim())
|
|
513
|
+
.filter(Boolean)
|
|
514
|
+
.map((line) => {
|
|
515
|
+
const [name, timestampText, peeledSha, objectSha] = line.split('\t');
|
|
516
|
+
const timestamp = Number(timestampText);
|
|
517
|
+
const sha = peeledSha || objectSha;
|
|
518
|
+
if (!name || !sha || !Number.isSafeInteger(timestamp)) {
|
|
519
|
+
throw new Error(`Unable to parse release tag ref: ${line}`);
|
|
520
|
+
}
|
|
521
|
+
return { name, sha, timestamp };
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
async function buildReleaseCandidate(root, packages) {
|
|
525
|
+
await run('nx', ['run-many', '-t', 'build', `--projects=${releasePackageProjects(packages)}`], root);
|
|
526
|
+
}
|
|
527
|
+
async function listMissingGithubReleasePackages(root, packages) {
|
|
528
|
+
return (await Promise.all(packages.map(async (pkg) => ((await githubReleaseExists(root, releaseTag(pkg))) ? null : pkg)))).filter((pkg) => pkg !== null);
|
|
529
|
+
}
|
|
530
|
+
async function createGithubRelease(root, pkg, dryRun) {
|
|
531
|
+
const currentTag = releaseTag(pkg);
|
|
532
|
+
console.log(`${pkg.name}@${pkg.version}: rendering GitHub Release notes for ${currentTag}.`);
|
|
533
|
+
console.log(`GitHub release auth: ${envPresence('GH_TOKEN')}, ${envPresence('GITHUB_TOKEN')}.`);
|
|
534
|
+
if (!dryRun) {
|
|
535
|
+
await assertRemoteTagExists(root, currentTag);
|
|
536
|
+
}
|
|
537
|
+
const previousTag = await previousReleaseTag(root, pkg, currentTag);
|
|
538
|
+
if (dryRun) {
|
|
539
|
+
await renderNxProjectChangelogContents({ root, pkg, previousTag, dryRun });
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
const contents = await renderNxProjectChangelogContents({ root, pkg, previousTag, dryRun });
|
|
543
|
+
await createOrUpdateGithubRelease(pkg, contents, {
|
|
544
|
+
githubReleaseExists: (tag) => githubReleaseExists(root, tag),
|
|
545
|
+
runGhRelease: (args) => run('gh', args, root),
|
|
546
|
+
log: (message) => console.log(message),
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
function envPresence(name) {
|
|
550
|
+
return `${name}=${process.env[name] ? 'present' : 'missing'}`;
|
|
551
|
+
}
|
|
552
|
+
function yesNo(value) {
|
|
553
|
+
return value ? 'yes' : 'no';
|
|
554
|
+
}
|
|
555
|
+
async function newerCommitsRemain(root) {
|
|
556
|
+
const branch = await releaseBranch(root);
|
|
557
|
+
const remote = await releaseRemote(root, branch);
|
|
558
|
+
await fetchReleaseRefs(root, remote, branch);
|
|
559
|
+
const remoteRef = `${remote}/${branch}`;
|
|
560
|
+
if (!(await gitRefExists(root, remoteRef))) {
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
563
|
+
const head = await gitHead(root);
|
|
564
|
+
return head !== (await gitSha(root, remoteRef)) && (await gitIsAncestor(root, head, remoteRef));
|
|
565
|
+
}
|
|
566
|
+
async function writeReleaseSummary(summary) {
|
|
567
|
+
const shortSha = summary.sha.slice(0, 12);
|
|
568
|
+
const lines = [
|
|
569
|
+
'## Release Summary',
|
|
570
|
+
'',
|
|
571
|
+
`- Commit: \`${shortSha}\``,
|
|
572
|
+
`- Mode: ${summary.dryRun ? 'dry run' : 'release'}`,
|
|
573
|
+
];
|
|
574
|
+
if (summary.noRelease) {
|
|
575
|
+
lines.push('- Result: no release tags found at HEAD');
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
lines.push(`- Packages: ${packageSummary(summary.packages)}`);
|
|
579
|
+
lines.push(`- Git refs pushed: ${summary.pushed ? 'yes' : 'already current'}`);
|
|
580
|
+
lines.push(`- npm published: ${packageSummary(summary.published)}`);
|
|
581
|
+
lines.push(`- npm already published: ${packageSummary(summary.alreadyPublished)}`);
|
|
582
|
+
lines.push(`- GitHub Releases created/updated: ${packageSummary(summary.githubReleases)}`);
|
|
583
|
+
}
|
|
584
|
+
if (summary.rerunRequired) {
|
|
585
|
+
const message = 'A previous incomplete release was repaired; newer commits remain. Run Publish again.';
|
|
586
|
+
console.log(`::warning::${message}`);
|
|
587
|
+
lines.push(`- Warning: ${message}`);
|
|
588
|
+
}
|
|
589
|
+
const text = `${lines.join('\n')}\n`;
|
|
590
|
+
console.log(text.trimEnd());
|
|
591
|
+
const summaryPath = process.env.GITHUB_STEP_SUMMARY;
|
|
592
|
+
if (summaryPath) {
|
|
593
|
+
await appendFile(summaryPath, `${text}\n`);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
async function writeRepairSummary(summaries, dryRun) {
|
|
597
|
+
const lines = ['## Pending Release Repair', '', `- Mode: ${dryRun ? 'dry run' : 'release'}`];
|
|
598
|
+
if (summaries.length === 0) {
|
|
599
|
+
lines.push('- Result: no pending releases needed repair');
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
for (const summary of summaries) {
|
|
603
|
+
lines.push(`- Repaired \`${summary.sha.slice(0, 12)}\`: ${packageSummary(summary.packages)}`);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
const text = `${lines.join('\n')}\n`;
|
|
607
|
+
console.log(text.trimEnd());
|
|
608
|
+
const summaryPath = process.env.GITHUB_STEP_SUMMARY;
|
|
609
|
+
if (summaryPath) {
|
|
610
|
+
await appendFile(summaryPath, `${text}\n`);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
function packageSummary(packages) {
|
|
614
|
+
if (packages.length === 0) {
|
|
615
|
+
return 'none';
|
|
616
|
+
}
|
|
617
|
+
return packages.map((pkg) => `${pkg.name}@${pkg.version}`).join(', ');
|
|
618
|
+
}
|
|
619
|
+
async function fetchReleaseRefs(root, remote, branch) {
|
|
620
|
+
await run('git', ['fetch', '--tags', remote, branch], root);
|
|
621
|
+
}
|
|
622
|
+
async function gitRefExists(root, ref) {
|
|
623
|
+
const result = await $ `git rev-parse --verify ${ref}`.cwd(root).quiet().nothrow();
|
|
624
|
+
return result.exitCode === 0;
|
|
625
|
+
}
|
|
626
|
+
async function packageChangedFilesSince(root, ref, packagePath) {
|
|
627
|
+
const result = await $ `git diff --name-only ${`${ref}..HEAD`} -- ${packagePath}`.cwd(root).quiet().nothrow();
|
|
628
|
+
if (result.exitCode !== 0) {
|
|
629
|
+
throw new Error(`Unable to inspect package changes under ${packagePath}.`);
|
|
630
|
+
}
|
|
631
|
+
const packagePrefix = `${packagePath}/`;
|
|
632
|
+
return decode(result.stdout)
|
|
633
|
+
.split('\n')
|
|
634
|
+
.map((path) => path.trim())
|
|
635
|
+
.filter(Boolean)
|
|
636
|
+
.map((path) => (path.startsWith(packagePrefix) ? path.slice(packagePrefix.length) : path));
|
|
637
|
+
}
|
|
638
|
+
async function packageJsonAtRef(root, ref, packagePath) {
|
|
639
|
+
const result = await $ `git show ${`${ref}:${packagePath}/package.json`}`.cwd(root).quiet().nothrow();
|
|
640
|
+
if (result.exitCode !== 0) {
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
643
|
+
try {
|
|
644
|
+
const parsed = JSON.parse(decode(result.stdout));
|
|
645
|
+
return isRecord(parsed) ? parsed : null;
|
|
646
|
+
}
|
|
647
|
+
catch {
|
|
648
|
+
return null;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
async function currentPackageJson(root, packagePath) {
|
|
652
|
+
return readPackageJson(join(root, packagePath, 'package.json'))?.json ?? null;
|
|
653
|
+
}
|
|
654
|
+
async function packageBuildInputPatterns(root, projectName, _packagePath) {
|
|
655
|
+
const project = await nxProjectJson(root, projectName);
|
|
656
|
+
const nxJson = readJsonObject(join(root, 'nx.json')) ?? {};
|
|
657
|
+
return resolveBuildInputPatterns(project, nxJson);
|
|
658
|
+
}
|
|
659
|
+
async function nxProjectJson(root, projectName) {
|
|
660
|
+
const result = await $ `nx show project ${projectName} --json`.cwd(root).quiet();
|
|
661
|
+
const parsed = JSON.parse(decode(result.stdout));
|
|
662
|
+
if (!isRecord(parsed)) {
|
|
663
|
+
throw new Error(`Unable to inspect Nx project ${projectName}.`);
|
|
664
|
+
}
|
|
665
|
+
return parsed;
|
|
666
|
+
}
|
|
667
|
+
function resolveBuildInputPatterns(project, nxJson) {
|
|
668
|
+
const targets = recordProperty(project, 'targets');
|
|
669
|
+
if (!targets) {
|
|
670
|
+
return [];
|
|
671
|
+
}
|
|
672
|
+
return normalizeInputPatterns(collectBuildInputs(targets), nxJson);
|
|
673
|
+
}
|
|
674
|
+
function collectBuildInputs(targets) {
|
|
675
|
+
const build = recordProperty(targets, 'build');
|
|
676
|
+
if (!build) {
|
|
677
|
+
return ['production'];
|
|
678
|
+
}
|
|
679
|
+
const directInputs = stringArrayProperty(build, 'inputs');
|
|
680
|
+
if (directInputs.length > 0) {
|
|
681
|
+
return directInputs;
|
|
682
|
+
}
|
|
683
|
+
const inputs = [];
|
|
684
|
+
for (const dependency of stringArrayProperty(build, 'dependsOn')) {
|
|
685
|
+
if (dependency.startsWith('^')) {
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
const targetName = dependency.includes(':') ? dependency.split(':')[1] : dependency;
|
|
689
|
+
if (!targetName) {
|
|
690
|
+
continue;
|
|
691
|
+
}
|
|
692
|
+
inputs.push(...stringArrayProperty(recordProperty(targets, targetName), 'inputs'));
|
|
693
|
+
}
|
|
694
|
+
return inputs.length > 0 ? inputs : ['production'];
|
|
695
|
+
}
|
|
696
|
+
function normalizeInputPatterns(inputs, nxJson) {
|
|
697
|
+
const patterns = [];
|
|
698
|
+
const seen = new Set();
|
|
699
|
+
for (const input of inputs) {
|
|
700
|
+
for (const pattern of expandInputPattern(input, nxJson, seen)) {
|
|
701
|
+
patterns.push(pattern);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
return patterns;
|
|
705
|
+
}
|
|
706
|
+
function expandInputPattern(input, nxJson, seen) {
|
|
707
|
+
if (seen.has(input)) {
|
|
708
|
+
return [];
|
|
709
|
+
}
|
|
710
|
+
seen.add(input);
|
|
711
|
+
if (!input.includes('{')) {
|
|
712
|
+
const namedInputs = recordProperty(nxJson, 'namedInputs');
|
|
713
|
+
const namedInput = namedInputs?.[input];
|
|
714
|
+
if (Array.isArray(namedInput)) {
|
|
715
|
+
return namedInput.flatMap((entry) => (typeof entry === 'string' ? expandInputPattern(entry, nxJson, seen) : []));
|
|
716
|
+
}
|
|
717
|
+
return [];
|
|
718
|
+
}
|
|
719
|
+
const excluded = input.startsWith('!');
|
|
720
|
+
const rawInput = excluded ? input.slice(1) : input;
|
|
721
|
+
if (!rawInput.startsWith('{projectRoot}/')) {
|
|
722
|
+
return [];
|
|
723
|
+
}
|
|
724
|
+
const packageRelative = rawInput.slice('{projectRoot}/'.length);
|
|
725
|
+
return [`${excluded ? '!' : ''}${packageRelative}`];
|
|
726
|
+
}
|
|
727
|
+
function recordProperty(record, key) {
|
|
728
|
+
if (!record) {
|
|
729
|
+
return null;
|
|
730
|
+
}
|
|
731
|
+
const value = record[key];
|
|
732
|
+
return isRecord(value) ? value : null;
|
|
733
|
+
}
|
|
734
|
+
function stringArrayProperty(record, key) {
|
|
735
|
+
const value = record?.[key];
|
|
736
|
+
return Array.isArray(value) ? value.filter((entry) => typeof entry === 'string') : [];
|
|
737
|
+
}
|
|
738
|
+
async function packageHasHistory(root, packagePath) {
|
|
739
|
+
const result = await $ `git log --format=%H -- ${packagePath}`.cwd(root).quiet().nothrow();
|
|
740
|
+
if (result.exitCode !== 0) {
|
|
741
|
+
throw new Error(`Unable to inspect package history under ${packagePath}.`);
|
|
742
|
+
}
|
|
743
|
+
return decode(result.stdout).trim().length > 0;
|
|
744
|
+
}
|
|
745
|
+
async function gitIsAncestor(root, ancestor, descendant) {
|
|
746
|
+
const result = await $ `git merge-base --is-ancestor ${ancestor} ${descendant}`.cwd(root).quiet().nothrow();
|
|
747
|
+
return result.exitCode === 0;
|
|
748
|
+
}
|
|
749
|
+
async function gitSha(root, ref) {
|
|
750
|
+
const result = await $ `git rev-parse ${ref}`.cwd(root).quiet().nothrow();
|
|
751
|
+
if (result.exitCode !== 0) {
|
|
752
|
+
throw new Error(`Unable to resolve git ref ${ref}.`);
|
|
753
|
+
}
|
|
754
|
+
return decode(result.stdout).trim();
|
|
755
|
+
}
|
|
756
|
+
async function gitTagPointsAt(root, tag, ref) {
|
|
757
|
+
return (await gitCommitForTag(root, tag)) === (await gitSha(root, ref));
|
|
758
|
+
}
|
|
759
|
+
async function gitCommitForTag(root, tag) {
|
|
760
|
+
const result = await $ `git rev-list -n 1 ${tag}`.cwd(root).quiet().nothrow();
|
|
761
|
+
if (result.exitCode !== 0) {
|
|
762
|
+
throw new Error(`Unable to resolve release tag ${tag}.`);
|
|
763
|
+
}
|
|
764
|
+
return decode(result.stdout).trim();
|
|
765
|
+
}
|
|
766
|
+
async function remoteReleaseTagExists(root, remote, tag) {
|
|
767
|
+
const result = await $ `git ls-remote --exit-code --tags ${remote} ${`refs/tags/${tag}`}`.cwd(root).quiet().nothrow();
|
|
768
|
+
return result.exitCode === 0;
|
|
769
|
+
}
|
|
770
|
+
async function remoteReleaseTagObject(root, remote, tag) {
|
|
771
|
+
const result = await $ `git ls-remote --exit-code --tags ${remote} ${`refs/tags/${tag}`}`.cwd(root).quiet().nothrow();
|
|
772
|
+
if (result.exitCode === 2) {
|
|
773
|
+
return null;
|
|
774
|
+
}
|
|
775
|
+
if (result.exitCode !== 0) {
|
|
776
|
+
throw new Error(`Unable to inspect remote release tag ${tag} on ${remote}.`);
|
|
777
|
+
}
|
|
778
|
+
const [object] = decode(result.stdout).trim().split('\t');
|
|
779
|
+
if (!object) {
|
|
780
|
+
throw new Error(`Unable to parse remote release tag ${tag} on ${remote}.`);
|
|
781
|
+
}
|
|
782
|
+
return object;
|
|
783
|
+
}
|
|
784
|
+
async function remoteBranchSha(root, remote, branch) {
|
|
785
|
+
const result = await $ `git ls-remote --exit-code --heads ${remote} ${`refs/heads/${branch}`}`
|
|
786
|
+
.cwd(root)
|
|
787
|
+
.quiet()
|
|
788
|
+
.nothrow();
|
|
789
|
+
if (result.exitCode === 2) {
|
|
790
|
+
return null;
|
|
791
|
+
}
|
|
792
|
+
if (result.exitCode !== 0) {
|
|
793
|
+
throw new Error(`Unable to inspect remote branch ${branch} on ${remote}.`);
|
|
794
|
+
}
|
|
795
|
+
const [sha] = decode(result.stdout).trim().split('\t');
|
|
796
|
+
if (!sha) {
|
|
797
|
+
throw new Error(`Unable to parse remote branch ${branch} on ${remote}.`);
|
|
798
|
+
}
|
|
799
|
+
return sha;
|
|
800
|
+
}
|
|
801
|
+
async function pushRetaggedReleaseTags(root, remote, updates) {
|
|
802
|
+
const leases = updates.map((update) => `--force-with-lease=refs/tags/${update.tag}:${update.expectedRemoteObject ?? ''}`);
|
|
803
|
+
const refspecs = updates.map((update) => `refs/tags/${update.tag}:refs/tags/${update.tag}`);
|
|
804
|
+
await run('git', ['push', '--atomic', ...leases, remote, ...refspecs], root);
|
|
805
|
+
}
|
|
806
|
+
async function githubReleaseExists(root, tag) {
|
|
807
|
+
return (await runStatus('gh', ['release', 'view', tag, '--json', 'tagName'], root, true)) === 0;
|
|
808
|
+
}
|
|
809
|
+
async function assertRemoteTagExists(root, tag) {
|
|
810
|
+
const branch = await releaseBranch(root);
|
|
811
|
+
const remote = await releaseRemote(root, branch);
|
|
812
|
+
if (!(await remoteReleaseTagExists(root, remote, tag))) {
|
|
813
|
+
throw new Error(`Release tag ${tag} is not present on remote ${remote}. Run smoo release version first.`);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
async function npmVersionExists(root, name, version) {
|
|
817
|
+
const result = await $ `bun pm view ${`${name}@${version}`} version`.cwd(root).quiet().nothrow();
|
|
818
|
+
return result.exitCode === 0 && decode(result.stdout).trim() === version;
|
|
819
|
+
}
|
|
820
|
+
async function npmPackageExists(root, name) {
|
|
821
|
+
const result = await $ `bun pm view ${name} name`.cwd(root).quiet().nothrow();
|
|
822
|
+
return result.exitCode === 0;
|
|
823
|
+
}
|
|
175
824
|
async function assertCleanGitTree(root) {
|
|
176
825
|
const result = await $ `git status --porcelain --untracked-files=no`.cwd(root).quiet().nothrow();
|
|
177
826
|
if (result.exitCode !== 0) {
|
|
@@ -189,11 +838,6 @@ async function gitHead(root) {
|
|
|
189
838
|
}
|
|
190
839
|
return decode(result.stdout).trim();
|
|
191
840
|
}
|
|
192
|
-
async function pushReleaseCommit(root) {
|
|
193
|
-
const branch = await releaseBranch(root);
|
|
194
|
-
const remote = await releaseRemote(root, branch);
|
|
195
|
-
await run('git', ['push', '--follow-tags', '--atomic', remote, `HEAD:refs/heads/${branch}`], root);
|
|
196
|
-
}
|
|
197
841
|
async function releaseBranch(root) {
|
|
198
842
|
const githubBranch = process.env.GITHUB_REF_NAME?.trim();
|
|
199
843
|
if (githubBranch) {
|
|
@@ -242,18 +886,6 @@ function releaseBumpArg(bump = 'auto') {
|
|
|
242
886
|
}
|
|
243
887
|
return bump;
|
|
244
888
|
}
|
|
245
|
-
function releaseNpmTagArg(options) {
|
|
246
|
-
const bump = releaseBumpArg(options.bump);
|
|
247
|
-
const derivedTag = bump === 'prerelease' ? 'next' : 'latest';
|
|
248
|
-
const explicitTag = options.tag ?? options.npmTag;
|
|
249
|
-
if (!explicitTag) {
|
|
250
|
-
return derivedTag;
|
|
251
|
-
}
|
|
252
|
-
if (explicitTag !== derivedTag) {
|
|
253
|
-
throw new Error(`--bump ${bump} publishes with npm dist-tag ${derivedTag}, not ${explicitTag}.`);
|
|
254
|
-
}
|
|
255
|
-
return explicitTag;
|
|
256
|
-
}
|
|
257
889
|
function githubRepositoryFromRootPackage(root) {
|
|
258
890
|
const pkg = readPackageJson(join(root, 'package.json'));
|
|
259
891
|
const repository = pkg ? repositoryInfo(pkg.json) : null;
|
|
@@ -284,21 +916,22 @@ function githubRepositoryFromUrl(url) {
|
|
|
284
916
|
async function runLatestNpm(root, npmArgs, env) {
|
|
285
917
|
await run('nix', ['shell', 'nixpkgs#nodejs_latest', '-c', 'npm', ...npmArgs], root, env);
|
|
286
918
|
}
|
|
287
|
-
async function
|
|
288
|
-
const
|
|
289
|
-
if (
|
|
290
|
-
|
|
291
|
-
return;
|
|
919
|
+
async function runLatestNpmTrust(root, npmArgs, env) {
|
|
920
|
+
const result = await runResult('nix', ['shell', 'nixpkgs#nodejs_latest', '-c', 'npm', ...npmArgs], root, env);
|
|
921
|
+
if (result.exitCode === 0) {
|
|
922
|
+
return 'configured';
|
|
292
923
|
}
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
await writeFile(npmrc, `registry=https://registry.npmjs.org/\n//registry.npmjs.org/:_authToken=${token}\n`);
|
|
297
|
-
await runLatestNpm(root, npmArgs, { NPM_CONFIG_USERCONFIG: npmrc });
|
|
298
|
-
}
|
|
299
|
-
finally {
|
|
300
|
-
await rm(tempDir, { recursive: true, force: true });
|
|
924
|
+
const output = `${result.stdout}\n${result.stderr}`;
|
|
925
|
+
if (/\bE409\b|\b409 Conflict\b/.test(output)) {
|
|
926
|
+
return 'already-configured';
|
|
301
927
|
}
|
|
928
|
+
throw new Error(`nix shell nixpkgs#nodejs_latest -c npm ${npmArgs.join(' ')} failed with exit code ${result.exitCode}`);
|
|
929
|
+
}
|
|
930
|
+
async function runLatestNpmPublish(root, npmArgs) {
|
|
931
|
+
await runLatestNpm(root, npmArgs, { NODE_AUTH_TOKEN: '', NPM_TOKEN: '' });
|
|
932
|
+
}
|
|
933
|
+
function missingNpmPackagePublishGuidance(pkg) {
|
|
934
|
+
return `${pkg.name} does not exist on npm yet. Run smoo release trust-publisher --bootstrap locally before rerunning the Publish workflow.`;
|
|
302
935
|
}
|
|
303
936
|
async function promptForNpmOtp(packageName) {
|
|
304
937
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|