@smoothbricks/cli 0.1.0 → 0.1.1
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 +208 -83
- package/dist/cli.js +50 -20
- 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/workspace.d.ts +5 -0
- package/dist/lib/workspace.d.ts.map +1 -1
- package/dist/lib/workspace.js +62 -5
- package/dist/monorepo/index.d.ts +6 -1
- package/dist/monorepo/index.d.ts.map +1 -1
- package/dist/monorepo/index.js +38 -5
- 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 +27 -10
- package/dist/monorepo/package-hygiene.js +1 -1
- package/dist/monorepo/package-policy.d.ts +3 -0
- package/dist/monorepo/package-policy.d.ts.map +1 -1
- package/dist/monorepo/package-policy.js +122 -19
- 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.map +1 -1
- package/dist/monorepo/packed-package.js +6 -0
- package/dist/monorepo/packs/index.d.ts.map +1 -1
- package/dist/monorepo/packs/index.js +4 -1
- package/dist/monorepo/publish-workflow.d.ts +86 -0
- package/dist/monorepo/publish-workflow.d.ts.map +1 -0
- package/dist/monorepo/publish-workflow.js +343 -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/core.d.ts +50 -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 +14 -5
- package/dist/release/index.d.ts.map +1 -1
- package/dist/release/index.js +544 -109
- package/dist/release/npm-auth.d.ts +17 -0
- package/dist/release/npm-auth.d.ts.map +1 -0
- package/dist/release/npm-auth.js +51 -0
- package/dist/release/orchestration.d.ts +48 -0
- package/dist/release/orchestration.d.ts.map +1 -0
- package/dist/release/orchestration.js +105 -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/tooling/git-hooks/pre-commit.sh +2 -7
- package/managed/templates/github/workflows/ci.yml +2 -0
- package/package.json +24 -3
- package/src/cli.ts +64 -25
- package/src/lib/devenv.test.ts +28 -0
- package/src/lib/devenv.ts +89 -0
- package/src/lib/workspace.ts +76 -5
- package/src/monorepo/__tests__/nx-version-actions.test.ts +75 -0
- package/src/monorepo/__tests__/publish-workflow.test.ts +315 -0
- package/src/monorepo/index.ts +45 -5
- package/src/monorepo/lockfile.ts +52 -7
- package/src/monorepo/managed-files.ts +42 -12
- package/src/monorepo/package-hygiene.ts +1 -1
- package/src/monorepo/package-policy.ts +134 -18
- package/src/monorepo/packed-manifest.ts +67 -0
- package/src/monorepo/packed-package.ts +7 -0
- package/src/monorepo/packs/index.ts +4 -0
- package/src/monorepo/publish-workflow.ts +430 -0
- package/src/nx-version-actions.cts +36 -0
- package/src/release/__tests__/core-properties.test.ts +149 -0
- package/src/release/__tests__/core-scenarios.test.ts +177 -0
- package/src/release/__tests__/core.test.ts +73 -0
- package/src/release/__tests__/fixture-repo.test.ts +305 -0
- package/src/release/__tests__/github-release.test.ts +144 -0
- package/src/release/__tests__/helpers/fixture-repo.ts +113 -0
- package/src/release/__tests__/npm-auth.test.ts +129 -0
- package/src/release/__tests__/orchestration.test.ts +202 -0
- package/src/release/__tests__/publish-plan.test.ts +61 -0
- package/src/release/__tests__/retag-unpublished.test.ts +160 -0
- package/src/release/core.ts +170 -0
- package/src/release/github-release.ts +134 -0
- package/src/release/index.ts +662 -116
- package/src/release/npm-auth.ts +122 -0
- package/src/release/orchestration.ts +186 -0
- package/src/release/publish-plan.ts +37 -0
- package/src/release/retag-unpublished.ts +122 -0
- package/managed/templates/github/workflows/publish.yml +0 -136
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
export type PublishWorkflowBump = 'auto' | 'patch' | 'minor' | 'major' | 'prerelease';
|
|
2
|
+
export type PublishWorkflowCondition = 'version-mode-not-none' | 'failure' | 'always';
|
|
3
|
+
export type PublishWorkflowNxTarget = 'build' | 'lint' | 'test';
|
|
4
|
+
|
|
5
|
+
export enum PublishWorkflowStepKind {
|
|
6
|
+
Checkout = 'checkout',
|
|
7
|
+
SetupDevenv = 'setup-devenv',
|
|
8
|
+
ConfigureReleaseAuthor = 'configure-release-author',
|
|
9
|
+
BuildSelfHostedCli = 'build-self-hosted-cli',
|
|
10
|
+
RepairPendingReleases = 'repair-pending-releases',
|
|
11
|
+
VersionRelease = 'version-release',
|
|
12
|
+
CheckManagedMonorepoFiles = 'check-managed-monorepo-files',
|
|
13
|
+
Build = 'build',
|
|
14
|
+
Lint = 'lint',
|
|
15
|
+
UnitTests = 'unit-tests',
|
|
16
|
+
UploadTraceDbs = 'upload-trace-dbs',
|
|
17
|
+
ValidateMonorepoConfig = 'validate-monorepo-config',
|
|
18
|
+
PublishRelease = 'publish-release',
|
|
19
|
+
SaveNixDevenv = 'save-nix-devenv',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface PublishWorkflowStep {
|
|
23
|
+
kind: PublishWorkflowStepKind;
|
|
24
|
+
name: string;
|
|
25
|
+
number: number;
|
|
26
|
+
id?: string;
|
|
27
|
+
condition?: PublishWorkflowCondition;
|
|
28
|
+
nxTarget?: PublishWorkflowNxTarget;
|
|
29
|
+
needsNodeAuthToken?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface PublishWorkflowDefinition {
|
|
33
|
+
steps: PublishWorkflowStep[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface PublishWorkflowDefinitionOptions {
|
|
37
|
+
repoName?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface PublishWorkflowInputs {
|
|
41
|
+
bump: PublishWorkflowBump;
|
|
42
|
+
dryRun: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface PublishWorkflowVersionOutputs {
|
|
46
|
+
mode: 'new' | 'none';
|
|
47
|
+
projects: string[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface PublishWorkflowSetupOutputs {
|
|
51
|
+
nixCacheHit: string;
|
|
52
|
+
devenvCacheHit: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface PublishWorkflowCallbacks {
|
|
56
|
+
checkout(): Promise<void>;
|
|
57
|
+
setupDevenv(): Promise<PublishWorkflowSetupOutputs>;
|
|
58
|
+
configureReleaseAuthor(): Promise<void>;
|
|
59
|
+
buildSelfHostedCli(): Promise<void>;
|
|
60
|
+
repairPendingReleases(input: { dryRun: boolean; nodeAuthToken: boolean }): Promise<void>;
|
|
61
|
+
versionRelease(input: { bump: PublishWorkflowBump; dryRun: boolean }): Promise<PublishWorkflowVersionOutputs>;
|
|
62
|
+
checkManagedMonorepoFiles(): Promise<void>;
|
|
63
|
+
nxRunMany(input: { target: PublishWorkflowNxTarget; projects: string[] }): Promise<void>;
|
|
64
|
+
uploadTraceDbs(): Promise<void>;
|
|
65
|
+
validateMonorepoConfig(): Promise<void>;
|
|
66
|
+
publishRelease(input: { bump: PublishWorkflowBump; dryRun: boolean; nodeAuthToken: boolean }): Promise<void>;
|
|
67
|
+
saveNixDevenv(input: PublishWorkflowSetupOutputs): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface PublishWorkflowRunContext {
|
|
71
|
+
inputs: PublishWorkflowInputs;
|
|
72
|
+
nodeAuthToken: boolean;
|
|
73
|
+
callbacks: PublishWorkflowCallbacks;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface PublishWorkflowRunResult {
|
|
77
|
+
version: PublishWorkflowVersionOutputs;
|
|
78
|
+
failed: boolean;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
type PublishWorkflowStepInput = Omit<PublishWorkflowStep, 'number'>;
|
|
82
|
+
|
|
83
|
+
export function definePublishWorkflow(options: PublishWorkflowDefinitionOptions = {}): PublishWorkflowDefinition {
|
|
84
|
+
const versionMode = githubExpression('steps.version.outputs.mode');
|
|
85
|
+
const setupSteps: PublishWorkflowStepInput[] = [
|
|
86
|
+
{ kind: PublishWorkflowStepKind.Checkout, name: '📥 Checkout' },
|
|
87
|
+
{ kind: PublishWorkflowStepKind.SetupDevenv, name: '🧱 Setup Nix/devenv', id: 'setup' },
|
|
88
|
+
{ kind: PublishWorkflowStepKind.ConfigureReleaseAuthor, name: '🤖 Configure release author' },
|
|
89
|
+
];
|
|
90
|
+
if (options.repoName === '@smoothbricks/codebase') {
|
|
91
|
+
setupSteps.push({ kind: PublishWorkflowStepKind.BuildSelfHostedCli, name: '🏗️ Build self-hosted smoo' });
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
steps: numberWorkflowSteps([
|
|
95
|
+
...setupSteps,
|
|
96
|
+
{
|
|
97
|
+
kind: PublishWorkflowStepKind.RepairPendingReleases,
|
|
98
|
+
name: '🧯 Repair pending releases',
|
|
99
|
+
needsNodeAuthToken: true,
|
|
100
|
+
},
|
|
101
|
+
{ kind: PublishWorkflowStepKind.VersionRelease, name: '🏷️ Version release', id: 'version' },
|
|
102
|
+
{
|
|
103
|
+
kind: PublishWorkflowStepKind.CheckManagedMonorepoFiles,
|
|
104
|
+
name: `✅ Check managed monorepo files (${versionMode})`,
|
|
105
|
+
condition: 'version-mode-not-none',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
kind: PublishWorkflowStepKind.Build,
|
|
109
|
+
name: `🔨 Build (${versionMode})`,
|
|
110
|
+
condition: 'version-mode-not-none',
|
|
111
|
+
nxTarget: 'build',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
kind: PublishWorkflowStepKind.Lint,
|
|
115
|
+
name: `🔍 Lint (${versionMode})`,
|
|
116
|
+
condition: 'version-mode-not-none',
|
|
117
|
+
nxTarget: 'lint',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
kind: PublishWorkflowStepKind.UnitTests,
|
|
121
|
+
name: `🧪 Unit Tests (${versionMode})`,
|
|
122
|
+
condition: 'version-mode-not-none',
|
|
123
|
+
nxTarget: 'test',
|
|
124
|
+
},
|
|
125
|
+
{ kind: PublishWorkflowStepKind.UploadTraceDbs, name: '📎 Upload trace DBs', condition: 'failure' },
|
|
126
|
+
{
|
|
127
|
+
kind: PublishWorkflowStepKind.ValidateMonorepoConfig,
|
|
128
|
+
name: `✅ Validate monorepo config (${versionMode})`,
|
|
129
|
+
condition: 'version-mode-not-none',
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
kind: PublishWorkflowStepKind.PublishRelease,
|
|
133
|
+
name: `📦 Publish release (${versionMode})`,
|
|
134
|
+
needsNodeAuthToken: true,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
kind: PublishWorkflowStepKind.SaveNixDevenv,
|
|
138
|
+
name: '🧹 Cleanup and cache Nix/devenv',
|
|
139
|
+
condition: 'always',
|
|
140
|
+
},
|
|
141
|
+
]),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function numberWorkflowSteps(steps: PublishWorkflowStepInput[]): PublishWorkflowStep[] {
|
|
146
|
+
return steps.map((step, index) => ({ ...step, number: index + 2 }));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export async function runPublishWorkflow(
|
|
150
|
+
workflow: PublishWorkflowDefinition,
|
|
151
|
+
context: PublishWorkflowRunContext,
|
|
152
|
+
): Promise<PublishWorkflowRunResult> {
|
|
153
|
+
let setupOutputs: PublishWorkflowSetupOutputs = { nixCacheHit: '', devenvCacheHit: '' };
|
|
154
|
+
let version: PublishWorkflowVersionOutputs = { mode: 'none', projects: [] };
|
|
155
|
+
let failed = false;
|
|
156
|
+
let failure: unknown;
|
|
157
|
+
for (const step of workflow.steps) {
|
|
158
|
+
if (!shouldRunStep(step, version, failed)) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
switch (step.kind) {
|
|
163
|
+
case PublishWorkflowStepKind.Checkout:
|
|
164
|
+
await context.callbacks.checkout();
|
|
165
|
+
break;
|
|
166
|
+
case PublishWorkflowStepKind.SetupDevenv:
|
|
167
|
+
setupOutputs = await context.callbacks.setupDevenv();
|
|
168
|
+
break;
|
|
169
|
+
case PublishWorkflowStepKind.ConfigureReleaseAuthor:
|
|
170
|
+
await context.callbacks.configureReleaseAuthor();
|
|
171
|
+
break;
|
|
172
|
+
case PublishWorkflowStepKind.BuildSelfHostedCli:
|
|
173
|
+
await context.callbacks.buildSelfHostedCli();
|
|
174
|
+
break;
|
|
175
|
+
case PublishWorkflowStepKind.RepairPendingReleases:
|
|
176
|
+
await context.callbacks.repairPendingReleases({
|
|
177
|
+
dryRun: context.inputs.dryRun,
|
|
178
|
+
nodeAuthToken: context.nodeAuthToken,
|
|
179
|
+
});
|
|
180
|
+
break;
|
|
181
|
+
case PublishWorkflowStepKind.VersionRelease:
|
|
182
|
+
version = await context.callbacks.versionRelease(context.inputs);
|
|
183
|
+
break;
|
|
184
|
+
case PublishWorkflowStepKind.CheckManagedMonorepoFiles:
|
|
185
|
+
await context.callbacks.checkManagedMonorepoFiles();
|
|
186
|
+
break;
|
|
187
|
+
case PublishWorkflowStepKind.Build:
|
|
188
|
+
case PublishWorkflowStepKind.Lint:
|
|
189
|
+
case PublishWorkflowStepKind.UnitTests:
|
|
190
|
+
if (!step.nxTarget) {
|
|
191
|
+
throw new Error(`Workflow step ${step.kind} is missing an Nx target.`);
|
|
192
|
+
}
|
|
193
|
+
await context.callbacks.nxRunMany({ target: step.nxTarget, projects: version.projects });
|
|
194
|
+
break;
|
|
195
|
+
case PublishWorkflowStepKind.UploadTraceDbs:
|
|
196
|
+
await context.callbacks.uploadTraceDbs();
|
|
197
|
+
break;
|
|
198
|
+
case PublishWorkflowStepKind.ValidateMonorepoConfig:
|
|
199
|
+
await context.callbacks.validateMonorepoConfig();
|
|
200
|
+
break;
|
|
201
|
+
case PublishWorkflowStepKind.PublishRelease:
|
|
202
|
+
await context.callbacks.publishRelease({
|
|
203
|
+
bump: context.inputs.bump,
|
|
204
|
+
dryRun: context.inputs.dryRun,
|
|
205
|
+
nodeAuthToken: context.nodeAuthToken,
|
|
206
|
+
});
|
|
207
|
+
break;
|
|
208
|
+
case PublishWorkflowStepKind.SaveNixDevenv:
|
|
209
|
+
await context.callbacks.saveNixDevenv(setupOutputs);
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
} catch (error) {
|
|
213
|
+
failed = true;
|
|
214
|
+
failure = error;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (failure) {
|
|
218
|
+
throw failure;
|
|
219
|
+
}
|
|
220
|
+
return { version, failed };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function shouldRunStep(step: PublishWorkflowStep, version: PublishWorkflowVersionOutputs, failed: boolean): boolean {
|
|
224
|
+
if (step.condition === 'version-mode-not-none') {
|
|
225
|
+
return version.mode !== 'none';
|
|
226
|
+
}
|
|
227
|
+
if (step.condition === 'failure') {
|
|
228
|
+
return failed;
|
|
229
|
+
}
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function renderPublishWorkflowYaml(options: PublishWorkflowDefinitionOptions = {}): string {
|
|
234
|
+
const steps = definePublishWorkflow(options).steps;
|
|
235
|
+
return `${renderPublishWorkflowHeader()}${renderPublishWorkflowSteps(steps)}`;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function renderPublishWorkflowHeader(): string {
|
|
239
|
+
return `name: Publish
|
|
240
|
+
|
|
241
|
+
on:
|
|
242
|
+
workflow_dispatch:
|
|
243
|
+
inputs:
|
|
244
|
+
bump:
|
|
245
|
+
type: choice
|
|
246
|
+
description:
|
|
247
|
+
Use auto for conventional commits, or force a semver bump. Prerelease publishes to next; all others publish to
|
|
248
|
+
latest.
|
|
249
|
+
options: [auto, patch, minor, major, prerelease]
|
|
250
|
+
default: auto
|
|
251
|
+
dry_run:
|
|
252
|
+
type: boolean
|
|
253
|
+
description: Run release commands without writing versions, tags, publishes, or GitHub Releases.
|
|
254
|
+
default: false
|
|
255
|
+
|
|
256
|
+
permissions:
|
|
257
|
+
contents: write
|
|
258
|
+
id-token: write
|
|
259
|
+
|
|
260
|
+
concurrency:
|
|
261
|
+
group: release-${githubExpression('github.ref')}
|
|
262
|
+
cancel-in-progress: false
|
|
263
|
+
|
|
264
|
+
defaults:
|
|
265
|
+
run:
|
|
266
|
+
working-directory: tooling/direnv
|
|
267
|
+
|
|
268
|
+
jobs:
|
|
269
|
+
publish:
|
|
270
|
+
runs-on: ubuntu-latest
|
|
271
|
+
env:
|
|
272
|
+
NIX_STORE_NAR: ${githubExpression('github.workspace')}/nix-store.nar
|
|
273
|
+
GH_TOKEN: ${githubExpression('github.token')}
|
|
274
|
+
steps:
|
|
275
|
+
`;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function renderPublishWorkflowSteps(steps: PublishWorkflowStep[]): string {
|
|
279
|
+
const lines: string[] = [];
|
|
280
|
+
for (const step of steps) {
|
|
281
|
+
lines.push(...sectionLinesBefore(step));
|
|
282
|
+
lines.push(...commentLinesForStep(step));
|
|
283
|
+
lines.push(...yamlLinesForStep(step));
|
|
284
|
+
lines.push('');
|
|
285
|
+
}
|
|
286
|
+
return `${lines.join('\n').trimEnd()}\n`;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function sectionLinesBefore(step: PublishWorkflowStep): string[] {
|
|
290
|
+
if (step.kind === PublishWorkflowStepKind.Checkout) {
|
|
291
|
+
return [' # --- Setup --------------------------------------------------------------', ''];
|
|
292
|
+
}
|
|
293
|
+
if (step.kind === PublishWorkflowStepKind.CheckManagedMonorepoFiles) {
|
|
294
|
+
return [
|
|
295
|
+
' # --- Validation ---------------------------------------------------------',
|
|
296
|
+
'',
|
|
297
|
+
' # Release validation intentionally does not restore persisted Nx task',
|
|
298
|
+
' # cache. Nx may reuse tasks produced earlier in this same job, but publish',
|
|
299
|
+
' # never relies on task outputs restored from CI cache. version runs before',
|
|
300
|
+
' # validation so the commit completed below is the commit that was checked.',
|
|
301
|
+
'',
|
|
302
|
+
];
|
|
303
|
+
}
|
|
304
|
+
if (step.kind === PublishWorkflowStepKind.PublishRelease) {
|
|
305
|
+
return [' # --- Release ------------------------------------------------------------', ''];
|
|
306
|
+
}
|
|
307
|
+
if (step.kind === PublishWorkflowStepKind.SaveNixDevenv) {
|
|
308
|
+
return [' # --- Cleanup ------------------------------------------------------------', ''];
|
|
309
|
+
}
|
|
310
|
+
return [];
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function commentLinesForStep(step: PublishWorkflowStep): string[] {
|
|
314
|
+
if (step.kind === PublishWorkflowStepKind.Checkout) {
|
|
315
|
+
return [' # Step 1: GitHub adds "Set up job" automatically', ' # Step 2'];
|
|
316
|
+
}
|
|
317
|
+
if (step.kind === PublishWorkflowStepKind.SetupDevenv) {
|
|
318
|
+
return [
|
|
319
|
+
' # Step 3. Composite action internals do not affect top-level job step',
|
|
320
|
+
' # anchors; update these comments if top-level steps move.',
|
|
321
|
+
];
|
|
322
|
+
}
|
|
323
|
+
return [` # Step ${step.number}`];
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function yamlLinesForStep(step: PublishWorkflowStep): string[] {
|
|
327
|
+
switch (step.kind) {
|
|
328
|
+
case PublishWorkflowStepKind.Checkout:
|
|
329
|
+
return [
|
|
330
|
+
` - name: ${step.name}`,
|
|
331
|
+
' uses: actions/checkout@v6.0.2',
|
|
332
|
+
' with:',
|
|
333
|
+
' filter: blob:none',
|
|
334
|
+
' fetch-depth: 0',
|
|
335
|
+
];
|
|
336
|
+
case PublishWorkflowStepKind.SetupDevenv:
|
|
337
|
+
return [` - name: ${step.name}`, ' id: setup', ' uses: ./.github/actions/setup-devenv'];
|
|
338
|
+
case PublishWorkflowStepKind.ConfigureReleaseAuthor:
|
|
339
|
+
return [
|
|
340
|
+
` - name: ${step.name}`,
|
|
341
|
+
' run:',
|
|
342
|
+
' git config user.name "github-actions[bot]" && git config user.email',
|
|
343
|
+
' "41898282+github-actions[bot]@users.noreply.github.com"',
|
|
344
|
+
];
|
|
345
|
+
case PublishWorkflowStepKind.BuildSelfHostedCli:
|
|
346
|
+
return [
|
|
347
|
+
` - name: ${step.name}`,
|
|
348
|
+
' # SmoothBricks self-hosts smoo from source, but Nx release loads',
|
|
349
|
+
' # @smoothbricks/cli/nx-version-actions through the built package export.',
|
|
350
|
+
' run: nx build @smoothbricks/cli',
|
|
351
|
+
];
|
|
352
|
+
case PublishWorkflowStepKind.RepairPendingReleases:
|
|
353
|
+
return [
|
|
354
|
+
` - name: ${step.name}`,
|
|
355
|
+
' env:',
|
|
356
|
+
` NODE_AUTH_TOKEN: ${githubExpression('secrets.NPM_TOKEN')}`,
|
|
357
|
+
` run: smoo release repair-pending --dry-run "${githubExpression('inputs.dry_run')}"`,
|
|
358
|
+
];
|
|
359
|
+
case PublishWorkflowStepKind.VersionRelease:
|
|
360
|
+
return [
|
|
361
|
+
` - name: ${step.name}`,
|
|
362
|
+
' id: version',
|
|
363
|
+
' run:',
|
|
364
|
+
` smoo release version --bump "${githubExpression('inputs.bump')}" --dry-run "${githubExpression('inputs.dry_run')}" --github-output`,
|
|
365
|
+
' "$GITHUB_OUTPUT"',
|
|
366
|
+
];
|
|
367
|
+
case PublishWorkflowStepKind.CheckManagedMonorepoFiles:
|
|
368
|
+
return conditionalRunStep(step, 'smoo monorepo check');
|
|
369
|
+
case PublishWorkflowStepKind.Build:
|
|
370
|
+
return conditionalRunStep(
|
|
371
|
+
step,
|
|
372
|
+
`smoo github-ci nx-run-many --targets build --projects "${githubExpression('steps.version.outputs.projects')}"`,
|
|
373
|
+
);
|
|
374
|
+
case PublishWorkflowStepKind.Lint:
|
|
375
|
+
return conditionalRunStep(
|
|
376
|
+
step,
|
|
377
|
+
`smoo github-ci nx-run-many --targets lint --projects "${githubExpression('steps.version.outputs.projects')}"`,
|
|
378
|
+
);
|
|
379
|
+
case PublishWorkflowStepKind.UnitTests:
|
|
380
|
+
return conditionalRunStep(
|
|
381
|
+
step,
|
|
382
|
+
`smoo github-ci nx-run-many --targets test --projects "${githubExpression('steps.version.outputs.projects')}"`,
|
|
383
|
+
);
|
|
384
|
+
case PublishWorkflowStepKind.UploadTraceDbs:
|
|
385
|
+
return [
|
|
386
|
+
` - name: ${step.name}`,
|
|
387
|
+
` if: ${githubExpression('failure()')}`,
|
|
388
|
+
' uses: actions/upload-artifact@v4',
|
|
389
|
+
' with:',
|
|
390
|
+
` name: trace-results-${githubExpression('github.run_id')}`,
|
|
391
|
+
' path: packages/*/.trace-results.db',
|
|
392
|
+
' if-no-files-found: ignore',
|
|
393
|
+
' retention-days: 14',
|
|
394
|
+
' include-hidden-files: true',
|
|
395
|
+
];
|
|
396
|
+
case PublishWorkflowStepKind.ValidateMonorepoConfig:
|
|
397
|
+
return conditionalRunStep(step, 'smoo monorepo validate');
|
|
398
|
+
case PublishWorkflowStepKind.PublishRelease:
|
|
399
|
+
return [
|
|
400
|
+
` - name: ${step.name}`,
|
|
401
|
+
' # smoo packs with Bun, then publishes tarballs with npm. Existing',
|
|
402
|
+
' # packages use trusted publishing/OIDC; first publishes use NODE_AUTH_TOKEN',
|
|
403
|
+
' # because npm trust can only be configured after a package exists.',
|
|
404
|
+
' env:',
|
|
405
|
+
` NODE_AUTH_TOKEN: ${githubExpression('secrets.NPM_TOKEN')}`,
|
|
406
|
+
` run: smoo release publish --bump "${githubExpression('inputs.bump')}" --dry-run "${githubExpression('inputs.dry_run')}"`,
|
|
407
|
+
];
|
|
408
|
+
case PublishWorkflowStepKind.SaveNixDevenv:
|
|
409
|
+
return [
|
|
410
|
+
` - name: ${step.name}`,
|
|
411
|
+
` if: ${githubExpression('always()')}`,
|
|
412
|
+
' uses: ./.github/actions/save-nix-devenv',
|
|
413
|
+
' with:',
|
|
414
|
+
` nix-cache-hit: ${githubExpression('steps.setup.outputs.nix-cache-hit')}`,
|
|
415
|
+
` devenv-cache-hit: ${githubExpression('steps.setup.outputs.devenv-cache-hit')}`,
|
|
416
|
+
];
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function conditionalRunStep(step: PublishWorkflowStep, run: string): string[] {
|
|
421
|
+
return [
|
|
422
|
+
` - name: ${step.name}`,
|
|
423
|
+
` if: ${githubExpression("steps.version.outputs.mode != 'none'")}`,
|
|
424
|
+
` run: ${run}`,
|
|
425
|
+
];
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function githubExpression(expression: string): string {
|
|
429
|
+
return ['$', '{{ ', expression, ' }}'].join('');
|
|
430
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AfterAllProjectsVersioned, VersionActions } from 'nx/release';
|
|
2
|
+
|
|
3
|
+
type VersionActionsModule = typeof VersionActions & {
|
|
4
|
+
default?: typeof VersionActions & { afterAllProjectsVersioned: AfterAllProjectsVersioned };
|
|
5
|
+
afterAllProjectsVersioned: AfterAllProjectsVersioned;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const nxJsVersionActions = require('@nx/js/src/release/version-actions') as VersionActionsModule;
|
|
9
|
+
const baseVersionActions = nxJsVersionActions.default ?? nxJsVersionActions;
|
|
10
|
+
|
|
11
|
+
const afterAllProjectsVersioned: AfterAllProjectsVersioned = async (cwd, options) => {
|
|
12
|
+
const result = await nxJsVersionActions.afterAllProjectsVersioned(cwd, options);
|
|
13
|
+
|
|
14
|
+
// Temporary Bun workaround. Remove this hook only after all three issues are
|
|
15
|
+
// fixed in supported Bun versions:
|
|
16
|
+
// - https://github.com/oven-sh/bun/issues/18906
|
|
17
|
+
// - https://github.com/oven-sh/bun/issues/20477
|
|
18
|
+
// - https://github.com/oven-sh/bun/issues/20829
|
|
19
|
+
// Nx runs `bun install --lockfile-only`, but Bun currently leaves workspace
|
|
20
|
+
// versions stale in bun.lock. `bun pm pack` then rewrites `workspace:*` using
|
|
21
|
+
// those stale lockfile versions instead of the current package.json versions.
|
|
22
|
+
const { syncBunLockfileVersions } = await import('./monorepo/lockfile.js');
|
|
23
|
+
const updated = syncBunLockfileVersions(cwd);
|
|
24
|
+
if (updated === 0) {
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
changedFiles: Array.from(new Set([...result.changedFiles, 'bun.lock'])),
|
|
30
|
+
deletedFiles: result.deletedFiles,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
baseVersionActions.afterAllProjectsVersioned = afterAllProjectsVersioned;
|
|
35
|
+
|
|
36
|
+
export = baseVersionActions;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import fc from 'fast-check';
|
|
3
|
+
import { groupReleaseTargets, pendingReleaseTargets, type ReleasePackageInfo, type ReleaseTagRecord } from '../core.js';
|
|
4
|
+
import { planPublishActions } from '../publish-plan.js';
|
|
5
|
+
|
|
6
|
+
const packages: ReleasePackageInfo[] = [
|
|
7
|
+
{ name: '@scope/a', path: 'packages/a', version: '1.0.0' },
|
|
8
|
+
{ name: '@scope/b', path: 'packages/b', version: '2.0.0-beta.1' },
|
|
9
|
+
{ name: '@scope/c', path: 'packages/c', version: '3.0.0' },
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
describe('release core properties', () => {
|
|
13
|
+
it('groups release tags by commit while preserving repair classifications', () => {
|
|
14
|
+
fc.assert(
|
|
15
|
+
fc.property(releaseRecords(), (records) => {
|
|
16
|
+
const targets = groupReleaseTargets(records);
|
|
17
|
+
|
|
18
|
+
for (const target of targets) {
|
|
19
|
+
const recordsForTarget = records.filter((record) => record.sha === target.sha);
|
|
20
|
+
const expectedTimestamp = Math.max(...recordsForTarget.map((record) => record.timestamp));
|
|
21
|
+
const expectedPackages = recordsForTarget
|
|
22
|
+
.filter((record) => record.needsNpmPublish || record.needsGithubRelease)
|
|
23
|
+
.map((record) => record.pkg.name);
|
|
24
|
+
const expectedNpmPackages = recordsForTarget
|
|
25
|
+
.filter((record) => record.needsNpmPublish)
|
|
26
|
+
.map((record) => record.pkg.name);
|
|
27
|
+
const expectedGithubPackages = recordsForTarget
|
|
28
|
+
.filter((record) => record.needsGithubRelease)
|
|
29
|
+
.map((record) => record.pkg.name);
|
|
30
|
+
|
|
31
|
+
expect(target.timestamp).toBe(expectedTimestamp);
|
|
32
|
+
expect(target.packages.map((pkg) => pkg.name)).toEqual(expectedPackages);
|
|
33
|
+
expect(target.npmPackages.map((pkg) => pkg.name)).toEqual(expectedNpmPackages);
|
|
34
|
+
expect(target.githubPackages.map((pkg) => pkg.name)).toEqual(expectedGithubPackages);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
expect(targets.map((target) => target.timestamp)).toEqual(
|
|
38
|
+
[...targets].map((target) => target.timestamp).sort((left, right) => right - left),
|
|
39
|
+
);
|
|
40
|
+
}),
|
|
41
|
+
{ numRuns: 300 },
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('repairs exactly the newest incomplete non-HEAD suffix in oldest-first order', () => {
|
|
46
|
+
fc.assert(
|
|
47
|
+
fc.property(
|
|
48
|
+
releaseRecords(),
|
|
49
|
+
fc.option(fc.constantFrom('commit-0', 'commit-1', 'commit-2', 'commit-3')),
|
|
50
|
+
(records, headSha) => {
|
|
51
|
+
const newestFirst = groupReleaseTargets(records);
|
|
52
|
+
const expected: string[] = [];
|
|
53
|
+
for (const target of newestFirst) {
|
|
54
|
+
if (target.sha === headSha) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (target.npmPackages.length === 0 && target.githubPackages.length === 0) {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
expected.push(target.sha);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const pending = pendingReleaseTargets(records, headSha ?? 'not-head');
|
|
64
|
+
expect(pending.map((target) => target.sha)).toEqual(expected.reverse());
|
|
65
|
+
expect(pending.some((target) => target.sha === headSha)).toBe(false);
|
|
66
|
+
for (const target of pending) {
|
|
67
|
+
expect(target.npmPackages.length + target.githubPackages.length).toBeGreaterThan(0);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
),
|
|
71
|
+
{ numRuns: 300 },
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('builds exactly npm-missing release packages and never builds GitHub-only repairs', () => {
|
|
76
|
+
fc.assert(
|
|
77
|
+
fc.property(packageSubset(), packageSubset(), (npmMissingPackages, githubMissingPackages) => {
|
|
78
|
+
const plan = planPublishActions({ releasePackages: packages, npmMissingPackages, githubMissingPackages });
|
|
79
|
+
|
|
80
|
+
expect(plan.buildProjects).toEqual(npmMissingPackages.map((pkg) => pkg.name));
|
|
81
|
+
expect(plan.publishPackages.map((action) => action.pkg.name)).toEqual(
|
|
82
|
+
npmMissingPackages.map((pkg) => pkg.name),
|
|
83
|
+
);
|
|
84
|
+
expect(plan.githubReleasePackages.map((pkg) => pkg.name)).toEqual(githubMissingPackages.map((pkg) => pkg.name));
|
|
85
|
+
for (const action of plan.publishPackages) {
|
|
86
|
+
expect(action.distTag).toBe(action.pkg.version.includes('-') ? 'next' : 'latest');
|
|
87
|
+
}
|
|
88
|
+
}),
|
|
89
|
+
{ numRuns: 300 },
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
function packageSubset(): fc.Arbitrary<ReleasePackageInfo[]> {
|
|
95
|
+
return fc.subarray(packages, { minLength: 0, maxLength: packages.length });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function releaseRecords(): fc.Arbitrary<ReleaseTagRecord[]> {
|
|
99
|
+
return fc
|
|
100
|
+
.array(
|
|
101
|
+
fc.record({
|
|
102
|
+
shaIndex: fc.integer({ min: 0, max: 3 }),
|
|
103
|
+
pkgIndex: fc.integer({ min: 0, max: packages.length - 1 }),
|
|
104
|
+
timestamp: fc.integer({ min: 1, max: 10_000 }),
|
|
105
|
+
needsNpmPublish: fc.boolean(),
|
|
106
|
+
needsGithubRelease: fc.boolean(),
|
|
107
|
+
}),
|
|
108
|
+
{ minLength: 1, maxLength: 12 },
|
|
109
|
+
)
|
|
110
|
+
.map((rows) => {
|
|
111
|
+
const seen = new Set<string>();
|
|
112
|
+
const records: ReleaseTagRecord[] = [];
|
|
113
|
+
for (const row of rows) {
|
|
114
|
+
const pkg = packages[row.pkgIndex];
|
|
115
|
+
if (!pkg) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const sha = `commit-${row.shaIndex}`;
|
|
119
|
+
const key = `${sha}:${pkg.name}`;
|
|
120
|
+
if (seen.has(key)) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
seen.add(key);
|
|
124
|
+
records.push({
|
|
125
|
+
tag: `${pkg.name}@${pkg.version}`,
|
|
126
|
+
sha,
|
|
127
|
+
timestamp: row.timestamp,
|
|
128
|
+
pkg,
|
|
129
|
+
needsNpmPublish: row.needsNpmPublish,
|
|
130
|
+
needsGithubRelease: row.needsGithubRelease,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return records.length > 0 ? records : [record(packages[0], 'commit-0')];
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function record(pkg: ReleasePackageInfo | undefined, sha: string): ReleaseTagRecord {
|
|
138
|
+
if (!pkg) {
|
|
139
|
+
throw new Error('Missing test package fixture.');
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
tag: `${pkg.name}@${pkg.version}`,
|
|
143
|
+
sha,
|
|
144
|
+
timestamp: 1,
|
|
145
|
+
pkg,
|
|
146
|
+
needsNpmPublish: false,
|
|
147
|
+
needsGithubRelease: false,
|
|
148
|
+
};
|
|
149
|
+
}
|