@smoothbricks/nx-plugin 0.4.15 โ 0.4.16
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 +17 -0
- package/dist/deploy-policy.d.ts +26 -0
- package/dist/deploy-policy.d.ts.map +1 -0
- package/dist/deploy-policy.js +36 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +153 -14
- package/dist/managed-assets.d.ts +3 -0
- package/dist/managed-assets.d.ts.map +1 -0
- package/dist/managed-assets.js +3 -0
- package/dist/managed-files/ci-workflow.d.ts +215 -0
- package/dist/managed-files/ci-workflow.d.ts.map +1 -0
- package/dist/managed-files/ci-workflow.js +1082 -0
- package/dist/managed-files/context.d.ts +51 -0
- package/dist/managed-files/context.d.ts.map +1 -0
- package/dist/managed-files/context.js +206 -0
- package/dist/managed-files/files.d.ts +53 -0
- package/dist/managed-files/files.d.ts.map +1 -0
- package/dist/managed-files/files.js +248 -0
- package/dist/managed-files/generator.d.ts +16 -0
- package/dist/managed-files/generator.d.ts.map +1 -0
- package/dist/managed-files/generator.js +41 -0
- package/dist/managed-files/github-runs-on.d.ts +19 -0
- package/dist/managed-files/github-runs-on.d.ts.map +1 -0
- package/dist/managed-files/github-runs-on.js +48 -0
- package/dist/managed-files/managed-content.d.ts +45 -0
- package/dist/managed-files/managed-content.d.ts.map +1 -0
- package/dist/managed-files/managed-content.js +102 -0
- package/dist/managed-files/managed-format.d.ts +37 -0
- package/dist/managed-files/managed-format.d.ts.map +1 -0
- package/dist/managed-files/managed-format.js +94 -0
- package/dist/managed-files/paths.d.ts +8 -0
- package/dist/managed-files/paths.d.ts.map +1 -0
- package/dist/managed-files/paths.js +46 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +5 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.js +38 -0
- package/dist/managed-files/private-npm-policy.d.ts +7 -0
- package/dist/managed-files/private-npm-policy.d.ts.map +1 -0
- package/dist/managed-files/private-npm-policy.js +51 -0
- package/dist/managed-files/publish-workflow.d.ts +150 -0
- package/dist/managed-files/publish-workflow.d.ts.map +1 -0
- package/dist/managed-files/publish-workflow.js +989 -0
- package/dist/managed-files/tree.d.ts +30 -0
- package/dist/managed-files/tree.d.ts.map +1 -0
- package/dist/managed-files/tree.js +91 -0
- package/dist/platform-targets.d.ts +5 -0
- package/dist/platform-targets.d.ts.map +1 -0
- package/dist/platform-targets.js +4 -0
- package/dist/typecheck-test-policy.d.ts +5 -9
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +69 -99
- package/dist/workspace-config-policy.d.ts +2 -3
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +8 -3
- package/dist/workspace-manifest.d.ts +291 -0
- package/dist/workspace-manifest.d.ts.map +1 -0
- package/dist/workspace-manifest.js +6 -0
- package/dist/workspace-package-policy.d.ts +13 -0
- package/dist/workspace-package-policy.d.ts.map +1 -0
- package/dist/workspace-package-policy.js +24 -0
- package/generators.json +5 -0
- package/managed/raw/envrc +20 -0
- package/managed/raw/git-format-staged.yml +82 -0
- package/managed/raw/gitattributes +8 -0
- package/managed/raw/tooling/devenv +83 -0
- package/managed/raw/tooling/direnv/devenv.smoo.nix +422 -0
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +251 -0
- package/managed/raw/tooling/direnv/merge-newer-pins.sh +48 -0
- package/managed/raw/tooling/direnv/repo-path +34 -0
- package/managed/raw/tooling/direnv/secret-references.ts +636 -0
- package/managed/raw/tooling/direnv/setup-environment.ts +585 -0
- package/managed/raw/tooling/direnv/toolchain-stamp.ts +88 -0
- package/managed/raw/tooling/git-hooks/commit-msg.sh +9 -0
- package/managed/raw/tooling/git-hooks/post-commit.sh +71 -0
- package/managed/raw/tooling/git-hooks/pre-commit.sh +18 -0
- package/managed/raw/tooling/git-hooks/pre-push.sh +48 -0
- package/managed/raw/tsconfig.lib.json +28 -0
- package/managed/templates/github/actions/cache-nix-devenv/action.yml +45 -0
- package/managed/templates/github/actions/cache-node-modules/action.yml +17 -0
- package/managed/templates/github/actions/cache-nx/action.yml +21 -0
- package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +19 -0
- package/managed/templates/github/actions/save-nix-devenv/action.yml +32 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +241 -0
- package/managed/templates/github/workflows/managed-files.yml +127 -0
- package/package.json +89 -5
- package/src/bun-bootstrap.test.ts +0 -6
- package/src/deploy-policy.ts +40 -0
- package/src/index.test.ts +225 -2
- package/src/index.ts +180 -14
- package/src/managed-assets.ts +4 -0
- package/src/managed-files/ci-workflow.ts +1365 -0
- package/src/managed-files/context.ts +240 -0
- package/src/managed-files/files.ts +324 -0
- package/src/managed-files/generator.test.ts +151 -0
- package/src/managed-files/generator.ts +60 -0
- package/src/managed-files/github-runs-on.ts +51 -0
- package/src/managed-files/managed-content.test.ts +147 -0
- package/src/managed-files/managed-content.ts +121 -0
- package/src/managed-files/managed-format.ts +102 -0
- package/src/managed-files/paths.ts +44 -0
- package/src/managed-files/pr-preview-cleanup-workflow.ts +44 -0
- package/src/managed-files/private-npm-policy.ts +62 -0
- package/src/managed-files/publish-workflow.ts +1523 -0
- package/src/managed-files/schema.json +8 -0
- package/src/managed-files/tree-permissions.test.ts +109 -0
- package/src/managed-files/tree.test.ts +123 -0
- package/src/managed-files/tree.ts +118 -0
- package/src/platform-targets.ts +4 -0
- package/src/typecheck-test-policy.test.ts +28 -3
- package/src/typecheck-test-policy.ts +46 -121
- package/src/workspace-config-policy.test.ts +14 -2
- package/src/workspace-config-policy.ts +9 -3
- package/src/workspace-manifest.ts +327 -0
- package/src/workspace-package-policy.ts +32 -0
|
@@ -0,0 +1,989 @@
|
|
|
1
|
+
/* biome-ignore-all lint/suspicious/noTemplateCurlyInString: GitHub Actions expressions are emitted literally. */
|
|
2
|
+
import { LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS } from '../platform-targets.js';
|
|
3
|
+
import { isSmoothBricksCodebasePackageName } from '../workspace-package-policy.js';
|
|
4
|
+
import { artifactStepLines, CiWorkflowStepKind, cargoCredentialJobEnvLines, cargoCredentialStepLines, deployStepSecretEnvLines, remoteCacheJobEnvLines, sourceCheckoutsStepLines, } from './ci-workflow.js';
|
|
5
|
+
import { GITHUB_HOSTED_LINUX_RUNNER, renderRunsOnLine } from './github-runs-on.js';
|
|
6
|
+
export var PublishWorkflowStepKind;
|
|
7
|
+
(function (PublishWorkflowStepKind) {
|
|
8
|
+
PublishWorkflowStepKind["Checkout"] = "checkout";
|
|
9
|
+
PublishWorkflowStepKind["SourceCheckouts"] = "source-checkouts";
|
|
10
|
+
PublishWorkflowStepKind["CargoCredentials"] = "cargo-credentials";
|
|
11
|
+
PublishWorkflowStepKind["SetupDevenv"] = "setup-devenv";
|
|
12
|
+
PublishWorkflowStepKind["ConfigureReleaseAuthor"] = "configure-release-author";
|
|
13
|
+
PublishWorkflowStepKind["BuildNxVersionActions"] = "build-nx-version-actions";
|
|
14
|
+
PublishWorkflowStepKind["RepairPendingReleases"] = "repair-pending-releases";
|
|
15
|
+
PublishWorkflowStepKind["PlanRelease"] = "plan-release";
|
|
16
|
+
PublishWorkflowStepKind["VersionRelease"] = "version-release";
|
|
17
|
+
PublishWorkflowStepKind["CheckManagedMonorepoFiles"] = "check-managed-monorepo-files";
|
|
18
|
+
PublishWorkflowStepKind["Build"] = "build";
|
|
19
|
+
PublishWorkflowStepKind["Lint"] = "lint";
|
|
20
|
+
PublishWorkflowStepKind["UnitTests"] = "unit-tests";
|
|
21
|
+
PublishWorkflowStepKind["UploadTraceDbs"] = "upload-trace-dbs";
|
|
22
|
+
PublishWorkflowStepKind["ValidateMonorepoConfig"] = "validate-monorepo-config";
|
|
23
|
+
PublishWorkflowStepKind["TagRelease"] = "tag-release";
|
|
24
|
+
PublishWorkflowStepKind["PublishRelease"] = "publish-release";
|
|
25
|
+
PublishWorkflowStepKind["DeployProduction"] = "deploy-production";
|
|
26
|
+
PublishWorkflowStepKind["SaveNixDevenv"] = "save-nix-devenv";
|
|
27
|
+
})(PublishWorkflowStepKind || (PublishWorkflowStepKind = {}));
|
|
28
|
+
export function definePublishWorkflow(options = {}) {
|
|
29
|
+
const versionMode = githubExpression('steps.version.outputs.mode');
|
|
30
|
+
// Steps that run before the bump must label themselves from the plan: the
|
|
31
|
+
// version step's outputs do not exist yet, so the interpolation renders empty.
|
|
32
|
+
const planMode = githubExpression('steps.plan.outputs.mode');
|
|
33
|
+
if (options.release === false) {
|
|
34
|
+
return { steps: defineDeployOnlyWorkflowSteps(options) };
|
|
35
|
+
}
|
|
36
|
+
const setupSteps = [
|
|
37
|
+
{ kind: PublishWorkflowStepKind.Checkout, name: '๐ฅ Checkout' },
|
|
38
|
+
...(options.cargoCredentials !== undefined
|
|
39
|
+
? [{ kind: PublishWorkflowStepKind.CargoCredentials, name: CARGO_CREDENTIALS_STEP_NAME }]
|
|
40
|
+
: []),
|
|
41
|
+
...(options.sourceCheckouts?.length
|
|
42
|
+
? [{ kind: PublishWorkflowStepKind.SourceCheckouts, name: '๐ฆ Check out sibling sources' }]
|
|
43
|
+
: []),
|
|
44
|
+
{ kind: PublishWorkflowStepKind.SetupDevenv, name: '๐งฑ Setup Nix/devenv', id: 'setup' },
|
|
45
|
+
{ kind: PublishWorkflowStepKind.ConfigureReleaseAuthor, name: '๐ค Configure release author' },
|
|
46
|
+
];
|
|
47
|
+
if (isSmoothBricksCodebasePackageName(options.repoName)) {
|
|
48
|
+
setupSteps.push({
|
|
49
|
+
kind: PublishWorkflowStepKind.BuildNxVersionActions,
|
|
50
|
+
name: '๐๏ธ Build smoo Nx version actions',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const releaseSteps = [
|
|
54
|
+
{ kind: PublishWorkflowStepKind.TagRelease, name: '๐ท๏ธ Tag release' },
|
|
55
|
+
{
|
|
56
|
+
kind: PublishWorkflowStepKind.PublishRelease,
|
|
57
|
+
name: `๐ฆ Publish release (${versionMode})`,
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
if (options.deploy === true) {
|
|
61
|
+
releaseSteps.push({
|
|
62
|
+
kind: PublishWorkflowStepKind.DeployProduction,
|
|
63
|
+
name: '๐ Deploy production',
|
|
64
|
+
condition: 'deploy-production',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
steps: numberWorkflowSteps([
|
|
69
|
+
...setupSteps,
|
|
70
|
+
{
|
|
71
|
+
kind: PublishWorkflowStepKind.RepairPendingReleases,
|
|
72
|
+
name: '๐งฏ Repair pending releases',
|
|
73
|
+
},
|
|
74
|
+
// Plan first, gate second, bump third. Lint and test hash the source, so
|
|
75
|
+
// running them BEFORE the version commit means their task hashes match
|
|
76
|
+
// the ones ci already computed for the same source โ the publish reuses
|
|
77
|
+
// that cache instead of re-running 189 tasks. Build stays after the bump
|
|
78
|
+
// on purpose: an artifact built from pre-bump sources would ship the
|
|
79
|
+
// previous version string.
|
|
80
|
+
{ kind: PublishWorkflowStepKind.PlanRelease, name: '๐งญ Plan release', id: 'plan' },
|
|
81
|
+
{
|
|
82
|
+
kind: PublishWorkflowStepKind.CheckManagedMonorepoFiles,
|
|
83
|
+
name: `โ
Check managed monorepo files (${planMode})`,
|
|
84
|
+
condition: 'plan-mode-not-none',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
kind: PublishWorkflowStepKind.Lint,
|
|
88
|
+
name: `๐ Lint (${planMode})`,
|
|
89
|
+
condition: 'plan-mode-not-none',
|
|
90
|
+
nxTarget: 'lint',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
kind: PublishWorkflowStepKind.UnitTests,
|
|
94
|
+
name: `๐งช Unit Tests (${planMode})`,
|
|
95
|
+
condition: 'plan-mode-not-none',
|
|
96
|
+
nxTarget: 'test',
|
|
97
|
+
},
|
|
98
|
+
{ kind: PublishWorkflowStepKind.VersionRelease, name: '๐ข Version release', id: 'version' },
|
|
99
|
+
{
|
|
100
|
+
kind: PublishWorkflowStepKind.Build,
|
|
101
|
+
name: `๐จ Build (${versionMode})`,
|
|
102
|
+
condition: 'version-mode-not-none',
|
|
103
|
+
nxTarget: 'build',
|
|
104
|
+
},
|
|
105
|
+
{ kind: PublishWorkflowStepKind.UploadTraceDbs, name: '๐ Upload trace DBs', condition: 'failure' },
|
|
106
|
+
{
|
|
107
|
+
kind: PublishWorkflowStepKind.ValidateMonorepoConfig,
|
|
108
|
+
name: `โ
Validate monorepo config (${versionMode})`,
|
|
109
|
+
condition: 'version-mode-not-none',
|
|
110
|
+
},
|
|
111
|
+
...releaseSteps,
|
|
112
|
+
{
|
|
113
|
+
kind: PublishWorkflowStepKind.SaveNixDevenv,
|
|
114
|
+
name: '๐งน Cleanup and cache Nix/devenv',
|
|
115
|
+
condition: 'always',
|
|
116
|
+
},
|
|
117
|
+
]),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Repos that deploy but own no release packages. Build, lint and test are not
|
|
122
|
+
* dropped safety: `nx-deploy --verify` runs all three before it deploys.
|
|
123
|
+
*/
|
|
124
|
+
function defineDeployOnlyWorkflowSteps(options) {
|
|
125
|
+
return numberWorkflowSteps([
|
|
126
|
+
{ kind: PublishWorkflowStepKind.Checkout, name: '๐ฅ Checkout' },
|
|
127
|
+
...(options.cargoCredentials !== undefined
|
|
128
|
+
? [{ kind: PublishWorkflowStepKind.CargoCredentials, name: CARGO_CREDENTIALS_STEP_NAME }]
|
|
129
|
+
: []),
|
|
130
|
+
...(options.sourceCheckouts?.length
|
|
131
|
+
? [{ kind: PublishWorkflowStepKind.SourceCheckouts, name: '๐ฆ Check out sibling sources' }]
|
|
132
|
+
: []),
|
|
133
|
+
{ kind: PublishWorkflowStepKind.SetupDevenv, name: '๐งฑ Setup Nix/devenv', id: 'setup' },
|
|
134
|
+
{
|
|
135
|
+
kind: PublishWorkflowStepKind.DeployProduction,
|
|
136
|
+
name: '๐ Deploy production',
|
|
137
|
+
condition: 'deploy-production-standalone',
|
|
138
|
+
},
|
|
139
|
+
{ kind: PublishWorkflowStepKind.UploadTraceDbs, name: '๐ Upload trace DBs', condition: 'failure' },
|
|
140
|
+
{
|
|
141
|
+
kind: PublishWorkflowStepKind.SaveNixDevenv,
|
|
142
|
+
name: '๐งน Cleanup and cache Nix/devenv',
|
|
143
|
+
condition: 'always',
|
|
144
|
+
},
|
|
145
|
+
]);
|
|
146
|
+
}
|
|
147
|
+
function numberWorkflowSteps(steps) {
|
|
148
|
+
return steps.map((step, index) => ({ ...step, number: index + 2 }));
|
|
149
|
+
}
|
|
150
|
+
export async function runPublishWorkflow(workflow, context) {
|
|
151
|
+
let setupOutputs = { nixCacheHit: '', devenvCacheHit: '' };
|
|
152
|
+
let version = { mode: 'none', projects: [] };
|
|
153
|
+
let plan = { mode: 'none', projects: [] };
|
|
154
|
+
let failed = false;
|
|
155
|
+
let failure;
|
|
156
|
+
for (const step of workflow.steps) {
|
|
157
|
+
if (!shouldRunStep(step, version, failed, context.inputs, plan)) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
switch (step.kind) {
|
|
162
|
+
case PublishWorkflowStepKind.Checkout:
|
|
163
|
+
await context.callbacks.checkout();
|
|
164
|
+
break;
|
|
165
|
+
case PublishWorkflowStepKind.SourceCheckouts:
|
|
166
|
+
case PublishWorkflowStepKind.CargoCredentials:
|
|
167
|
+
// The generated job runs these setup shells; runtime simulation has no callback.
|
|
168
|
+
break;
|
|
169
|
+
case PublishWorkflowStepKind.SetupDevenv:
|
|
170
|
+
setupOutputs = await context.callbacks.setupDevenv();
|
|
171
|
+
break;
|
|
172
|
+
case PublishWorkflowStepKind.ConfigureReleaseAuthor:
|
|
173
|
+
await context.callbacks.configureReleaseAuthor();
|
|
174
|
+
break;
|
|
175
|
+
case PublishWorkflowStepKind.BuildNxVersionActions:
|
|
176
|
+
await context.callbacks.buildNxVersionActions();
|
|
177
|
+
break;
|
|
178
|
+
case PublishWorkflowStepKind.RepairPendingReleases:
|
|
179
|
+
await context.callbacks.repairPendingReleases({
|
|
180
|
+
dryRun: context.inputs.dryRun,
|
|
181
|
+
});
|
|
182
|
+
break;
|
|
183
|
+
case PublishWorkflowStepKind.PlanRelease:
|
|
184
|
+
plan = context.callbacks.planRelease
|
|
185
|
+
? await context.callbacks.planRelease({ bump: context.inputs.bump })
|
|
186
|
+
: await context.callbacks.versionRelease({ bump: context.inputs.bump, dryRun: true });
|
|
187
|
+
break;
|
|
188
|
+
case PublishWorkflowStepKind.VersionRelease:
|
|
189
|
+
version = await context.callbacks.versionRelease(context.inputs);
|
|
190
|
+
break;
|
|
191
|
+
case PublishWorkflowStepKind.CheckManagedMonorepoFiles:
|
|
192
|
+
await context.callbacks.checkManagedMonorepoFiles();
|
|
193
|
+
break;
|
|
194
|
+
case PublishWorkflowStepKind.Build:
|
|
195
|
+
case PublishWorkflowStepKind.Lint:
|
|
196
|
+
case PublishWorkflowStepKind.UnitTests:
|
|
197
|
+
if (!step.nxTarget) {
|
|
198
|
+
throw new Error(`Workflow step ${step.kind} is missing an Nx target.`);
|
|
199
|
+
}
|
|
200
|
+
// Lint and test run before the bump exists, so they select from the
|
|
201
|
+
// plan; build runs after it and selects from the written version.
|
|
202
|
+
await context.callbacks.nxRunMany({
|
|
203
|
+
target: step.nxTarget,
|
|
204
|
+
projects: step.kind === PublishWorkflowStepKind.Build ? version.projects : plan.projects,
|
|
205
|
+
});
|
|
206
|
+
break;
|
|
207
|
+
case PublishWorkflowStepKind.UploadTraceDbs:
|
|
208
|
+
await context.callbacks.uploadTraceDbs();
|
|
209
|
+
break;
|
|
210
|
+
case PublishWorkflowStepKind.ValidateMonorepoConfig:
|
|
211
|
+
await context.callbacks.validateMonorepoConfig();
|
|
212
|
+
break;
|
|
213
|
+
case PublishWorkflowStepKind.TagRelease:
|
|
214
|
+
await context.callbacks.tagRelease({ dryRun: context.inputs.dryRun });
|
|
215
|
+
break;
|
|
216
|
+
case PublishWorkflowStepKind.PublishRelease:
|
|
217
|
+
await context.callbacks.publishRelease({
|
|
218
|
+
bump: context.inputs.bump,
|
|
219
|
+
dryRun: context.inputs.dryRun,
|
|
220
|
+
});
|
|
221
|
+
break;
|
|
222
|
+
case PublishWorkflowStepKind.DeployProduction:
|
|
223
|
+
await context.callbacks.deployProduction();
|
|
224
|
+
break;
|
|
225
|
+
case PublishWorkflowStepKind.SaveNixDevenv:
|
|
226
|
+
await context.callbacks.saveNixDevenv(setupOutputs);
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
failed = true;
|
|
232
|
+
failure = error;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (failure) {
|
|
236
|
+
throw failure;
|
|
237
|
+
}
|
|
238
|
+
return { version, failed };
|
|
239
|
+
}
|
|
240
|
+
function shouldRunStep(step, version, failed, inputs, plan = version) {
|
|
241
|
+
if (step.condition === 'plan-mode-not-none') {
|
|
242
|
+
return plan.mode !== 'none';
|
|
243
|
+
}
|
|
244
|
+
if (step.condition === 'version-mode-not-none') {
|
|
245
|
+
return version.mode !== 'none';
|
|
246
|
+
}
|
|
247
|
+
if (step.condition === 'deploy-production') {
|
|
248
|
+
return version.mode !== 'none' && inputs.deployStage === 'production' && !inputs.dryRun;
|
|
249
|
+
}
|
|
250
|
+
if (step.condition === 'deploy-production-standalone') {
|
|
251
|
+
return inputs.deployStage === 'production' && !inputs.dryRun;
|
|
252
|
+
}
|
|
253
|
+
if (step.condition === 'failure') {
|
|
254
|
+
return failed;
|
|
255
|
+
}
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* The workflow as this generator composes it. The consumer's own formatter has
|
|
260
|
+
* the last word on the bytes that land on disk โ see `formatManagedContent` โ
|
|
261
|
+
* so nothing here encodes one repository's Prettier preferences.
|
|
262
|
+
*/
|
|
263
|
+
export function renderPublishWorkflowYaml(options = {}) {
|
|
264
|
+
if (options.release === false) {
|
|
265
|
+
return `${renderPublishWorkflowHeader(options)}${renderPublishWorkflowSteps(definePublishWorkflow(options).steps, options)}`;
|
|
266
|
+
}
|
|
267
|
+
if (hasMacosPlatformTargets(options) && !skipsPublishHandoff(options)) {
|
|
268
|
+
return renderPlatformPublishWorkflowYaml(options);
|
|
269
|
+
}
|
|
270
|
+
// A linux-cross producer runs the Apple targets on the publisher's own
|
|
271
|
+
// runner. Splitting jobs then buys nothing and costs a real transfer: the
|
|
272
|
+
// outputs get tarred, uploaded, downloaded into a second checkout, and two
|
|
273
|
+
// more devenv setups pay for themselves twice. One job, no artifacts.
|
|
274
|
+
if (hasMacosPlatformTargets(options) || hasLinuxPlatformTargets(options)) {
|
|
275
|
+
return `${renderPublishWorkflowHeader(options)}${renderSingleJobPublishWorkflowSteps(definePublishWorkflow(options).steps, options)}`;
|
|
276
|
+
}
|
|
277
|
+
return `${renderPublishWorkflowHeader(options)}${renderPublishWorkflowSteps(definePublishWorkflow(options).steps, options)}`;
|
|
278
|
+
}
|
|
279
|
+
function renderPublishWorkflowHeader(options) {
|
|
280
|
+
const dryRunDescription = options.release === false
|
|
281
|
+
? 'Skip the deploy and report what would run.'
|
|
282
|
+
: 'Run release commands without writing versions, tags, publishes, or GitHub Releases.';
|
|
283
|
+
const bumpInput = options.release === false
|
|
284
|
+
? ''
|
|
285
|
+
: `
|
|
286
|
+
bump:
|
|
287
|
+
type: choice
|
|
288
|
+
description:
|
|
289
|
+
Use auto for conventional commits, or force a semver bump. Prerelease publishes to next; all others publish to
|
|
290
|
+
latest.
|
|
291
|
+
options: [auto, patch, minor, major, prerelease]
|
|
292
|
+
default: auto
|
|
293
|
+
projects:
|
|
294
|
+
type: string
|
|
295
|
+
description:
|
|
296
|
+
Comma-separated Nx projects to release, or all for every owned release package. Blank releases package-local
|
|
297
|
+
changes since the last release, whatever the bump mode is.
|
|
298
|
+
default: ''`;
|
|
299
|
+
const deployInput = options.deploy === true
|
|
300
|
+
? `
|
|
301
|
+
deploy_stage:
|
|
302
|
+
type: choice
|
|
303
|
+
description: Deploy live systems after a successful publish.
|
|
304
|
+
options: [none, production]
|
|
305
|
+
default: none`
|
|
306
|
+
: '';
|
|
307
|
+
return `name: Publish
|
|
308
|
+
|
|
309
|
+
on:
|
|
310
|
+
workflow_dispatch:
|
|
311
|
+
inputs:${bumpInput}
|
|
312
|
+
dry_run:
|
|
313
|
+
type: boolean
|
|
314
|
+
description: ${dryRunDescription}
|
|
315
|
+
default: false${deployInput}
|
|
316
|
+
|
|
317
|
+
permissions:
|
|
318
|
+
contents: write
|
|
319
|
+
id-token: write
|
|
320
|
+
|
|
321
|
+
concurrency:
|
|
322
|
+
group: release-${githubExpression('github.ref')}
|
|
323
|
+
cancel-in-progress: false
|
|
324
|
+
|
|
325
|
+
defaults:
|
|
326
|
+
run:
|
|
327
|
+
working-directory: tooling/direnv
|
|
328
|
+
|
|
329
|
+
jobs:
|
|
330
|
+
publish:
|
|
331
|
+
${options.release === false ? renderRunsOnLine(options.runsOn) : publishJobRunsOnLine(options)}
|
|
332
|
+
env:
|
|
333
|
+
GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options)}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}${platformProducerJobEnv(options)}
|
|
334
|
+
steps:
|
|
335
|
+
`;
|
|
336
|
+
}
|
|
337
|
+
function renderPublishWorkflowSteps(steps, options) {
|
|
338
|
+
const lines = [];
|
|
339
|
+
for (const step of steps) {
|
|
340
|
+
lines.push(...sectionLinesBefore(step));
|
|
341
|
+
lines.push(...commentLinesForStep(step));
|
|
342
|
+
lines.push(...yamlLinesForStep(step, options));
|
|
343
|
+
lines.push('');
|
|
344
|
+
}
|
|
345
|
+
return `${lines.join('\n').trimEnd()}\n`;
|
|
346
|
+
}
|
|
347
|
+
function sectionLinesBefore(step) {
|
|
348
|
+
if (step.kind === PublishWorkflowStepKind.Checkout) {
|
|
349
|
+
return [' # --- Setup --------------------------------------------------------------', ''];
|
|
350
|
+
}
|
|
351
|
+
if (step.kind === PublishWorkflowStepKind.CheckManagedMonorepoFiles) {
|
|
352
|
+
return [
|
|
353
|
+
' # --- Validation ---------------------------------------------------------',
|
|
354
|
+
'',
|
|
355
|
+
' # Release validation intentionally does not restore persisted Nx task',
|
|
356
|
+
' # cache. Nx may reuse tasks produced earlier in this same job, but publish',
|
|
357
|
+
' # never relies on task outputs restored from CI cache. version runs before',
|
|
358
|
+
' # validation so the commit completed below is the commit that was checked.',
|
|
359
|
+
'',
|
|
360
|
+
];
|
|
361
|
+
}
|
|
362
|
+
if (step.kind === PublishWorkflowStepKind.TagRelease) {
|
|
363
|
+
return [' # --- Release ------------------------------------------------------------', ''];
|
|
364
|
+
}
|
|
365
|
+
if (step.kind === PublishWorkflowStepKind.SaveNixDevenv) {
|
|
366
|
+
return [' # --- Cleanup ------------------------------------------------------------', ''];
|
|
367
|
+
}
|
|
368
|
+
return [];
|
|
369
|
+
}
|
|
370
|
+
function commentLinesForStep(step) {
|
|
371
|
+
if (step.kind === PublishWorkflowStepKind.Checkout) {
|
|
372
|
+
return [' # Step 1: GitHub adds "Set up job" automatically', ' # Step 2'];
|
|
373
|
+
}
|
|
374
|
+
if (step.kind === PublishWorkflowStepKind.SetupDevenv) {
|
|
375
|
+
return [
|
|
376
|
+
` # Step ${step.number}. Composite action internals do not affect top-level job step`,
|
|
377
|
+
' # anchors; update these comments if top-level steps move.',
|
|
378
|
+
];
|
|
379
|
+
}
|
|
380
|
+
return [` # Step ${step.number}`];
|
|
381
|
+
}
|
|
382
|
+
function yamlLinesForStep(step, options) {
|
|
383
|
+
switch (step.kind) {
|
|
384
|
+
case PublishWorkflowStepKind.Checkout:
|
|
385
|
+
return [
|
|
386
|
+
` - name: ${step.name}`,
|
|
387
|
+
' uses: actions/checkout@v6.0.2',
|
|
388
|
+
' with:',
|
|
389
|
+
' filter: blob:none',
|
|
390
|
+
' fetch-depth: 0',
|
|
391
|
+
];
|
|
392
|
+
case PublishWorkflowStepKind.SourceCheckouts:
|
|
393
|
+
return siblingSourceCheckoutStepLines(options);
|
|
394
|
+
case PublishWorkflowStepKind.CargoCredentials:
|
|
395
|
+
return cargoCredentialsStepLines(options);
|
|
396
|
+
case PublishWorkflowStepKind.SetupDevenv:
|
|
397
|
+
return [` - name: ${step.name}`, ' id: setup', ' uses: ./.github/actions/setup-devenv'];
|
|
398
|
+
case PublishWorkflowStepKind.ConfigureReleaseAuthor:
|
|
399
|
+
return [
|
|
400
|
+
` - name: ${step.name}`,
|
|
401
|
+
' run:',
|
|
402
|
+
' git config user.name "github-actions[bot]" && git config user.email',
|
|
403
|
+
' "41898282+github-actions[bot]@users.noreply.github.com"',
|
|
404
|
+
];
|
|
405
|
+
case PublishWorkflowStepKind.BuildNxVersionActions:
|
|
406
|
+
return [
|
|
407
|
+
` - name: ${step.name}`,
|
|
408
|
+
' # Nx Release loads @smoothbricks/nx-plugin/version-actions through the',
|
|
409
|
+
' # export map in its own node process, and versioning runs before the',
|
|
410
|
+
' # build phase, so the hook must exist in dist first. Downstream',
|
|
411
|
+
' # consumers install the published package and skip this bootstrap.',
|
|
412
|
+
' #',
|
|
413
|
+
' # `nx` cannot do it: the project graph loads this very plugin, so',
|
|
414
|
+
' # `nx build nx-plugin` deadlocks on the executor it is building.',
|
|
415
|
+
' # ttsc needs only the package tsconfig -- same bootstrap the devenv',
|
|
416
|
+
' # shell runs (tooling/direnv/enter-shell.ts).',
|
|
417
|
+
' working-directory: packages/nx-plugin',
|
|
418
|
+
' run: ttsc -p tsconfig.lib.json --emit',
|
|
419
|
+
];
|
|
420
|
+
case PublishWorkflowStepKind.RepairPendingReleases:
|
|
421
|
+
return [
|
|
422
|
+
` - name: ${step.name}`,
|
|
423
|
+
...privateNpmPublisherStepEnv(options),
|
|
424
|
+
` run: smoo release repair-pending --dry-run "${githubExpression('inputs.dry_run')}"`,
|
|
425
|
+
];
|
|
426
|
+
case PublishWorkflowStepKind.PlanRelease:
|
|
427
|
+
// The same selection the bump will make, computed without writing: the
|
|
428
|
+
// gates need `mode` and `projects` before any version commit exists.
|
|
429
|
+
return [
|
|
430
|
+
` - name: ${step.name}`,
|
|
431
|
+
' id: plan',
|
|
432
|
+
' run:',
|
|
433
|
+
` smoo release version --bump "${githubExpression('inputs.bump')}" --projects "${githubExpression('inputs.projects')}" --dry-run "true" --github-output`,
|
|
434
|
+
' "$GITHUB_OUTPUT"',
|
|
435
|
+
];
|
|
436
|
+
case PublishWorkflowStepKind.VersionRelease:
|
|
437
|
+
return [
|
|
438
|
+
` - name: ${step.name}`,
|
|
439
|
+
' id: version',
|
|
440
|
+
' run:',
|
|
441
|
+
` smoo release version --bump "${githubExpression('inputs.bump')}" --projects "${githubExpression('inputs.projects')}" --dry-run "${githubExpression('inputs.dry_run')}" --github-output`,
|
|
442
|
+
' "$GITHUB_OUTPUT"',
|
|
443
|
+
];
|
|
444
|
+
case PublishWorkflowStepKind.CheckManagedMonorepoFiles:
|
|
445
|
+
// Drift is derived state with its own remediation PR; publishing only
|
|
446
|
+
// blocks on actual package issues (smoo monorepo validate).
|
|
447
|
+
return conditionalRunStep(step, 'smoo monorepo check --warn');
|
|
448
|
+
case PublishWorkflowStepKind.Build:
|
|
449
|
+
return conditionalRunStep(step, `smoo github-ci nx-run-many --targets build --projects "${githubExpression('steps.version.outputs.projects')}"`);
|
|
450
|
+
case PublishWorkflowStepKind.Lint:
|
|
451
|
+
return conditionalRunStep(step, `smoo github-ci nx-run-many --targets lint --projects "${githubExpression('steps.plan.outputs.projects')}"`);
|
|
452
|
+
case PublishWorkflowStepKind.UnitTests:
|
|
453
|
+
return conditionalRunStep(step, `smoo github-ci nx-run-many --targets test --projects "${githubExpression('steps.plan.outputs.projects')}"`);
|
|
454
|
+
case PublishWorkflowStepKind.UploadTraceDbs:
|
|
455
|
+
return artifactStepLines(options.actionsProvider, step.name, 'upload', [
|
|
456
|
+
`name: trace-results-${githubExpression('github.run_id')}`,
|
|
457
|
+
'path: packages/*/.cache/trace-results.db*',
|
|
458
|
+
'if-no-files-found: ignore',
|
|
459
|
+
'retention-days: 14',
|
|
460
|
+
'include-hidden-files: true',
|
|
461
|
+
], 'failure()');
|
|
462
|
+
case PublishWorkflowStepKind.ValidateMonorepoConfig:
|
|
463
|
+
// Scoped to the release's candidates: the build phase and the packed-package
|
|
464
|
+
// checks cover what ships. Unscoped, validate compiled every project - on a
|
|
465
|
+
// release touching no Rust that was 3m30 of the cowshed CLI on the critical
|
|
466
|
+
// path, for a binary the release did not contain.
|
|
467
|
+
return conditionalRunStep(step, `smoo monorepo validate --projects "${githubExpression('steps.version.outputs.projects')}"`);
|
|
468
|
+
case PublishWorkflowStepKind.TagRelease:
|
|
469
|
+
return tagReleaseStepLines(step.name);
|
|
470
|
+
case PublishWorkflowStepKind.PublishRelease:
|
|
471
|
+
return [
|
|
472
|
+
` - name: ${step.name}`,
|
|
473
|
+
...privateNpmPublisherStepEnv(options),
|
|
474
|
+
...(options.privateNpm
|
|
475
|
+
? [' # Private publication uses the declared registry and step-scoped publisher credential.']
|
|
476
|
+
: [
|
|
477
|
+
' # smoo packs with Bun, then publishes tarballs with npm. Existing',
|
|
478
|
+
' # packages must already exist on npm and use trusted publishing/OIDC.',
|
|
479
|
+
' # Missing package names are bootstrapped locally before trust setup.',
|
|
480
|
+
]),
|
|
481
|
+
` run: smoo release publish --bump "${githubExpression('inputs.bump')}" --dry-run "${githubExpression('inputs.dry_run')}"`,
|
|
482
|
+
];
|
|
483
|
+
case PublishWorkflowStepKind.DeployProduction:
|
|
484
|
+
return deployProductionStep(step, options);
|
|
485
|
+
case PublishWorkflowStepKind.SaveNixDevenv:
|
|
486
|
+
return [
|
|
487
|
+
` - name: ${step.name}`,
|
|
488
|
+
' # success() is default; always() still saves GH Nix cache after a red job.',
|
|
489
|
+
' if: always()',
|
|
490
|
+
' uses: ./.github/actions/save-nix-devenv',
|
|
491
|
+
' with:',
|
|
492
|
+
` devenv-cache-hit: ${githubExpression('steps.setup.outputs.devenv-cache-hit')}`,
|
|
493
|
+
];
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* The one place release tags come into existence. Release candidates version
|
|
498
|
+
* without tagging, so a candidate that fails Build, Lint, or Unit Tests leaves
|
|
499
|
+
* no ref behind and the next run recomputes the same version cleanly. Tagging
|
|
500
|
+
* here โ after validation, immediately before the npm publish โ preserves the
|
|
501
|
+
* "tagged but not published" state that `smoo release repair-pending`
|
|
502
|
+
* reconciles, because git and npm cannot be written atomically.
|
|
503
|
+
*/
|
|
504
|
+
function tagReleaseStepLines(name) {
|
|
505
|
+
return [
|
|
506
|
+
` - name: ${name}`,
|
|
507
|
+
' # Ordered before the publish below so an interrupted release stays',
|
|
508
|
+
' # detectable by the repair step at the top of this job on a later run.',
|
|
509
|
+
` run: smoo release tag --dry-run "${githubExpression('inputs.dry_run')}"`,
|
|
510
|
+
];
|
|
511
|
+
}
|
|
512
|
+
function deployProductionStep(step, options) {
|
|
513
|
+
const conditionLines = step.condition === 'deploy-production-standalone'
|
|
514
|
+
? [" if: ${{ inputs.deploy_stage == 'production' && inputs.dry_run != 'true' }}"]
|
|
515
|
+
: [
|
|
516
|
+
' if:',
|
|
517
|
+
" ${{ steps.version.outputs.mode != 'none' && inputs.deploy_stage == 'production' && inputs.dry_run !=",
|
|
518
|
+
" 'true' }}",
|
|
519
|
+
];
|
|
520
|
+
return [
|
|
521
|
+
` - name: ${step.name}`,
|
|
522
|
+
...conditionLines,
|
|
523
|
+
...deployStepSecretEnvLines(options),
|
|
524
|
+
' run: smoo github-ci nx-deploy --stage production --mode run-many --verify --name "Deploy Production"',
|
|
525
|
+
];
|
|
526
|
+
}
|
|
527
|
+
function conditionalRunStep(step, run) {
|
|
528
|
+
// A step gated on the plan must read the PLAN's mode: it runs before the
|
|
529
|
+
// version step exists, and `steps.version.outputs.mode` is empty there, which
|
|
530
|
+
// silently skips the gate rather than running it.
|
|
531
|
+
const source = step.condition === 'plan-mode-not-none' ? 'plan' : 'version';
|
|
532
|
+
return [` - name: ${step.name}`, ` if: steps.${source}.outputs.mode != 'none'`, ` run: ${run}`];
|
|
533
|
+
}
|
|
534
|
+
function siblingSourceCheckoutStepLines(options) {
|
|
535
|
+
const checkouts = options.sourceCheckouts;
|
|
536
|
+
if (!checkouts?.length) {
|
|
537
|
+
return [];
|
|
538
|
+
}
|
|
539
|
+
return sourceCheckoutsStepLines({ kind: CiWorkflowStepKind.SourceCheckouts, name: '๐ฆ Check out sibling sources', number: 0 }, checkouts);
|
|
540
|
+
}
|
|
541
|
+
const CARGO_CREDENTIALS_STEP_NAME = 'Prepare Cargo credentials';
|
|
542
|
+
/**
|
|
543
|
+
* One credential-helper install per job, because the helper is process
|
|
544
|
+
* configuration and every later cargo fetch in that job resolves through it:
|
|
545
|
+
* the release candidate, both native platform legs, and the final publish job
|
|
546
|
+
* whose pending-release repair still builds historical versions from source.
|
|
547
|
+
*/
|
|
548
|
+
function cargoCredentialsStepLines(options) {
|
|
549
|
+
const config = options.cargoCredentials;
|
|
550
|
+
if (config === undefined) {
|
|
551
|
+
return [];
|
|
552
|
+
}
|
|
553
|
+
return cargoCredentialStepLines({ kind: CiWorkflowStepKind.CargoCredentials, name: CARGO_CREDENTIALS_STEP_NAME, number: 0 }, config);
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Cargo credentials are job env, not step env: the helper reads its token at
|
|
557
|
+
* call time from whichever later step runs the fetch, and build, lint, test
|
|
558
|
+
* and platform-output builds all do. Narrowing it to the install step would
|
|
559
|
+
* leave those fetches unauthenticated. Only `${{ secrets.NAME }}` is ever
|
|
560
|
+
* rendered โ no token value, URL, or argv. Malformed declarations throw here,
|
|
561
|
+
* on every render path, rather than in CI.
|
|
562
|
+
*/
|
|
563
|
+
function cargoCredentialsJobEnv(options) {
|
|
564
|
+
const rendered = cargoCredentialJobEnvLines(options.cargoCredentials).trimEnd();
|
|
565
|
+
return rendered === '' ? '' : `\n${rendered}`;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* The remote cache is job env for the same reason: every Nx target in the job
|
|
569
|
+
* reads it, and a release build that missed the cache would rebuild what CI
|
|
570
|
+
* already built for the identical hashes. Only `${{ secrets.NAME }}` is
|
|
571
|
+
* rendered for the token. Malformed declarations throw here, not in CI.
|
|
572
|
+
*/
|
|
573
|
+
function remoteCacheJobEnv(options) {
|
|
574
|
+
const rendered = remoteCacheJobEnvLines(options.remoteCache).trimEnd();
|
|
575
|
+
return rendered === '' ? '' : `\n${rendered}`;
|
|
576
|
+
}
|
|
577
|
+
function renderSingleJobPublishWorkflowSteps(steps, options) {
|
|
578
|
+
const lines = [];
|
|
579
|
+
const producer = options.platformProducer;
|
|
580
|
+
const crossOnThisRunner = skipsPublishHandoff(options) && hasMacosPlatformTargets(options);
|
|
581
|
+
for (const step of steps) {
|
|
582
|
+
lines.push(...sectionLinesBefore(step));
|
|
583
|
+
lines.push(...commentLinesForStep(step));
|
|
584
|
+
lines.push(...yamlLinesForStep(step, options));
|
|
585
|
+
lines.push('');
|
|
586
|
+
if (crossOnThisRunner && producer && step.kind === PublishWorkflowStepKind.Checkout) {
|
|
587
|
+
// Before any toolchain setup or build, exactly as the dedicated producer
|
|
588
|
+
// job ordered it: the SDK has to be on disk before devenv resolves it.
|
|
589
|
+
lines.push(' - name: Check cross-platform toolchain prerequisites', ' working-directory: .', ' run: |', ' set -euo pipefail', ...producer.preflight.split('\n').map((line) => ` ${line}`), '');
|
|
590
|
+
}
|
|
591
|
+
if (step.kind === PublishWorkflowStepKind.Build) {
|
|
592
|
+
lines.push(' - name: ๐ง Build supplemental Linux targets', " if: steps.version.outputs.mode != 'none'", ` run: smoo github-ci nx-run-many --targets "${LINUX_PLATFORM_TARGET_GLOBS.join(',')}" --projects "${githubExpression('steps.version.outputs.projects')}"`, '');
|
|
593
|
+
if (crossOnThisRunner) {
|
|
594
|
+
lines.push(' - name: ๐ Build selected macOS and iOS release outputs', " if: steps.version.outputs.mode != 'none'", ` run: smoo github-ci nx-run-many --targets "${macosPlatformFamilies(options).join(',')}" --projects "${githubExpression('steps.version.outputs.projects')}"`, '');
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
return `${lines.join('\n').trimEnd()}\n`;
|
|
599
|
+
}
|
|
600
|
+
function renderPlatformPublishWorkflowYaml(options) {
|
|
601
|
+
const deployInput = options.deploy === true
|
|
602
|
+
? `
|
|
603
|
+
deploy_stage:
|
|
604
|
+
type: choice
|
|
605
|
+
description: Deploy live systems after a successful publish.
|
|
606
|
+
options: [none, production]
|
|
607
|
+
default: none`
|
|
608
|
+
: '';
|
|
609
|
+
const steps = definePublishWorkflow(options).steps;
|
|
610
|
+
return `name: Publish
|
|
611
|
+
|
|
612
|
+
on:
|
|
613
|
+
workflow_dispatch:
|
|
614
|
+
inputs:
|
|
615
|
+
bump:
|
|
616
|
+
type: choice
|
|
617
|
+
description:
|
|
618
|
+
Use auto for conventional commits, or force a semver bump. Prerelease publishes to next; all others publish to
|
|
619
|
+
latest.
|
|
620
|
+
options: [auto, patch, minor, major, prerelease]
|
|
621
|
+
default: auto
|
|
622
|
+
projects:
|
|
623
|
+
type: string
|
|
624
|
+
description:
|
|
625
|
+
Comma-separated Nx projects to release, or all for every owned release package. Blank releases package-local
|
|
626
|
+
changes since the last release, whatever the bump mode is.
|
|
627
|
+
default: ''
|
|
628
|
+
dry_run:
|
|
629
|
+
type: boolean
|
|
630
|
+
description: Run release commands without writing versions, tags, publishes, or GitHub Releases.
|
|
631
|
+
default: false${deployInput}
|
|
632
|
+
|
|
633
|
+
permissions:
|
|
634
|
+
contents: read
|
|
635
|
+
|
|
636
|
+
concurrency:
|
|
637
|
+
group: release-${githubExpression('github.ref')}
|
|
638
|
+
cancel-in-progress: false
|
|
639
|
+
|
|
640
|
+
defaults:
|
|
641
|
+
run:
|
|
642
|
+
working-directory: tooling/direnv
|
|
643
|
+
|
|
644
|
+
jobs:
|
|
645
|
+
linux-release-candidate:
|
|
646
|
+
${renderRunsOnLine(options.runsOn)}
|
|
647
|
+
permissions:
|
|
648
|
+
contents: write
|
|
649
|
+
id-token: none
|
|
650
|
+
outputs:
|
|
651
|
+
mode: ${githubExpression('steps.version.outputs.mode')}
|
|
652
|
+
release-sha: ${githubExpression('steps.release-state.outputs.sha')}
|
|
653
|
+
env:
|
|
654
|
+
GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options)}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
|
|
655
|
+
steps:
|
|
656
|
+
${renderLinuxReleaseCandidateSteps(steps, options)}
|
|
657
|
+
|
|
658
|
+
${options.platformProducer?.kind === 'linux-cross' ? 'cross-platform' : 'macos-platform'}:
|
|
659
|
+
${renderMacosJobHeaderLines(options)}
|
|
660
|
+
permissions:
|
|
661
|
+
contents: read
|
|
662
|
+
id-token: none
|
|
663
|
+
env:
|
|
664
|
+
GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options)}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
|
|
665
|
+
${Object.entries(options.platformProducer?.env ?? {})
|
|
666
|
+
.map(([name, value]) => ` ${name}: ${JSON.stringify(value)}`)
|
|
667
|
+
.join('\n')}
|
|
668
|
+
steps:
|
|
669
|
+
${renderMacosPlatformSteps(options)}
|
|
670
|
+
|
|
671
|
+
publish-on-linux:
|
|
672
|
+
needs: [linux-release-candidate, ${options.platformProducer?.kind === 'linux-cross' ? 'cross-platform' : 'macos-platform'}]
|
|
673
|
+
${publishJobRunsOnLine(options)}
|
|
674
|
+
permissions:
|
|
675
|
+
contents: write
|
|
676
|
+
id-token: write
|
|
677
|
+
env:
|
|
678
|
+
TTSC_TSGO_BINARY: ${githubExpression('github.workspace')}/node_modules/@typescript/native/bin/tsc
|
|
679
|
+
GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options)}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
|
|
680
|
+
steps:
|
|
681
|
+
${renderFinalLinuxPublishSteps(options)}
|
|
682
|
+
`;
|
|
683
|
+
}
|
|
684
|
+
function renderLinuxReleaseCandidateSteps(steps, options) {
|
|
685
|
+
const lines = [];
|
|
686
|
+
let stepNumber = 2;
|
|
687
|
+
for (const step of steps) {
|
|
688
|
+
if (step.kind === PublishWorkflowStepKind.RepairPendingReleases ||
|
|
689
|
+
step.kind === PublishWorkflowStepKind.TagRelease ||
|
|
690
|
+
step.kind === PublishWorkflowStepKind.PublishRelease ||
|
|
691
|
+
step.kind === PublishWorkflowStepKind.DeployProduction ||
|
|
692
|
+
step.kind === PublishWorkflowStepKind.SaveNixDevenv) {
|
|
693
|
+
continue;
|
|
694
|
+
}
|
|
695
|
+
lines.push(...sectionLinesBefore(step));
|
|
696
|
+
if (step.kind === PublishWorkflowStepKind.Checkout) {
|
|
697
|
+
lines.push(' # Step 1: GitHub adds "Set up job" automatically', ` # Step ${stepNumber}`);
|
|
698
|
+
}
|
|
699
|
+
else if (step.kind === PublishWorkflowStepKind.SetupDevenv) {
|
|
700
|
+
lines.push(` # Step ${stepNumber}. Composite action internals do not affect top-level job step`, ' # anchors; update these comments if top-level steps move.');
|
|
701
|
+
}
|
|
702
|
+
else {
|
|
703
|
+
lines.push(` # Step ${stepNumber}`);
|
|
704
|
+
}
|
|
705
|
+
if (step.kind === PublishWorkflowStepKind.Checkout) {
|
|
706
|
+
lines.push(` - name: ${step.name}`, ' uses: actions/checkout@v6.0.2', ' with:', ` ref: ${githubExpression('github.sha')}`, ' filter: blob:none', ' fetch-depth: 0');
|
|
707
|
+
}
|
|
708
|
+
else if (step.kind === PublishWorkflowStepKind.Build) {
|
|
709
|
+
lines.push(` - name: ${step.name}`, " if: steps.version.outputs.mode != 'none'", ' run:', ` smoo github-ci nx-run-many --targets build --projects "${githubExpression('steps.version.outputs.projects')}" --collect-outputs "${githubExpression('runner.temp')}/release-build-outputs"`);
|
|
710
|
+
}
|
|
711
|
+
else {
|
|
712
|
+
lines.push(...yamlLinesForStep(step, options));
|
|
713
|
+
}
|
|
714
|
+
stepNumber += 1;
|
|
715
|
+
if (step.kind === PublishWorkflowStepKind.VersionRelease) {
|
|
716
|
+
lines.push('', ` # Step ${stepNumber}`, ' - name: ๐ Capture candidate release SHA', ' id: release-state', ' run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"');
|
|
717
|
+
stepNumber += 1;
|
|
718
|
+
}
|
|
719
|
+
if (step.kind === PublishWorkflowStepKind.Build && hasLinuxPlatformTargets(options)) {
|
|
720
|
+
lines.push('', ` # Step ${stepNumber}`, ' - name: ๐ง Build supplemental Linux targets', " if: steps.version.outputs.mode != 'none'", ' run:', ` smoo github-ci nx-run-many --targets "${LINUX_PLATFORM_TARGET_GLOBS.join(',')}" --projects "${githubExpression('steps.version.outputs.projects')}" --collect-outputs "${githubExpression('runner.temp')}/linux-platform-outputs"`);
|
|
721
|
+
stepNumber += 1;
|
|
722
|
+
}
|
|
723
|
+
lines.push('');
|
|
724
|
+
}
|
|
725
|
+
lines.push(' # --- Candidate transfer --------------------------------------------------', '', ` # Step ${stepNumber++}`, ' - name: ๐ฆ Bundle validated release state', ' run:', ` mkdir -p "${githubExpression('runner.temp')}/publish-release-state" && git bundle create`, ` "${githubExpression('runner.temp')}/publish-release-state/release-state.bundle" HEAD --tags && git rev-parse HEAD >`, ` "${githubExpression('runner.temp')}/publish-release-state/release-head"`, '', ` # Step ${stepNumber++}`, ...artifactStepLines(options.actionsProvider, '๐ค Upload validated release state', 'upload', [
|
|
726
|
+
`name: publish-release-state-${githubExpression('github.run_id')}`,
|
|
727
|
+
`path: ${githubExpression('runner.temp')}/publish-release-state`,
|
|
728
|
+
'if-no-files-found: error',
|
|
729
|
+
'retention-days: 1',
|
|
730
|
+
]), '', ` # Step ${stepNumber++}`, ...artifactStepLines(options.actionsProvider, '๐ค Upload validated build outputs', 'upload', [
|
|
731
|
+
`name: publish-release-outputs-${githubExpression('github.run_id')}`,
|
|
732
|
+
`path: ${githubExpression('runner.temp')}/release-build-outputs`,
|
|
733
|
+
'if-no-files-found: error',
|
|
734
|
+
'retention-days: 1',
|
|
735
|
+
'include-hidden-files: true',
|
|
736
|
+
], "steps.version.outputs.mode != 'none'"));
|
|
737
|
+
if (hasLinuxPlatformTargets(options)) {
|
|
738
|
+
lines.push('', ` # Step ${stepNumber++}`, ...artifactStepLines(options.actionsProvider, '๐ค Upload supplemental Linux outputs', 'upload', [
|
|
739
|
+
`name: publish-linux-outputs-${githubExpression('github.run_id')}`,
|
|
740
|
+
`path: ${githubExpression('runner.temp')}/linux-platform-outputs`,
|
|
741
|
+
'if-no-files-found: error',
|
|
742
|
+
'retention-days: 1',
|
|
743
|
+
'include-hidden-files: true',
|
|
744
|
+
], "steps.version.outputs.mode != 'none'"));
|
|
745
|
+
}
|
|
746
|
+
lines.push('', ' # --- Cleanup ------------------------------------------------------------', '', ` # Step ${stepNumber}`, ' - name: ๐งน Cleanup and cache Nix/devenv', ' # success() is default; always() still saves GH Nix cache after a red job.', ' if: always()', ' uses: ./.github/actions/save-nix-devenv', ' with:', ` devenv-cache-hit: ${githubExpression('steps.setup.outputs.devenv-cache-hit')}`);
|
|
747
|
+
return lines.join('\n').trimEnd();
|
|
748
|
+
}
|
|
749
|
+
function renderMacosPlatformSteps(options) {
|
|
750
|
+
let stepNumber = 3;
|
|
751
|
+
const lines = [
|
|
752
|
+
' # --- Setup --------------------------------------------------------------',
|
|
753
|
+
'',
|
|
754
|
+
' # Step 1: GitHub adds "Set up job" automatically',
|
|
755
|
+
' # Step 2',
|
|
756
|
+
' - name: ๐ฅ Checkout dispatch commit',
|
|
757
|
+
' uses: actions/checkout@v6.0.2',
|
|
758
|
+
' with:',
|
|
759
|
+
` ref: ${githubExpression('github.sha')}`,
|
|
760
|
+
' filter: blob:none',
|
|
761
|
+
' fetch-depth: 0',
|
|
762
|
+
];
|
|
763
|
+
if (options.platformProducer) {
|
|
764
|
+
if (!options.platformProducer.preflight.trim()) {
|
|
765
|
+
throw new Error('Linux cross-platform production requires a nonempty toolchain preflight command.');
|
|
766
|
+
}
|
|
767
|
+
lines.push('', ` # Step ${stepNumber++}`, ' - name: Check cross-platform toolchain prerequisites', ' working-directory: .', ' run: |', ' set -euo pipefail', ...options.platformProducer.preflight.split('\n').map((line) => ` ${line}`));
|
|
768
|
+
}
|
|
769
|
+
const macosCargoCredentials = cargoCredentialsStepLines(options);
|
|
770
|
+
if (macosCargoCredentials.length > 0) {
|
|
771
|
+
lines.push('', ` # Step ${stepNumber++}`, ...macosCargoCredentials);
|
|
772
|
+
}
|
|
773
|
+
const siblingSourceCheckouts = siblingSourceCheckoutStepLines(options);
|
|
774
|
+
if (siblingSourceCheckouts.length > 0) {
|
|
775
|
+
lines.push('', ` # Step ${stepNumber++}`, ...siblingSourceCheckouts);
|
|
776
|
+
}
|
|
777
|
+
lines.push('', ` # Step ${stepNumber++}. Composite action internals do not affect top-level job step`, ' # anchors; update these comments if top-level steps move.', ' - name: ๐งฑ Setup Nix/devenv', ' id: setup', ' uses: ./.github/actions/setup-devenv');
|
|
778
|
+
if (isSmoothBricksCodebasePackageName(options.repoName)) {
|
|
779
|
+
lines.push('', ` # Step ${stepNumber++}`, ' - name: ๐๏ธ Build smoo Nx version actions', ' # Nx Release loads @smoothbricks/nx-plugin/version-actions through the', ' # export map in its own node process, and versioning runs before the', ' # build phase, so the hook must exist in dist first. Downstream', ' # consumers install the published package and skip this bootstrap.', ' #', ' # `nx` cannot do it: the project graph loads this very plugin, so', ' # `nx build nx-plugin` deadlocks on the executor it is building.', ' # ttsc needs only the package tsconfig -- same bootstrap the devenv', ' # shell runs (tooling/direnv/enter-shell.ts).', ' working-directory: packages/nx-plugin', ' run: ttsc -p tsconfig.lib.json --emit');
|
|
780
|
+
}
|
|
781
|
+
lines.push('', ` # Step ${stepNumber++}`, ' - name: ๐ค Configure release author', ' run:', ' git config user.name "github-actions[bot]" && git config user.email', ' "41898282+github-actions[bot]@users.noreply.github.com"', '', ` # Step ${stepNumber++}`, ' - name: ๐ข Version release', ' id: version', ' run:', ` smoo release version --bump "${githubExpression('inputs.bump')}" --projects "${githubExpression('inputs.projects')}" --dry-run "${githubExpression('inputs.dry_run')}" --github-output`, ' "$GITHUB_OUTPUT"');
|
|
782
|
+
const architectures = macosPlatformArchitectures(options);
|
|
783
|
+
const isMatrix = architectures.length >= 2;
|
|
784
|
+
const testArchitecture = macosTestArchitecture(architectures);
|
|
785
|
+
const legLabel = isMatrix ? ` (${githubExpression('matrix.arch')})` : '';
|
|
786
|
+
const testCondition = isMatrix && testArchitecture !== undefined
|
|
787
|
+
? `matrix.arch == '${testArchitecture}' && steps.platform-outputs.outputs.projects != ''`
|
|
788
|
+
: `steps.platform-outputs.outputs.projects != ''`;
|
|
789
|
+
lines.push('', ` # Step ${stepNumber++}`, ` - name: ๐ Build selected macOS and iOS release outputs${legLabel}`, ' id: platform-outputs', ' run:', ` smoo release build-platform-outputs --bump "${githubExpression('inputs.bump')}" --projects "${githubExpression('inputs.projects')}" --ref "${githubExpression('github.sha')}" --targets "${macosPlatformTargetSelector(options)}" --output`, ` "${githubExpression('runner.temp')}/macos-platform-outputs" --github-output "$GITHUB_OUTPUT"`);
|
|
790
|
+
if (options.platformProducer?.kind !== 'linux-cross') {
|
|
791
|
+
lines.push('', ` # Step ${stepNumber++}`, ' - name: ๐งช Unit test selected macOS and iOS packages');
|
|
792
|
+
if (isMatrix) {
|
|
793
|
+
lines.push(' # Only the runner-native leg can execute what it built; the foreign', ' # architecture ships as an artifact without running here.');
|
|
794
|
+
}
|
|
795
|
+
lines.push(` if: ${testCondition}`, ' run:', ' smoo github-ci nx-run-many --targets test --projects', ` "${githubExpression('steps.platform-outputs.outputs.projects')}"`);
|
|
796
|
+
}
|
|
797
|
+
lines.push('', ` # Step ${stepNumber++}`, ...artifactStepLines(options.actionsProvider, `๐ค Upload macOS platform outputs${legLabel}`, 'upload', [
|
|
798
|
+
`name: ${isMatrix
|
|
799
|
+
? `publish-macos-${githubExpression('matrix.arch')}-outputs-${githubExpression('github.run_id')}`
|
|
800
|
+
: `publish-macos-outputs-${githubExpression('github.run_id')}`}`,
|
|
801
|
+
`path: ${githubExpression('runner.temp')}/macos-platform-outputs`,
|
|
802
|
+
'if-no-files-found: error',
|
|
803
|
+
'retention-days: 1',
|
|
804
|
+
'include-hidden-files: true',
|
|
805
|
+
]), '', ' # --- Cleanup ------------------------------------------------------------', '', ` # Step ${stepNumber}`, ' - name: ๐งน Cleanup and cache Nix/devenv', ' # success() is default; always() still saves GH Nix cache after a red job.', ' if: always()', ' uses: ./.github/actions/save-nix-devenv', ' with:', ` devenv-cache-hit: ${githubExpression('steps.setup.outputs.devenv-cache-hit')}`);
|
|
806
|
+
return lines.join('\n').trimEnd();
|
|
807
|
+
}
|
|
808
|
+
function renderFinalLinuxPublishSteps(options) {
|
|
809
|
+
const mode = 'needs.linux-release-candidate.outputs.mode';
|
|
810
|
+
let stepNumber = 2;
|
|
811
|
+
const lines = [
|
|
812
|
+
' # --- Setup --------------------------------------------------------------',
|
|
813
|
+
'',
|
|
814
|
+
' # Step 1: GitHub adds "Set up job" automatically',
|
|
815
|
+
` # Step ${stepNumber++}`,
|
|
816
|
+
' - name: ๐ฅ Checkout dispatch commit',
|
|
817
|
+
' uses: actions/checkout@v6.0.2',
|
|
818
|
+
' with:',
|
|
819
|
+
` ref: ${githubExpression('github.sha')}`,
|
|
820
|
+
' filter: blob:none',
|
|
821
|
+
' fetch-depth: 0',
|
|
822
|
+
];
|
|
823
|
+
const publishCargoCredentials = cargoCredentialsStepLines(options);
|
|
824
|
+
if (publishCargoCredentials.length > 0) {
|
|
825
|
+
lines.push('', ` # Step ${stepNumber++}`, ...publishCargoCredentials);
|
|
826
|
+
}
|
|
827
|
+
const siblingSourceCheckouts = siblingSourceCheckoutStepLines(options);
|
|
828
|
+
if (siblingSourceCheckouts.length > 0) {
|
|
829
|
+
lines.push('', ` # Step ${stepNumber++}`, ...siblingSourceCheckouts);
|
|
830
|
+
}
|
|
831
|
+
lines.push('', ` # Step ${stepNumber++}`, ' - name: ๐งฑ Setup Nix/devenv', ' # Pending release repair builds historical npm gaps before the current', ' # verified artifacts are restored, so this job still needs the full', ' # toolchain even though current release publishing is prebuilt-only.', ' id: setup', ' uses: ./.github/actions/setup-devenv', '', ` # Step ${stepNumber++}`, ...artifactStepLines(options.actionsProvider, '๐ฅ Download candidate artifacts', 'download', [
|
|
832
|
+
`pattern: publish-*-${githubExpression('github.run_id')}`,
|
|
833
|
+
`path: ${githubExpression('runner.temp')}/publish-artifacts`,
|
|
834
|
+
'merge-multiple: false',
|
|
835
|
+
]), '', ` # Step ${stepNumber++}`, ' - name: ๐ค Configure release author', ' run:', ' git config user.name "github-actions[bot]" && git config user.email', ' "41898282+github-actions[bot]@users.noreply.github.com"');
|
|
836
|
+
if (isSmoothBricksCodebasePackageName(options.repoName)) {
|
|
837
|
+
lines.push('', ` # Step ${stepNumber++}`, ' - name: ๐๏ธ Build smoo Nx version actions', ' # Nx Release loads @smoothbricks/nx-plugin/version-actions through the', ' # export map in its own node process, and that export has no source', ' # condition, so the next-prerelease bump inside smoo release publish', ' # needs dist/version-actions.cjs on disk. Downstream consumers install', ' # the published package and skip this bootstrap.', ' #', ' # `nx` cannot do it: the project graph loads this very plugin, so', ' # `nx build nx-plugin` deadlocks on the executor it is building.', ' # ttsc needs only the package tsconfig -- same bootstrap the devenv', ' # shell runs (tooling/direnv/enter-shell.ts).', ' working-directory: packages/nx-plugin', ' run: ttsc -p tsconfig.lib.json --emit');
|
|
838
|
+
}
|
|
839
|
+
lines.push('', ' # --- Repair -------------------------------------------------------------', '', ` # Step ${stepNumber++}`, ' - name: ๐งฏ Repair pending releases', ' run:', ` smoo release repair-pending --ref "${githubExpression('github.sha')}" --platform-outputs`, ` "${macosPlatformArtifactNames(options)
|
|
840
|
+
.map((name) => `${githubExpression('runner.temp')}/publish-artifacts/${name}/repairs`)
|
|
841
|
+
.join(',')}" --dry-run "${githubExpression('inputs.dry_run')}"`, '', ` # Step ${stepNumber++}`, ' - name: โป๏ธ Restore validated release state', ' env:', ` EXPECTED_RELEASE_SHA: ${githubExpression('needs.linux-release-candidate.outputs.release-sha')}`, ' run: |', ' set -euo pipefail', ` state="${githubExpression('runner.temp')}/publish-artifacts/publish-release-state-${githubExpression('github.run_id')}"`, ' actual="$(cat "$state/release-head")"', ' if [ -z "$EXPECTED_RELEASE_SHA" ] || [ "$actual" != "$EXPECTED_RELEASE_SHA" ]; then', ' echo "Release state does not match the validated candidate SHA." >&2', ' exit 1', ' fi', ' git bundle verify "$state/release-state.bundle"', ' git fetch "$state/release-state.bundle" HEAD --tags', ' if [ "$(git rev-parse FETCH_HEAD)" != "$EXPECTED_RELEASE_SHA" ]; then', ' echo "Release bundle HEAD does not match the validated candidate SHA." >&2', ' exit 1', ' fi', ' git reset --hard "$EXPECTED_RELEASE_SHA"');
|
|
842
|
+
lines.push('', ' # --- Validation ---------------------------------------------------------', '', ` # Step ${stepNumber++}`, ' - name: ๐ฆ Apply verified Linux outputs', ` if: ${mode} != 'none'`, ' run:', ` smoo github-ci apply-outputs --source-sha "${githubExpression('needs.linux-release-candidate.outputs.release-sha')}"`, ` "${githubExpression('runner.temp')}/publish-artifacts/publish-release-outputs-${githubExpression('github.run_id')}"`);
|
|
843
|
+
if (hasLinuxPlatformTargets(options)) {
|
|
844
|
+
lines.push(` "${githubExpression('runner.temp')}/publish-artifacts/publish-linux-outputs-${githubExpression('github.run_id')}"`);
|
|
845
|
+
}
|
|
846
|
+
lines.push('', ` # Step ${stepNumber++}`, ' - name: ๐ Apply verified macOS outputs', ` if: ${mode} != 'none'`, ' run:', ` smoo github-ci apply-outputs --source-sha "${githubExpression('github.sha')}"`, ...macosPlatformArtifactNames(options).map((name) => ` "${githubExpression('runner.temp')}/publish-artifacts/${name}/current"`), '', ' # --- Release ------------------------------------------------------------', '', ` # Step ${stepNumber++}`, ...tagReleaseStepLines('๐ท๏ธ Tag release'), '', ` # Step ${stepNumber++}`, ` - name: ๐ฆ Publish release (${githubExpression(mode)})`, ...privateNpmPublisherStepEnv(options), ' # Pack verified outputs; --prebuilt refuses missing artifacts rather than rebuilding.', ...(options.privateNpm
|
|
847
|
+
? [' # Private publication uses the declared registry and step-scoped publisher credential.']
|
|
848
|
+
: [' # Public npm packages use trusted publishing/OIDC after local bootstrap.']), ' run:', ' smoo release publish --prebuilt', ` "${githubExpression('runner.temp')}/publish-artifacts/publish-release-outputs-${githubExpression('github.run_id')}"`, ...(hasLinuxPlatformTargets(options)
|
|
849
|
+
? [
|
|
850
|
+
` "${githubExpression('runner.temp')}/publish-artifacts/publish-linux-outputs-${githubExpression('github.run_id')}"`,
|
|
851
|
+
]
|
|
852
|
+
: []), ...macosPlatformArtifactNames(options).map((name) => ` "${githubExpression('runner.temp')}/publish-artifacts/${name}/current"`), ` --bump "${githubExpression('inputs.bump')}" --dry-run "${githubExpression('inputs.dry_run')}"`);
|
|
853
|
+
if (options.deploy === true) {
|
|
854
|
+
lines.push('', ` # Step ${stepNumber++}`, ' - name: ๐ Deploy production', ' if:', " ${{ needs.linux-release-candidate.outputs.mode != 'none' && inputs.deploy_stage == 'production' &&", " inputs.dry_run != 'true' }}", ...deployStepSecretEnvLines(options), ' run: smoo github-ci nx-deploy --stage production --mode run-many --verify --name "Deploy Production"');
|
|
855
|
+
}
|
|
856
|
+
lines.push('', ' # --- Cleanup ------------------------------------------------------------', '', ` # Step ${stepNumber}`, ' - name: ๐งน Cleanup and cache Nix/devenv', ' if: always()', ' uses: ./.github/actions/save-nix-devenv', ' with:', ` devenv-cache-hit: ${githubExpression('steps.setup.outputs.devenv-cache-hit')}`);
|
|
857
|
+
return lines.join('\n').trimEnd();
|
|
858
|
+
}
|
|
859
|
+
function hasMacosPlatformTargets(options) {
|
|
860
|
+
return MACOS_PLATFORM_TARGET_GLOBS.some((glob) => options.platformTargetGlobs?.includes(glob) === true);
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* The architecture `macos-latest` runs natively. Only that leg can execute the
|
|
864
|
+
* binaries it just built, so it owns the unit-test step; keep this beside the
|
|
865
|
+
* `runs-on` label it describes.
|
|
866
|
+
*/
|
|
867
|
+
const MACOS_RUNNER_ARCHITECTURE = 'arm64';
|
|
868
|
+
function macosPlatformFamilies(options) {
|
|
869
|
+
return MACOS_PLATFORM_TARGET_GLOBS.filter((glob) => options.platformTargetGlobs?.includes(glob) === true);
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* One matrix leg per architecture. A single runner cannot overlap two platform
|
|
873
|
+
* builds of one package: cargo holds an exclusive lock on the package's whole
|
|
874
|
+
* `target/` directory, so extra Nx workers only queue behind it. Separate
|
|
875
|
+
* runners have separate target directories, so the architectures compile in
|
|
876
|
+
* parallel for real.
|
|
877
|
+
*/
|
|
878
|
+
function macosPlatformArchitectures(options) {
|
|
879
|
+
if (options.platformProducer?.kind === 'linux-cross')
|
|
880
|
+
return [];
|
|
881
|
+
return hasMacosPlatformTargets(options) ? [...(options.macosPlatformArchitectures ?? [])] : [];
|
|
882
|
+
}
|
|
883
|
+
function macosTestArchitecture(architectures) {
|
|
884
|
+
return architectures.includes(MACOS_RUNNER_ARCHITECTURE) ? MACOS_RUNNER_ARCHITECTURE : architectures[0];
|
|
885
|
+
}
|
|
886
|
+
function renderMacosJobHeaderLines(options) {
|
|
887
|
+
if (options.platformProducer?.kind === 'linux-cross')
|
|
888
|
+
return renderRunsOnLine(options.runsOn);
|
|
889
|
+
const architectures = macosPlatformArchitectures(options);
|
|
890
|
+
const lines = [
|
|
891
|
+
options.macosRunsOn === undefined ? ' runs-on: macos-latest' : renderRunsOnLine(options.macosRunsOn),
|
|
892
|
+
];
|
|
893
|
+
if (architectures.length >= 2) {
|
|
894
|
+
lines.push(' strategy:', ' # One architecture per runner: a leg that fails still leaves the other', ' # architecture uploaded for inspection.', ' fail-fast: false', ' matrix:', ` arch: [${architectures.join(', ')}]`);
|
|
895
|
+
}
|
|
896
|
+
return lines.join('\n');
|
|
897
|
+
}
|
|
898
|
+
/** Per-leg target selector, or every macOS family when there is no matrix. */
|
|
899
|
+
function macosPlatformTargetSelector(options) {
|
|
900
|
+
const families = macosPlatformFamilies(options);
|
|
901
|
+
const selectors = families.length > 0 ? families : [...MACOS_PLATFORM_TARGET_GLOBS];
|
|
902
|
+
if (macosPlatformArchitectures(options).length < 2) {
|
|
903
|
+
return selectors.join(',');
|
|
904
|
+
}
|
|
905
|
+
return selectors.map((glob) => `*-${githubExpression('matrix.arch')}-${glob.slice(2)}`).join(',');
|
|
906
|
+
}
|
|
907
|
+
/** Artifact names the final job downloads, one per rendered macOS leg. */
|
|
908
|
+
function macosPlatformArtifactNames(options) {
|
|
909
|
+
const architectures = macosPlatformArchitectures(options);
|
|
910
|
+
const runId = githubExpression('github.run_id');
|
|
911
|
+
if (architectures.length < 2) {
|
|
912
|
+
return [`publish-macos-outputs-${runId}`];
|
|
913
|
+
}
|
|
914
|
+
return architectures.map((architecture) => `publish-macos-${architecture}-outputs-${runId}`);
|
|
915
|
+
}
|
|
916
|
+
function hasLinuxPlatformTargets(options) {
|
|
917
|
+
return LINUX_PLATFORM_TARGET_GLOBS.some((glob) => options.platformTargetGlobs?.includes(glob) === true);
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Runner for the job that tags and publishes, on GitHub Actions always the
|
|
921
|
+
* GitHub-hosted one.
|
|
922
|
+
*
|
|
923
|
+
* npmjs mints provenance from the job's OIDC token and then rejects the upload
|
|
924
|
+
* with `422 Unsupported GitHub Actions runner environment "self-hosted", only
|
|
925
|
+
* github-hosted supported for provenance`: the tarball is signed, the registry
|
|
926
|
+
* refuses it, and the release is left tagged but unpublished. Publishing from
|
|
927
|
+
* a GitHub-hosted runner is the fix; dropping `--provenance` is not.
|
|
928
|
+
*
|
|
929
|
+
* A `forgejo` actions provider keeps the configured labels: that workflow does
|
|
930
|
+
* not run on GitHub Actions, so `ubuntu-latest` names no runner there and
|
|
931
|
+
* there is no GitHub OIDC to mint provenance from in the first place.
|
|
932
|
+
* Private-registry publishing is unaffected either way โ its static publisher
|
|
933
|
+
* token works from any runner, and its packages ride the same job.
|
|
934
|
+
*
|
|
935
|
+
* Build lanes keep `smoo.github.runsOn`: only the publishing job moves. Where
|
|
936
|
+
* build and publish share one job (no macOS platform fan-out) that whole job
|
|
937
|
+
* follows the publisher, because that job is the one npmjs sees.
|
|
938
|
+
*/
|
|
939
|
+
function publishJobRunsOnLine(options) {
|
|
940
|
+
return renderRunsOnLine(options.actionsProvider === 'forgejo' ? options.runsOn : GITHUB_HOSTED_LINUX_RUNNER);
|
|
941
|
+
}
|
|
942
|
+
function githubExpression(expression) {
|
|
943
|
+
return ['$', '{{ ', expression, ' }}'].join('');
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Whether the separate publishing job can be dropped, so the release runs as
|
|
947
|
+
* one job that builds every artifact and publishes them.
|
|
948
|
+
*
|
|
949
|
+
* The hand-off exists for ONE reason: npmjs mints provenance from the
|
|
950
|
+
* publishing job's OIDC token and refuses a self-hosted runner for it, so a
|
|
951
|
+
* release with public packages must publish from the GitHub-hosted runner and
|
|
952
|
+
* therefore has to receive its self-hosted artifacts through an artifact.
|
|
953
|
+
* A release that publishes only to the declared private registry has no such
|
|
954
|
+
* constraint; when its Apple targets are cross-built on the same runner (or it
|
|
955
|
+
* has none), one job holds everything.
|
|
956
|
+
*/
|
|
957
|
+
function skipsPublishHandoff(options) {
|
|
958
|
+
if (options.actionsProvider !== 'forgejo' || options.privateNpm === undefined) {
|
|
959
|
+
return false;
|
|
960
|
+
}
|
|
961
|
+
return !hasMacosPlatformTargets(options) || options.platformProducer?.kind === 'linux-cross';
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Toolchain environment for a foreign-platform producer, rendered onto whichever
|
|
965
|
+
* job runs its builds. In the flattened single-job shape that is the publish job
|
|
966
|
+
* itself, so the SDK path and cross flags have to reach it the same way the
|
|
967
|
+
* dedicated producer job received them.
|
|
968
|
+
*/
|
|
969
|
+
function platformProducerJobEnv(options) {
|
|
970
|
+
const producer = options.platformProducer;
|
|
971
|
+
if (!producer || !skipsPublishHandoff(options)) {
|
|
972
|
+
return '';
|
|
973
|
+
}
|
|
974
|
+
return Object.entries(producer.env ?? {})
|
|
975
|
+
.map(([name, value]) => `\n ${name}: ${JSON.stringify(value)}`)
|
|
976
|
+
.join('');
|
|
977
|
+
}
|
|
978
|
+
function privateNpmInstallJobEnv(options) {
|
|
979
|
+
const tokenEnv = options.privateNpm?.readTokenEnv;
|
|
980
|
+
if (!tokenEnv) {
|
|
981
|
+
return '';
|
|
982
|
+
}
|
|
983
|
+
return ['', ` ${tokenEnv}: ${githubExpression(`secrets.${tokenEnv}`)}`].join('\n');
|
|
984
|
+
}
|
|
985
|
+
/** Both repair and publish can write packages; neither exposes the credential to setup/build. */
|
|
986
|
+
function privateNpmPublisherStepEnv(options) {
|
|
987
|
+
const name = options.privateNpm?.publishTokenEnv;
|
|
988
|
+
return name ? [' env:', ` ${name}: ${githubExpression(`secrets.${name}`)}`] : [];
|
|
989
|
+
}
|