@rightkit/ci 0.2.49 → 0.3.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 +75 -2
- package/artifacts.mjs +290 -0
- package/cli/right-git.mjs +26 -4
- package/install.mjs +1 -1
- package/manifest.mjs +196 -9
- package/manifest.schema.json +46 -1
- package/package.json +5 -3
- package/sync.mjs +51 -4
- package/templates/ci.yml +2 -2
- package/templates/package-smoke.yml +2 -2
- package/templates/profiles/rust-hybrid/ci.yml +7 -7
- package/templates/profiles/rust-hybrid/release-candidate.yml +2 -2
- package/templates/publish-npm.yml +2 -2
- package/templates/qualification.yml +2 -2
- package/templates/release-candidate.yml +2 -2
- package/templates/swift-check.yml +2 -2
- package/workflows.mjs +638 -0
- package/checkout.test.mjs +0 -92
- package/cli.test.mjs +0 -68
- package/drift.test.mjs +0 -203
- package/guard-coverage.test.mjs +0 -237
- package/manifest.test.mjs +0 -535
- package/ownership-registration.test.mjs +0 -20
- package/pack-smoke.test.mjs +0 -55
- package/pnpm-lock-patch.test.mjs +0 -161
- package/render.test.mjs +0 -2077
- package/supersede.test.mjs +0 -84
- package/swift-check.test.mjs +0 -95
- package/sync.test.mjs +0 -147
- package/test-support.mjs +0 -34
- package/uninstall.test.mjs +0 -89
- package/visibility-gate.test.mjs +0 -141
package/workflows.mjs
ADDED
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
// `workflows` manifest block: named workflows rendered by code, not by a lane template.
|
|
2
|
+
//
|
|
3
|
+
// kind "custom" one build job: triggers, steps, toolchain pins, named artifact (#465)
|
|
4
|
+
// kind "swift-host" `swift test` on Windows and macOS hosts for chosen packages (#437)
|
|
5
|
+
// kind "dispatch-matrix" workflow_dispatch inputs -> plan job -> per-item matrix jobs -> collect job (#437)
|
|
6
|
+
//
|
|
7
|
+
// Every action is pinned to a 40-hex commit SHA, the workflow runs with `contents: read` only, no step may read
|
|
8
|
+
// the secrets context, and every checkout sets `persist-credentials: false`. Manifest values reach YAML only
|
|
9
|
+
// through strict allowlists, so no value can carry `${{ }}` except the fixed artifact-name tokens below.
|
|
10
|
+
// Each rendered file starts with the managed marker, so sync, drift and uninstall treat it like a lane file.
|
|
11
|
+
|
|
12
|
+
import { validateCheckout, applyCheckoutOptions } from "./checkout.mjs";
|
|
13
|
+
import {
|
|
14
|
+
LANE_FILENAMES,
|
|
15
|
+
RUST_HYBRID_ONLY_LANES,
|
|
16
|
+
UPLOAD_ARTIFACT_PIN,
|
|
17
|
+
DOWNLOAD_ARTIFACT_SHA,
|
|
18
|
+
deriveProjectName,
|
|
19
|
+
ownershipStep,
|
|
20
|
+
parsePackageManager,
|
|
21
|
+
} from "./manifest.mjs";
|
|
22
|
+
|
|
23
|
+
export const WORKFLOW_KINDS = Object.freeze(["custom", "swift-host", "dispatch-matrix"]);
|
|
24
|
+
|
|
25
|
+
const CHECKOUT_PIN = "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1";
|
|
26
|
+
const SETUP_NODE_PIN = "actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0";
|
|
27
|
+
const RUST_TOOLCHAIN_PIN = "dtolnay/rust-toolchain@f8be11a05b1d4f3fcebe6410cc16743212b999b0";
|
|
28
|
+
|
|
29
|
+
const NAME_RE = /^[a-z][a-z0-9-]{0,40}$/;
|
|
30
|
+
const FILE_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,60}\.yml$/;
|
|
31
|
+
const RUNNER_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,40}$/;
|
|
32
|
+
const BRANCH_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
|
|
33
|
+
const TRIGGER_PATH_RE = /^!?(?!.*\.\.)(?!\/)[A-Za-z0-9._/*-]+$/;
|
|
34
|
+
const GROUP_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,60}$/;
|
|
35
|
+
const WORK_DIR_RE = /^(?:\.|(?!.*\.\.)(?!.*\s)(?!\/)[A-Za-z0-9][A-Za-z0-9._/-]*)$/;
|
|
36
|
+
const STEP_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9 ._:()/+-]{0,80}$/;
|
|
37
|
+
const ARTIFACT_PATH_RE = /^(?!.*\.\.)(?!\/)[A-Za-z0-9._/*?-]+$/;
|
|
38
|
+
const ARTIFACT_TOKEN_RE = /\{(sha|run_id|run_attempt|os|matrix\.[a-z_][a-z0-9_]*)\}/g;
|
|
39
|
+
const ARTIFACT_LITERAL_RE = /^[A-Za-z0-9._-]+$/;
|
|
40
|
+
const INPUT_NAME_RE = /^[a-z][a-z0-9_]{0,39}$/;
|
|
41
|
+
const INPUT_TEXT_RE = /^[A-Za-z0-9 ._,:()/+-]{0,120}$/;
|
|
42
|
+
const INPUT_VALUE_RE = /^[A-Za-z0-9._,:/+-][A-Za-z0-9 ._,:/+-]{0,199}$|^$/;
|
|
43
|
+
const SWIFT_VERSION_RE = /^\d+\.\d+(?:\.\d+)?$/;
|
|
44
|
+
const SHA256_RE = /^[0-9a-f]{64}$/;
|
|
45
|
+
const RUST_VERSION_RE = /^(?:stable|beta|nightly|\d+\.\d+(?:\.\d+)?)$/;
|
|
46
|
+
const SWIFT_ARG_RE = /^--?[A-Za-z][A-Za-z0-9-]*(?:=[A-Za-z0-9._/-]+)?$/;
|
|
47
|
+
const SECRETS_RE = /\bsecrets\b/i;
|
|
48
|
+
const UNTRUSTED_EXPRESSION_RE = /\$\{\{[^}]*(?:github\.head_ref|github\.event\.(?:pull_request|issue|comment|review|head_commit|commits|discussion|pages|workflow_run))/;
|
|
49
|
+
// Static expression forms allowed inside a `run:` script; everything else must travel through a quoted env variable.
|
|
50
|
+
const ALLOWED_RUN_EXPRESSION_RE = /^(?:matrix\.[a-z_][a-z0-9_]*|runner\.os|github\.(?:sha|run_id|run_attempt)|'[A-Za-z0-9 ._-]*')$/;
|
|
51
|
+
const MAX_STEPS = 40;
|
|
52
|
+
const MAX_RUN_CHARS = 6000;
|
|
53
|
+
const MAX_ITEM_JOBS = 6;
|
|
54
|
+
const MAX_PACKAGES = 32;
|
|
55
|
+
|
|
56
|
+
const COMMON_KEYS = ["kind", "file", "on", "concurrency", "checkout", "timeoutMinutes"];
|
|
57
|
+
const KIND_KEYS = {
|
|
58
|
+
custom: ["runsOn", "toolchain", "steps", "artifact"],
|
|
59
|
+
"swift-host": ["os", "packages", "swiftArgs", "toolchain", "artifact"],
|
|
60
|
+
"dispatch-matrix": ["inputs", "plan", "jobs", "collect"],
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function isObject(value) {
|
|
64
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function unknownKeys(value, allowed, label, errors) {
|
|
68
|
+
for (const key of Object.keys(value)) if (!allowed.includes(key)) errors.push(`unknown ${label} field: ${key}`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function reservedFilenames(lanes) {
|
|
72
|
+
const reserved = new Set(Object.values(LANE_FILENAMES));
|
|
73
|
+
for (const lane of RUST_HYBRID_ONLY_LANES) if (LANE_FILENAMES[lane]) reserved.add(LANE_FILENAMES[lane]);
|
|
74
|
+
return reserved;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Effective workflow filename: explicit `file`, else `<name>.yml`. */
|
|
78
|
+
export function workflowFilename(name, config) {
|
|
79
|
+
return typeof config?.file === "string" ? config.file : `${name}.yml`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function validateStringList(value, label, errors, { max = 16, pattern }) {
|
|
83
|
+
if (!Array.isArray(value) || value.length === 0 || value.length > max
|
|
84
|
+
|| !value.every((item) => typeof item === "string" && pattern.test(item)) || new Set(value).size !== value.length) {
|
|
85
|
+
errors.push(`${label} must be a non-empty array (at most ${max}) of unique safe values`);
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function validateTriggers(on, label, errors) {
|
|
92
|
+
if (!isObject(on)) {
|
|
93
|
+
errors.push(`${label}.on must be an object with push, pull_request and/or workflow_dispatch`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
unknownKeys(on, ["push", "pull_request", "workflow_dispatch"], `${label}.on`, errors);
|
|
97
|
+
if (Object.keys(on).length === 0) errors.push(`${label}.on must declare at least one trigger`);
|
|
98
|
+
for (const key of ["push", "pull_request"]) {
|
|
99
|
+
const trigger = on[key];
|
|
100
|
+
if (trigger === undefined || trigger === true) continue;
|
|
101
|
+
if (!isObject(trigger)) {
|
|
102
|
+
errors.push(`${label}.on.${key} must be true or an object with branches and/or paths`);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
unknownKeys(trigger, ["branches", "paths"], `${label}.on.${key}`, errors);
|
|
106
|
+
if (trigger.branches !== undefined) validateStringList(trigger.branches, `${label}.on.${key}.branches`, errors, { pattern: BRANCH_RE });
|
|
107
|
+
if (trigger.paths !== undefined) validateStringList(trigger.paths, `${label}.on.${key}.paths`, errors, { max: 32, pattern: TRIGGER_PATH_RE });
|
|
108
|
+
}
|
|
109
|
+
if (on.workflow_dispatch !== undefined && on.workflow_dispatch !== true) {
|
|
110
|
+
errors.push(`${label}.on.workflow_dispatch must be true (declare inputs on the dispatch-matrix workflow's inputs field)`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function validateInputs(inputs, label, errors) {
|
|
115
|
+
if (!isObject(inputs) || Object.keys(inputs).length === 0 || Object.keys(inputs).length > 10) {
|
|
116
|
+
errors.push(`${label}.inputs must be an object of 1 to 10 workflow_dispatch inputs`);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
for (const [name, input] of Object.entries(inputs)) {
|
|
120
|
+
const at = `${label}.inputs.${name}`;
|
|
121
|
+
if (!INPUT_NAME_RE.test(name)) errors.push(`${label}.inputs name must be lower snake case: ${name}`);
|
|
122
|
+
if (!isObject(input)) {
|
|
123
|
+
errors.push(`${at} must be an object`);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
unknownKeys(input, ["description", "required", "default", "type", "options"], at, errors);
|
|
127
|
+
const type = input.type ?? "string";
|
|
128
|
+
if (!["string", "boolean", "choice"].includes(type)) errors.push(`${at}.type must be string, boolean or choice`);
|
|
129
|
+
if (input.description !== undefined && (typeof input.description !== "string" || !INPUT_TEXT_RE.test(input.description))) errors.push(`${at}.description must be short safe text`);
|
|
130
|
+
if (input.required !== undefined && typeof input.required !== "boolean") errors.push(`${at}.required must be a boolean`);
|
|
131
|
+
if (type === "boolean") {
|
|
132
|
+
if (input.default !== undefined && typeof input.default !== "boolean") errors.push(`${at}.default must be a boolean`);
|
|
133
|
+
} else if (input.default !== undefined && (typeof input.default !== "string" || !INPUT_VALUE_RE.test(input.default))) {
|
|
134
|
+
errors.push(`${at}.default must be a short safe string`);
|
|
135
|
+
}
|
|
136
|
+
if (type === "choice") {
|
|
137
|
+
if (!Array.isArray(input.options) || input.options.length === 0 || !input.options.every((option) => typeof option === "string" && INPUT_VALUE_RE.test(option) && option !== "")) {
|
|
138
|
+
errors.push(`${at}.options must list the safe choices`);
|
|
139
|
+
} else if (input.default !== undefined && !input.options.includes(input.default)) {
|
|
140
|
+
errors.push(`${at}.default must be one of the options`);
|
|
141
|
+
}
|
|
142
|
+
} else if (input.options !== undefined) {
|
|
143
|
+
errors.push(`${at}.options is only valid for type choice`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function validateStep(step, label, errors) {
|
|
149
|
+
if (!isObject(step)) {
|
|
150
|
+
errors.push(`${label} must be an object`);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
unknownKeys(step, ["name", "shell", "workingDirectory", "run"], label, errors);
|
|
154
|
+
if (step.name !== undefined && (typeof step.name !== "string" || !STEP_NAME_RE.test(step.name))) errors.push(`${label}.name must be short safe text`);
|
|
155
|
+
if (!["bash", "pwsh"].includes(step.shell)) errors.push(`${label}.shell must be bash or pwsh`);
|
|
156
|
+
if (step.workingDirectory !== undefined && (typeof step.workingDirectory !== "string" || !WORK_DIR_RE.test(step.workingDirectory))) {
|
|
157
|
+
errors.push(`${label}.workingDirectory must be a safe repository-relative directory or '.'`);
|
|
158
|
+
}
|
|
159
|
+
if (typeof step.run !== "string" || step.run.trim() === "" || step.run.length > MAX_RUN_CHARS) {
|
|
160
|
+
errors.push(`${label}.run must be a non-empty script of at most ${MAX_RUN_CHARS} characters`);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (/[\0\r]/.test(step.run)) errors.push(`${label}.run must not contain NUL or carriage-return characters`);
|
|
164
|
+
if (/^\s/.test(step.run.replace(/^\n+/, ""))) errors.push(`${label}.run must not start with indentation`);
|
|
165
|
+
if (SECRETS_RE.test(step.run)) errors.push(`${label}.run must not reference secrets: managed build workflows never read secrets`);
|
|
166
|
+
const opened = step.run.split("${{").length - 1;
|
|
167
|
+
const expressions = [...step.run.matchAll(/\$\{\{\s*([^{}]*?)\s*\}\}/g)];
|
|
168
|
+
const disallowed = expressions.filter((match) => !ALLOWED_RUN_EXPRESSION_RE.test(match[1]));
|
|
169
|
+
if (opened !== expressions.length || disallowed.length > 0) {
|
|
170
|
+
const shown = disallowed.length > 0 ? disallowed[0][1] : "<malformed expression>";
|
|
171
|
+
errors.push(`${label}.run must not interpolate \${{ ${shown} }}: only matrix.<key>, runner.os, github.sha, github.run_id, github.run_attempt and literal strings are allowed in scripts; pass any other value through a quoted env: variable (workflow_dispatch inputs already render as RIGHT_GIT_INPUT_<NAME> environment variables) and read it as "$VAR"`);
|
|
172
|
+
}
|
|
173
|
+
if (UNTRUSTED_EXPRESSION_RE.test(step.run)) errors.push(`${label}.run must not interpolate untrusted event data (pass it through a workflow_dispatch input, which renders as an environment variable)`);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function validateSteps(steps, label, errors) {
|
|
177
|
+
if (!Array.isArray(steps) || steps.length === 0 || steps.length > MAX_STEPS) {
|
|
178
|
+
errors.push(`${label} must be a non-empty array of at most ${MAX_STEPS} steps`);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
steps.forEach((step, index) => validateStep(step, `${label}[${index}]`, errors));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function artifactNameTokens(name) {
|
|
185
|
+
return [...name.matchAll(ARTIFACT_TOKEN_RE)].map((match) => match[1]);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function validateArtifact(artifact, label, errors, { requireToken }) {
|
|
189
|
+
if (!isObject(artifact)) {
|
|
190
|
+
errors.push(`${label} must be an object`);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
unknownKeys(artifact, ["name", "path", "retentionDays", "ifNoFilesFound", "when"], label, errors);
|
|
194
|
+
if (typeof artifact.name !== "string" || artifact.name.length > 120) {
|
|
195
|
+
errors.push(`${label}.name must be a string`);
|
|
196
|
+
} else {
|
|
197
|
+
const literal = artifact.name.replace(ARTIFACT_TOKEN_RE, "");
|
|
198
|
+
if (literal === "" || !ARTIFACT_LITERAL_RE.test(literal)) {
|
|
199
|
+
errors.push(`${label}.name may contain only letters, digits, '.', '_', '-' and the tokens {sha}, {run_id}, {run_attempt}, {os}, {matrix.<key>}`);
|
|
200
|
+
} else if (requireToken(artifactNameTokens(artifact.name)) === false) {
|
|
201
|
+
errors.push(`${label}.name must carry a token that differs per job ({os} or {matrix.<key>}), or the jobs overwrite each other's artifact`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (typeof artifact.path !== "string" || !ARTIFACT_PATH_RE.test(artifact.path)) errors.push(`${label}.path must be a safe repository-relative path or glob`);
|
|
205
|
+
if (artifact.retentionDays !== undefined && (!Number.isInteger(artifact.retentionDays) || artifact.retentionDays < 1 || artifact.retentionDays > 90)) errors.push(`${label}.retentionDays must be an integer from 1 to 90`);
|
|
206
|
+
if (artifact.ifNoFilesFound !== undefined && !["error", "warn", "ignore"].includes(artifact.ifNoFilesFound)) errors.push(`${label}.ifNoFilesFound must be error, warn or ignore`);
|
|
207
|
+
if (artifact.when !== undefined && !["success", "always"].includes(artifact.when)) errors.push(`${label}.when must be success or always`);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function validateToolchain(toolchain, label, errors, { allowSwift }) {
|
|
211
|
+
if (!isObject(toolchain) || Object.keys(toolchain).length === 0) {
|
|
212
|
+
errors.push(`${label} must be an object with rust and/or swift`);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
unknownKeys(toolchain, allowSwift ? ["rust", "swift"] : ["rust"], label, errors);
|
|
216
|
+
if (toolchain.rust !== undefined && (typeof toolchain.rust !== "string" || !RUST_VERSION_RE.test(toolchain.rust))) errors.push(`${label}.rust must be stable, beta, nightly or an exact version such as 1.91.0`);
|
|
217
|
+
if (toolchain.swift !== undefined) {
|
|
218
|
+
const swift = toolchain.swift;
|
|
219
|
+
if (!isObject(swift) || Object.keys(swift).some((key) => key !== "version" && key !== "sha256")
|
|
220
|
+
|| typeof swift.version !== "string" || !SWIFT_VERSION_RE.test(swift.version)
|
|
221
|
+
|| typeof swift.sha256 !== "string" || !SHA256_RE.test(swift.sha256)) {
|
|
222
|
+
errors.push(`${label}.swift must be { version: "x.y.z", sha256: <64 lowercase hex> }; the installer's sha256 is verified before it runs`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function validateRunsOn(runsOn, label, errors) {
|
|
228
|
+
const list = typeof runsOn === "string" ? [runsOn] : runsOn;
|
|
229
|
+
if (!Array.isArray(list) || list.length === 0 || list.length > 6 || !list.every((value) => typeof value === "string" && RUNNER_RE.test(value)) || new Set(list).size !== list.length) {
|
|
230
|
+
errors.push(`${label} must be one safe runner label or an array of up to 6 unique labels`);
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
return list;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function validateCustom(config, label, errors) {
|
|
237
|
+
const runners = validateRunsOn(config.runsOn, `${label}.runsOn`, errors);
|
|
238
|
+
if (config.toolchain !== undefined) validateToolchain(config.toolchain, `${label}.toolchain`, errors, { allowSwift: true });
|
|
239
|
+
validateSteps(config.steps, `${label}.steps`, errors);
|
|
240
|
+
if (config.artifact !== undefined) {
|
|
241
|
+
validateArtifact(config.artifact, `${label}.artifact`, errors, { requireToken: (tokens) => !runners || runners.length < 2 || tokens.includes("os") });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function validateSwiftHost(config, label, errors) {
|
|
246
|
+
if (!Array.isArray(config.os)) errors.push(`${label}.os must be an array of runner labels`);
|
|
247
|
+
const runners = Array.isArray(config.os) ? validateRunsOn(config.os, `${label}.os`, errors) : null;
|
|
248
|
+
if (!validateStringList(config.packages, `${label}.packages`, errors, { max: MAX_PACKAGES, pattern: WORK_DIR_RE })) { /* reported */ }
|
|
249
|
+
if (config.swiftArgs !== undefined && (!Array.isArray(config.swiftArgs) || config.swiftArgs.length > 8 || !config.swiftArgs.every((arg) => typeof arg === "string" && SWIFT_ARG_RE.test(arg)))) {
|
|
250
|
+
errors.push(`${label}.swiftArgs must be an array of at most 8 plain swift test options such as "--parallel"`);
|
|
251
|
+
}
|
|
252
|
+
if (config.toolchain !== undefined) validateToolchain(config.toolchain, `${label}.toolchain`, errors, { allowSwift: true });
|
|
253
|
+
const windows = runners ? runners.some((runner) => /^windows-/i.test(runner)) : false;
|
|
254
|
+
if (windows && config.toolchain?.swift === undefined) errors.push(`${label}.toolchain.swift is required when os includes a Windows runner (Windows has no Swift toolchain)`);
|
|
255
|
+
if (config.artifact !== undefined) {
|
|
256
|
+
validateArtifact(config.artifact, `${label}.artifact`, errors, { requireToken: (tokens) => !runners || runners.length < 2 || tokens.includes("os") });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function validateDispatchMatrix(config, label, errors, on) {
|
|
261
|
+
if (!isObject(on) || on.workflow_dispatch !== true) errors.push(`${label}.on.workflow_dispatch must be true for kind dispatch-matrix`);
|
|
262
|
+
if (config.inputs !== undefined) validateInputs(config.inputs, label, errors);
|
|
263
|
+
const plan = config.plan;
|
|
264
|
+
if (!isObject(plan)) {
|
|
265
|
+
errors.push(`${label}.plan must be an object { run, shell, runsOn?, workingDirectory? }; the plan script writes matrix=<JSON> to $GITHUB_OUTPUT`);
|
|
266
|
+
} else {
|
|
267
|
+
unknownKeys(plan, ["run", "shell", "runsOn", "workingDirectory"], `${label}.plan`, errors);
|
|
268
|
+
validateStep({ shell: plan.shell, run: plan.run, workingDirectory: plan.workingDirectory }, `${label}.plan`, errors);
|
|
269
|
+
if (plan.runsOn !== undefined && (typeof plan.runsOn !== "string" || !RUNNER_RE.test(plan.runsOn))) errors.push(`${label}.plan.runsOn must be one safe runner label`);
|
|
270
|
+
}
|
|
271
|
+
if (!Array.isArray(config.jobs) || config.jobs.length === 0 || config.jobs.length > MAX_ITEM_JOBS) {
|
|
272
|
+
errors.push(`${label}.jobs must be an array of 1 to ${MAX_ITEM_JOBS} per-item jobs`);
|
|
273
|
+
} else {
|
|
274
|
+
const ids = new Set();
|
|
275
|
+
config.jobs.forEach((job, index) => {
|
|
276
|
+
const at = `${label}.jobs[${index}]`;
|
|
277
|
+
if (!isObject(job)) {
|
|
278
|
+
errors.push(`${at} must be an object`);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
unknownKeys(job, ["id", "runsOn", "toolchain", "steps", "artifact"], at, errors);
|
|
282
|
+
if (typeof job.id !== "string" || !NAME_RE.test(job.id) || ["plan", "collect", "private-repo-guard"].includes(job.id)) errors.push(`${at}.id must be a lowercase job id other than plan, collect and private-repo-guard`);
|
|
283
|
+
else if (ids.has(job.id)) errors.push(`${at}.id must be unique: ${job.id}`);
|
|
284
|
+
else ids.add(job.id);
|
|
285
|
+
if (typeof job.runsOn !== "string" || !RUNNER_RE.test(job.runsOn)) errors.push(`${at}.runsOn must be one safe runner label`);
|
|
286
|
+
if (job.toolchain !== undefined) validateToolchain(job.toolchain, `${at}.toolchain`, errors, { allowSwift: true });
|
|
287
|
+
validateSteps(job.steps, `${at}.steps`, errors);
|
|
288
|
+
if (job.artifact !== undefined) {
|
|
289
|
+
validateArtifact(job.artifact, `${at}.artifact`, errors, { requireToken: (tokens) => tokens.some((token) => token.startsWith("matrix.")) });
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
if (config.collect !== undefined) {
|
|
294
|
+
const collect = config.collect;
|
|
295
|
+
if (!isObject(collect)) {
|
|
296
|
+
errors.push(`${label}.collect must be an object`);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
unknownKeys(collect, ["runsOn", "download", "steps"], `${label}.collect`, errors);
|
|
300
|
+
if (collect.runsOn !== undefined && (typeof collect.runsOn !== "string" || !RUNNER_RE.test(collect.runsOn))) errors.push(`${label}.collect.runsOn must be one safe runner label`);
|
|
301
|
+
if (collect.download !== undefined) {
|
|
302
|
+
if (!isObject(collect.download) || Object.keys(collect.download).some((key) => key !== "pattern" && key !== "path")
|
|
303
|
+
|| typeof collect.download.pattern !== "string" || !ARTIFACT_PATH_RE.test(collect.download.pattern)
|
|
304
|
+
|| typeof collect.download.path !== "string" || !ARTIFACT_PATH_RE.test(collect.download.path)) {
|
|
305
|
+
errors.push(`${label}.collect.download must be { pattern, path } with safe values`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
validateSteps(collect.steps, `${label}.collect.steps`, errors);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Validate manifest.workflows. Appends to `errors`; never throws.
|
|
314
|
+
* Checks each workflow in isolation, then filename collisions across lanes and workflows.
|
|
315
|
+
*/
|
|
316
|
+
export function validateWorkflows(manifest, errors) {
|
|
317
|
+
const workflows = manifest.workflows;
|
|
318
|
+
if (workflows === undefined) return;
|
|
319
|
+
if (!isObject(workflows) || Object.keys(workflows).length === 0 || Object.keys(workflows).length > 8) {
|
|
320
|
+
errors.push("workflows must be an object of 1 to 8 named workflows");
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const reserved = reservedFilenames(manifest.lanes);
|
|
324
|
+
const files = new Map();
|
|
325
|
+
for (const [name, config] of Object.entries(workflows)) {
|
|
326
|
+
const label = `workflows.${name}`;
|
|
327
|
+
if (!NAME_RE.test(name)) errors.push(`${label}: workflow names are lowercase letters, digits and '-' (starting with a letter)`);
|
|
328
|
+
if (!isObject(config)) {
|
|
329
|
+
errors.push(`${label} must be an object`);
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if (!WORKFLOW_KINDS.includes(config.kind)) {
|
|
333
|
+
errors.push(`${label}.kind must be one of ${WORKFLOW_KINDS.join(", ")}`);
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
unknownKeys(config, [...COMMON_KEYS, ...KIND_KEYS[config.kind]], label, errors);
|
|
337
|
+
if (config.file !== undefined && (typeof config.file !== "string" || !FILE_RE.test(config.file))) {
|
|
338
|
+
errors.push(`${label}.file must be a plain workflow filename ending in .yml`);
|
|
339
|
+
} else {
|
|
340
|
+
const file = workflowFilename(name, config);
|
|
341
|
+
if (!FILE_RE.test(file)) errors.push(`${label}: the default filename ${file} is not a safe workflow filename; set file`);
|
|
342
|
+
else if (reserved.has(file)) errors.push(`${label}.file ${file} collides with a built-in lane workflow`);
|
|
343
|
+
else if (files.has(file)) errors.push(`${label}.file ${file} is also used by workflows.${files.get(file)}`);
|
|
344
|
+
else files.set(file, name);
|
|
345
|
+
}
|
|
346
|
+
if (config.on === undefined && config.kind === "swift-host") {
|
|
347
|
+
// swift-host defaults to push on the default branch plus pull_request.
|
|
348
|
+
} else {
|
|
349
|
+
validateTriggers(config.on, label, errors);
|
|
350
|
+
}
|
|
351
|
+
if (config.concurrency !== undefined) {
|
|
352
|
+
if (!isObject(config.concurrency) || Object.keys(config.concurrency).some((key) => key !== "group" && key !== "cancelInProgress")
|
|
353
|
+
|| typeof config.concurrency.group !== "string" || !GROUP_RE.test(config.concurrency.group)
|
|
354
|
+
|| (config.concurrency.cancelInProgress !== undefined && typeof config.concurrency.cancelInProgress !== "boolean")) {
|
|
355
|
+
errors.push(`${label}.concurrency must be { group: <safe prefix>, cancelInProgress?: boolean }; the group renders as <prefix>-\${{ github.ref }}`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (config.checkout !== undefined) validateCheckout(config.checkout, errors);
|
|
359
|
+
if (config.timeoutMinutes !== undefined && (!Number.isInteger(config.timeoutMinutes) || config.timeoutMinutes < 1 || config.timeoutMinutes > 360)) {
|
|
360
|
+
errors.push(`${label}.timeoutMinutes must be an integer from 1 to 360`);
|
|
361
|
+
}
|
|
362
|
+
if (config.kind === "custom") validateCustom(config, label, errors);
|
|
363
|
+
else if (config.kind === "swift-host") validateSwiftHost(config, label, errors);
|
|
364
|
+
else validateDispatchMatrix(config, label, errors, config.on);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// ---------------------------------------------------------------------------------------------- rendering
|
|
369
|
+
|
|
370
|
+
function q(value) {
|
|
371
|
+
return `'${String(value).replace(/'/g, "''")}'`;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function renderArtifactName(name) {
|
|
375
|
+
return name.replace(ARTIFACT_TOKEN_RE, (_, token) => {
|
|
376
|
+
if (token === "sha") return "${{ github.sha }}";
|
|
377
|
+
if (token === "run_id") return "${{ github.run_id }}";
|
|
378
|
+
if (token === "run_attempt") return "${{ github.run_attempt }}";
|
|
379
|
+
if (token === "os") return "${{ matrix.os || runner.os }}";
|
|
380
|
+
return `\${{ ${token} }}`;
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function pmExec(manifest) {
|
|
385
|
+
const { name } = parsePackageManager(manifest.packageManager);
|
|
386
|
+
return name === "pnpm" ? "pnpm exec" : name === "npm" ? "npm exec --" : "yarn exec";
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* The `swift-toolchain` step: installs the pinned Windows Swift toolchain through
|
|
391
|
+
* `right-release toolchain swift` (Orthic-Labs/rightkit#436). The installer's sha256 is verified before it runs;
|
|
392
|
+
* `--github-env` exports what the installer changed to GITHUB_ENV and GITHUB_PATH for the later steps. It runs
|
|
393
|
+
* on Windows only (right-release refuses other hosts; macOS runners ship Swift with Xcode). Needs
|
|
394
|
+
* `@rightkit/release` in the repository's dependencies (the install step before it provides it).
|
|
395
|
+
* Returns the step's lines, indented as a job step.
|
|
396
|
+
*/
|
|
397
|
+
export function swiftToolchainStep(manifest, swift) {
|
|
398
|
+
return [
|
|
399
|
+
" - name: Install pinned Swift toolchain",
|
|
400
|
+
" if: runner.os == 'Windows'",
|
|
401
|
+
" shell: bash",
|
|
402
|
+
` run: ${pmExec(manifest)} right-release toolchain swift --version ${swift.version} --sha256 ${swift.sha256} --github-env`,
|
|
403
|
+
];
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function setupLines(manifest, { linuxOwnershipGuard }) {
|
|
407
|
+
const pm = parsePackageManager(manifest.packageManager);
|
|
408
|
+
const lines = [
|
|
409
|
+
` - uses: ${SETUP_NODE_PIN}`,
|
|
410
|
+
" with:",
|
|
411
|
+
` node-version: ${JSON.stringify(String(manifest.matrix.node[0]))}`,
|
|
412
|
+
" package-manager-cache: false",
|
|
413
|
+
];
|
|
414
|
+
if (pm.setup) lines.push(...pm.setup.split("\n"));
|
|
415
|
+
lines.push(` - run: ${pm.installCommand}`);
|
|
416
|
+
const ownership = ownershipStep(manifest, "workflow").split("\n").slice(1);
|
|
417
|
+
if (linuxOwnershipGuard) ownership.splice(1, 0, " if: ${{ runner.os != 'Linux' }}");
|
|
418
|
+
lines.push(...ownership);
|
|
419
|
+
return lines;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function userStepLines(step, index) {
|
|
423
|
+
const lines = [` - name: ${q(step.name ?? `Step ${index + 1}`)}`, ` shell: ${step.shell}`];
|
|
424
|
+
if (step.workingDirectory !== undefined && step.workingDirectory !== ".") lines.push(` working-directory: ${step.workingDirectory}`);
|
|
425
|
+
lines.push(" run: |");
|
|
426
|
+
for (const line of step.run.replace(/^\n+/, "").replace(/\s+$/, "").split("\n")) lines.push(line === "" ? "" : ` ${line}`);
|
|
427
|
+
return lines;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function artifactLines(artifact) {
|
|
431
|
+
return [
|
|
432
|
+
" - name: Upload build artifact",
|
|
433
|
+
` if: \${{ ${artifact.when === "always" ? "always()" : "success()"} }}`,
|
|
434
|
+
` uses: ${UPLOAD_ARTIFACT_PIN}`,
|
|
435
|
+
" with:",
|
|
436
|
+
` name: ${renderArtifactName(artifact.name)}`,
|
|
437
|
+
` path: ${q(artifact.path)}`,
|
|
438
|
+
` retention-days: ${artifact.retentionDays ?? 14}`,
|
|
439
|
+
` if-no-files-found: ${artifact.ifNoFilesFound ?? "error"}`,
|
|
440
|
+
];
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function toolchainLines(manifest, toolchain) {
|
|
444
|
+
const lines = [];
|
|
445
|
+
if (toolchain?.rust !== undefined) {
|
|
446
|
+
lines.push(` - uses: ${RUST_TOOLCHAIN_PIN}`, " with:", ` toolchain: ${toolchain.rust}`);
|
|
447
|
+
}
|
|
448
|
+
if (toolchain?.swift !== undefined) lines.push(...swiftToolchainStep(manifest, toolchain.swift));
|
|
449
|
+
return lines;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function inputEnvName(name) {
|
|
453
|
+
return `RIGHT_GIT_INPUT_${name.toUpperCase()}`;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function inputEnvLines(inputs) {
|
|
457
|
+
if (!inputs) return [];
|
|
458
|
+
return [" env:", ...Object.keys(inputs).map((name) => ` ${inputEnvName(name)}: \${{ inputs.${name} }}`)];
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function runnerLinux(runner) {
|
|
462
|
+
return /^(ubuntu|linux)/i.test(runner);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function jobLines(manifest, job) {
|
|
466
|
+
const lines = [` ${job.id}:`, ` needs: [${["private-repo-guard", ...(job.needs ?? [])].join(", ")}]`];
|
|
467
|
+
if (job.condition) lines.push(` if: ${job.condition}`);
|
|
468
|
+
if (job.matrixOs) {
|
|
469
|
+
lines.push(" strategy:", " fail-fast: false", " matrix:", ` os: ${JSON.stringify(job.matrixOs)}`, " runs-on: ${{ matrix.os }}");
|
|
470
|
+
} else if (job.matrixFromPlan) {
|
|
471
|
+
lines.push(" strategy:", " fail-fast: false", " matrix: ${{ fromJSON(needs.plan.outputs.matrix) }}", ` runs-on: ${job.runsOn}`);
|
|
472
|
+
} else {
|
|
473
|
+
lines.push(` runs-on: ${job.runsOn}`);
|
|
474
|
+
}
|
|
475
|
+
lines.push(` timeout-minutes: ${job.timeoutMinutes}`);
|
|
476
|
+
if (job.outputs) lines.push(" outputs:", ...Object.entries(job.outputs).map(([key, value]) => ` ${key}: ${value}`));
|
|
477
|
+
lines.push(...inputEnvLines(job.inputs));
|
|
478
|
+
lines.push(" steps:");
|
|
479
|
+
if (job.checkout !== false) {
|
|
480
|
+
lines.push(` - uses: ${CHECKOUT_PIN}`, " with:", " persist-credentials: false");
|
|
481
|
+
}
|
|
482
|
+
if (job.download) {
|
|
483
|
+
lines.push(
|
|
484
|
+
" - name: Download job artifacts",
|
|
485
|
+
` uses: actions/download-artifact@${DOWNLOAD_ARTIFACT_SHA} # v4.3.0`,
|
|
486
|
+
" with:",
|
|
487
|
+
` pattern: ${q(job.download.pattern)}`,
|
|
488
|
+
` path: ${q(job.download.path)}`,
|
|
489
|
+
" merge-multiple: true",
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
const linux = job.matrixOs ? job.matrixOs.some(runnerLinux) : runnerLinux(job.runsOn ?? "");
|
|
493
|
+
lines.push(...setupLines(manifest, { linuxOwnershipGuard: linux }));
|
|
494
|
+
lines.push(...toolchainLines(manifest, job.toolchain));
|
|
495
|
+
job.steps.forEach((step, index) => lines.push(...(step.raw ?? userStepLines(step, index))));
|
|
496
|
+
if (job.artifact) lines.push(...artifactLines(job.artifact));
|
|
497
|
+
return lines;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function triggerLines(manifest, config, name) {
|
|
501
|
+
const branch = manifest.defaultBranch ?? "main";
|
|
502
|
+
const on = config.on ?? { push: true, pull_request: true };
|
|
503
|
+
const lines = ["on:"];
|
|
504
|
+
for (const key of ["push", "pull_request"]) {
|
|
505
|
+
const trigger = on[key];
|
|
506
|
+
if (trigger === undefined) continue;
|
|
507
|
+
lines.push(` ${key}:`);
|
|
508
|
+
if (trigger === true) {
|
|
509
|
+
if (key === "push") lines.push(` branches: [${branch}]`);
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
if (trigger.branches) lines.push(` branches: [${trigger.branches.join(", ")}]`);
|
|
513
|
+
if (trigger.paths) lines.push(" paths:", ...trigger.paths.map((p) => ` - ${q(p)}`));
|
|
514
|
+
}
|
|
515
|
+
if (on.workflow_dispatch === true) {
|
|
516
|
+
lines.push(" workflow_dispatch:");
|
|
517
|
+
if (config.kind === "dispatch-matrix" && config.inputs) {
|
|
518
|
+
lines.push(" inputs:");
|
|
519
|
+
for (const [inputName, input] of Object.entries(config.inputs)) {
|
|
520
|
+
const type = input.type ?? "string";
|
|
521
|
+
lines.push(` ${inputName}:`);
|
|
522
|
+
if (input.description !== undefined) lines.push(` description: ${q(input.description)}`);
|
|
523
|
+
lines.push(` type: ${type}`);
|
|
524
|
+
lines.push(` required: ${input.required === true}`);
|
|
525
|
+
if (type === "choice") lines.push(" options:", ...input.options.map((option) => ` - ${q(option)}`));
|
|
526
|
+
if (input.default !== undefined) lines.push(` default: ${type === "boolean" ? input.default : q(input.default)}`);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return lines;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function buildJobs(manifest, name, config) {
|
|
534
|
+
const timeoutMinutes = config.timeoutMinutes ?? 60;
|
|
535
|
+
if (config.kind === "custom") {
|
|
536
|
+
const runners = typeof config.runsOn === "string" ? [config.runsOn] : config.runsOn;
|
|
537
|
+
return [{
|
|
538
|
+
id: "build",
|
|
539
|
+
...(runners.length > 1 ? { matrixOs: runners } : { runsOn: runners[0] }),
|
|
540
|
+
timeoutMinutes,
|
|
541
|
+
toolchain: config.toolchain,
|
|
542
|
+
steps: config.steps,
|
|
543
|
+
artifact: config.artifact,
|
|
544
|
+
inputs: undefined,
|
|
545
|
+
}];
|
|
546
|
+
}
|
|
547
|
+
if (config.kind === "swift-host") {
|
|
548
|
+
const swiftArgs = config.swiftArgs?.length ? ` ${config.swiftArgs.join(" ")}` : "";
|
|
549
|
+
const steps = config.packages.map((pkg) => ({ name: `swift test ${pkg}`, shell: "bash", workingDirectory: pkg, run: `swift test${swiftArgs}` }));
|
|
550
|
+
return [{
|
|
551
|
+
id: "swift-host",
|
|
552
|
+
matrixOs: config.os,
|
|
553
|
+
timeoutMinutes,
|
|
554
|
+
toolchain: config.toolchain,
|
|
555
|
+
steps: [{ raw: [" - name: swift --version", " shell: bash", " run: swift --version"] }, ...steps],
|
|
556
|
+
artifact: config.artifact,
|
|
557
|
+
}];
|
|
558
|
+
}
|
|
559
|
+
const inputs = config.inputs;
|
|
560
|
+
const jobs = [{
|
|
561
|
+
id: "plan",
|
|
562
|
+
runsOn: config.plan.runsOn ?? "ubuntu-24.04",
|
|
563
|
+
timeoutMinutes,
|
|
564
|
+
outputs: { matrix: "${{ steps.plan.outputs.matrix }}" },
|
|
565
|
+
inputs,
|
|
566
|
+
steps: [{ raw: planStepLines(config.plan) }],
|
|
567
|
+
}];
|
|
568
|
+
for (const job of config.jobs) {
|
|
569
|
+
jobs.push({
|
|
570
|
+
id: job.id,
|
|
571
|
+
needs: ["plan"],
|
|
572
|
+
runsOn: job.runsOn,
|
|
573
|
+
matrixFromPlan: true,
|
|
574
|
+
timeoutMinutes,
|
|
575
|
+
toolchain: job.toolchain,
|
|
576
|
+
steps: job.steps,
|
|
577
|
+
artifact: job.artifact,
|
|
578
|
+
inputs,
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
if (config.collect) {
|
|
582
|
+
jobs.push({
|
|
583
|
+
id: "collect",
|
|
584
|
+
needs: config.jobs.map((job) => job.id),
|
|
585
|
+
condition: "${{ !cancelled() && needs.private-repo-guard.result == 'success' }}",
|
|
586
|
+
runsOn: config.collect.runsOn ?? "ubuntu-24.04",
|
|
587
|
+
timeoutMinutes,
|
|
588
|
+
download: config.collect.download,
|
|
589
|
+
steps: config.collect.steps,
|
|
590
|
+
inputs,
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
return jobs;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
function planStepLines(plan) {
|
|
597
|
+
const lines = [" - name: Plan matrix", " id: plan", ` shell: ${plan.shell}`];
|
|
598
|
+
if (plan.workingDirectory !== undefined && plan.workingDirectory !== ".") lines.push(` working-directory: ${plan.workingDirectory}`);
|
|
599
|
+
lines.push(" run: |");
|
|
600
|
+
for (const line of plan.run.replace(/^\n+/, "").replace(/\s+$/, "").split("\n")) lines.push(line === "" ? "" : ` ${line}`);
|
|
601
|
+
return lines;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/** Render one manifest.workflows entry to workflow text. */
|
|
605
|
+
export function renderWorkflow(manifest, repoPath, name, config) {
|
|
606
|
+
const concurrency = config.concurrency;
|
|
607
|
+
const lines = [
|
|
608
|
+
"# Managed by right-git — do not hand-edit. Run `right-git sync` to update.",
|
|
609
|
+
`# Template: workflows.${config.kind} | Template version: ${manifest.templateVersion}`,
|
|
610
|
+
`name: ${deriveProjectName(repoPath).toLowerCase().replace(/[^a-z0-9-]+/g, "-")}-${name}`,
|
|
611
|
+
...triggerLines(manifest, config, name),
|
|
612
|
+
"permissions:",
|
|
613
|
+
" contents: read",
|
|
614
|
+
"concurrency:",
|
|
615
|
+
` group: ${concurrency ? `${concurrency.group}-\${{ github.ref }}` : "${{ github.workflow }}-${{ github.ref }}"}`,
|
|
616
|
+
` cancel-in-progress: ${concurrency?.cancelInProgress ?? true}`,
|
|
617
|
+
"jobs:",
|
|
618
|
+
" private-repo-guard:",
|
|
619
|
+
" runs-on: ubuntu-24.04",
|
|
620
|
+
" steps:",
|
|
621
|
+
" - name: Refuse private repository",
|
|
622
|
+
" if: ${{ github.event.repository.private }}",
|
|
623
|
+
" run: exit 1",
|
|
624
|
+
];
|
|
625
|
+
for (const job of buildJobs(manifest, name, config)) lines.push(...jobLines(manifest, job));
|
|
626
|
+
const text = `${lines.join("\n")}\n`;
|
|
627
|
+
const withCheckout = { checkout: config.checkout ?? manifest.checkout };
|
|
628
|
+
return applyCheckoutOptions(text, withCheckout);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/** Render every workflow in manifest.workflows. Returns { lane, filename, content }[] (lane is `workflow:<name>`). */
|
|
632
|
+
export function renderWorkflows(manifest, repoPath) {
|
|
633
|
+
return Object.entries(manifest.workflows ?? {}).map(([name, config]) => ({
|
|
634
|
+
lane: `workflow:${name}`,
|
|
635
|
+
filename: workflowFilename(name, config),
|
|
636
|
+
content: renderWorkflow(manifest, repoPath, name, config),
|
|
637
|
+
}));
|
|
638
|
+
}
|