@rightkit/ci 0.2.45 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -3
- package/artifacts.mjs +290 -0
- package/artifacts.test.mjs +168 -0
- package/checkout.test.mjs +1 -0
- package/cli/right-git.mjs +4 -0
- package/guard-coverage.test.mjs +1 -0
- package/manifest.mjs +545 -30
- package/manifest.schema.json +138 -6
- package/manifest.test.mjs +48 -0
- package/orkflows.test.mjs +0 -0
- package/package.json +2 -2
- package/render.test.mjs +362 -27
- package/supersede.mjs +127 -0
- package/supersede.test.mjs +84 -0
- package/swift-check.test.mjs +95 -0
- package/sync.mjs +4 -1
- package/templates/ci.yml +4 -4
- package/templates/profiles/rust-hybrid/ci.yml +4 -4
- package/templates/profiles/rust-hybrid/release-candidate.yml +2 -1
- package/templates/profiles/rust-hybrid/sign-existing.yml +36 -0
- package/templates/swift-check.yml +85 -0
- package/workflows.mjs +638 -0
- package/workflows.test.mjs +213 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { validateManifest } from "./manifest.mjs";
|
|
6
|
+
import { renderLanes, planSync, applyPlan } from "./sync.mjs";
|
|
7
|
+
import { driftCommand } from "./drift.mjs";
|
|
8
|
+
import { makeTempRepo, PUBLIC_DEPS } from "./test-support.mjs";
|
|
9
|
+
import { swiftToolchainStep } from "./workflows.mjs";
|
|
10
|
+
|
|
11
|
+
const SWIFT_PIN = "a".repeat(64);
|
|
12
|
+
const RENDER = {
|
|
13
|
+
kind: "custom",
|
|
14
|
+
file: "render-windows.yml",
|
|
15
|
+
on: { push: { branches: ["main"], paths: ["render/**", ".github/workflows/render-windows.yml"] }, workflow_dispatch: true },
|
|
16
|
+
runsOn: "windows-2025",
|
|
17
|
+
concurrency: { group: "render-windows", cancelInProgress: false },
|
|
18
|
+
checkout: { sparse: ["render"], longPaths: true },
|
|
19
|
+
timeoutMinutes: 45,
|
|
20
|
+
toolchain: { rust: "1.91.0" },
|
|
21
|
+
steps: [
|
|
22
|
+
{ name: "cargo test", shell: "pwsh", workingDirectory: "render", run: "cargo test --release" },
|
|
23
|
+
{ name: "Build info", shell: "pwsh", workingDirectory: "render", run: "cargo build --release\n$h = (Get-FileHash target/release/render.dll).Hash\nSet-Content build-info.txt \"sha=${{ github.sha }} dll=$h\"" },
|
|
24
|
+
],
|
|
25
|
+
artifact: { name: "swiftright-render-{sha}", path: "render/target/release/render.dll", retentionDays: 30, ifNoFilesFound: "error" },
|
|
26
|
+
};
|
|
27
|
+
const SWIFT_HOST = {
|
|
28
|
+
kind: "swift-host",
|
|
29
|
+
file: "swift-host-tests.yml",
|
|
30
|
+
os: ["windows-2025", "macos-15"],
|
|
31
|
+
packages: ["packages/SwiftCore", "packages/SwiftUIKit"],
|
|
32
|
+
swiftArgs: ["--parallel"],
|
|
33
|
+
toolchain: { swift: { version: "6.4.0", sha256: SWIFT_PIN } },
|
|
34
|
+
checkout: { sparse: ["packages"], longPaths: true },
|
|
35
|
+
artifact: { name: "swift-test-logs-{os}", path: "packages/**/.build/logs", when: "always", ifNoFilesFound: "ignore" },
|
|
36
|
+
};
|
|
37
|
+
const FACTORY = {
|
|
38
|
+
kind: "dispatch-matrix",
|
|
39
|
+
file: "factory-pairs.yml",
|
|
40
|
+
on: { workflow_dispatch: true },
|
|
41
|
+
inputs: { cases: { description: "Case ids", default: "" }, cases_file: { description: "Case list file" }, runs: { description: "Runs per case", default: "1" } },
|
|
42
|
+
plan: { shell: "bash", run: "node factory/tools/plan.mjs >> \"$GITHUB_OUTPUT\"" },
|
|
43
|
+
jobs: [
|
|
44
|
+
{ id: "capture-mac", runsOn: "macos-15", steps: [{ shell: "bash", run: "./capture.sh \"${{ matrix.case }}\"" }], artifact: { name: "capture-mac-{matrix.case}", path: "out/**" } },
|
|
45
|
+
{ id: "capture-win", runsOn: "windows-2025", toolchain: { swift: { version: "6.4.0", sha256: SWIFT_PIN } }, steps: [{ shell: "pwsh", run: "./capture.ps1" }], artifact: { name: "capture-win-{matrix.case}", path: "out/**" } },
|
|
46
|
+
],
|
|
47
|
+
collect: { download: { pattern: "capture-*", path: "captures" }, steps: [{ shell: "bash", run: "node factory/tools/compare.mjs captures" }] },
|
|
48
|
+
};
|
|
49
|
+
const BASE = {
|
|
50
|
+
schemaVersion: 1,
|
|
51
|
+
compile: "github-actions-only",
|
|
52
|
+
lanes: ["ci"],
|
|
53
|
+
matrix: { os: ["ubuntu-latest"], node: ["22.13"] },
|
|
54
|
+
packageManager: "pnpm@11.24.0",
|
|
55
|
+
templateVersion: "1.0.0",
|
|
56
|
+
};
|
|
57
|
+
const withWorkflows = (workflows) => ({ ...BASE, workflows });
|
|
58
|
+
const errorsFor = (workflows) => validateManifest(withWorkflows(workflows)).errors;
|
|
59
|
+
const renderByFile = (manifest) => Object.fromEntries(renderLanes(manifest, "/repos/swiftright").map((entry) => [entry.filename, entry.content]));
|
|
60
|
+
|
|
61
|
+
test("all three workflow kinds validate and render next to the ci lane", () => {
|
|
62
|
+
const manifest = withWorkflows({ "render-windows": RENDER, "swift-host": SWIFT_HOST, "factory-pairs": FACTORY });
|
|
63
|
+
assert.deepEqual(validateManifest(manifest).errors, []);
|
|
64
|
+
const files = renderByFile(manifest);
|
|
65
|
+
assert.deepEqual(Object.keys(files).sort(), ["ci.yml", "factory-pairs.yml", "render-windows.yml", "swift-host-tests.yml"]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("every rendered workflow pins actions to a commit sha, reads no secrets, has read-only permissions and no persisted credentials", () => {
|
|
69
|
+
const files = renderByFile(withWorkflows({ "render-windows": RENDER, "swift-host": SWIFT_HOST, "factory-pairs": FACTORY }));
|
|
70
|
+
for (const name of ["render-windows.yml", "swift-host-tests.yml", "factory-pairs.yml"]) {
|
|
71
|
+
const text = files[name];
|
|
72
|
+
assert.ok(text.startsWith("# Managed by right-git"), name);
|
|
73
|
+
const uses = text.split("\n").filter((line) => /^\s*(?:- )?uses:/.test(line));
|
|
74
|
+
assert.ok(uses.length > 0, name);
|
|
75
|
+
for (const line of uses) assert.match(line, /@[0-9a-f]{40}(?:\s|$)/, `${name}: ${line.trim()}`);
|
|
76
|
+
assert.equal((text.match(/persist-credentials: false/g) ?? []).length, uses.filter((line) => /actions\/checkout@/.test(line)).length, name);
|
|
77
|
+
assert.match(text, /^permissions:\n contents: read$/m, name);
|
|
78
|
+
assert.doesNotMatch(text, /secrets\.|pull_request_target|workflow_run/, name);
|
|
79
|
+
assert.match(text, /RightKit ownership/, `${name} keeps the ownership scan`);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("custom lane renders filename, path triggers, plain dispatch, steps, named artifact, per-lane sparse, concurrency and toolchain pin (#465)", () => {
|
|
84
|
+
const text = renderByFile(withWorkflows({ "render-windows": RENDER }))["render-windows.yml"];
|
|
85
|
+
assert.match(text, /^on:\n push:\n branches: \[main\]\n paths:\n - 'render\/\*\*'\n - '\.github\/workflows\/render-windows\.yml'\n workflow_dispatch:\npermissions:/m);
|
|
86
|
+
assert.match(text, /^concurrency:\n group: render-windows-\$\{\{ github\.ref \}\}\n cancel-in-progress: false$/m);
|
|
87
|
+
assert.match(text, /runs-on: windows-2025\n timeout-minutes: 45/);
|
|
88
|
+
assert.match(text, /uses: dtolnay\/rust-toolchain@[0-9a-f]{40}\n with:\n toolchain: 1\.91\.0/);
|
|
89
|
+
assert.match(text, /- name: 'cargo test'\n shell: pwsh\n working-directory: render\n run: \|\n cargo test --release/);
|
|
90
|
+
assert.match(text, /Set-Content build-info\.txt "sha=\$\{\{ github\.sha \}\} dll=\$h"/);
|
|
91
|
+
assert.match(text, /sparse-checkout: \|\n render\n sparse-checkout-cone-mode: true/);
|
|
92
|
+
assert.match(text, /- name: Enable Windows long paths/);
|
|
93
|
+
assert.match(text, /name: swiftright-render-\$\{\{ github\.sha \}\}\n path: 'render\/target\/release\/render\.dll'\n retention-days: 30\n if-no-files-found: error/);
|
|
94
|
+
assert.doesNotMatch(text, /toolchain: stable/);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("swift-host lane runs swift test per package on windows and macOS with the pinned toolchain step (#437, #436)", () => {
|
|
98
|
+
const text = renderByFile(withWorkflows({ "swift-host": SWIFT_HOST }))["swift-host-tests.yml"];
|
|
99
|
+
assert.match(text, /matrix:\n os: \["windows-2025","macos-15"\]\n runs-on: \$\{\{ matrix\.os \}\}/);
|
|
100
|
+
assert.match(text, /- name: Install pinned Swift toolchain\n if: runner\.os == 'Windows'\n shell: bash\n run: pnpm exec right-release toolchain swift --version 6\.4\.0 --sha256 a{64} --github-env/);
|
|
101
|
+
assert.match(text, /- name: 'swift test packages\/SwiftCore'\n shell: bash\n working-directory: packages\/SwiftCore\n run: \|\n swift test --parallel/);
|
|
102
|
+
assert.match(text, /- name: 'swift test packages\/SwiftUIKit'/);
|
|
103
|
+
assert.match(text, /name: swift-test-logs-\$\{\{ matrix\.os \|\| runner\.os \}\}/);
|
|
104
|
+
assert.match(text, /if: \$\{\{ always\(\) \}\}\n uses: actions\/upload-artifact@[0-9a-f]{40}/);
|
|
105
|
+
assert.match(text, /on:\n push:\n branches: \[main\]\n pull_request:\npermissions:/);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("swiftToolchainStep calls right-release toolchain swift through the manifest's package manager", () => {
|
|
109
|
+
const step = swiftToolchainStep({ packageManager: "npm@10.9.0" }, { version: "6.4.0", sha256: SWIFT_PIN }).join("\n");
|
|
110
|
+
assert.match(step, /run: npm exec -- right-release toolchain swift --version 6\.4\.0 --sha256 a{64} --github-env/);
|
|
111
|
+
assert.match(step, /if: runner\.os == 'Windows'/);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("dispatch-matrix lane renders inputs, a plan job, per-item matrix jobs and a collect job (#437)", () => {
|
|
115
|
+
const text = renderByFile(withWorkflows({ "factory-pairs": FACTORY }))["factory-pairs.yml"];
|
|
116
|
+
assert.match(text, /workflow_dispatch:\n inputs:\n cases:\n description: 'Case ids'\n type: string\n required: false\n default: ''/);
|
|
117
|
+
assert.match(text, / plan:\n needs: \[private-repo-guard\]\n runs-on: ubuntu-24\.04/);
|
|
118
|
+
assert.match(text, /outputs:\n matrix: \$\{\{ steps\.plan\.outputs\.matrix \}\}/);
|
|
119
|
+
assert.match(text, /RIGHT_GIT_INPUT_CASES_FILE: \$\{\{ inputs\.cases_file \}\}/);
|
|
120
|
+
assert.match(text, / capture-mac:\n needs: \[private-repo-guard, plan\]\n strategy:\n fail-fast: false\n matrix: \$\{\{ fromJSON\(needs\.plan\.outputs\.matrix\) \}\}\n runs-on: macos-15/);
|
|
121
|
+
assert.match(text, /name: capture-mac-\$\{\{ matrix\.case \}\}/);
|
|
122
|
+
assert.match(text, / collect:\n needs: \[private-repo-guard, capture-mac, capture-win\]\n if: \$\{\{ !cancelled\(\) && needs\.private-repo-guard\.result == 'success' \}\}/);
|
|
123
|
+
assert.match(text, /uses: actions\/download-artifact@[0-9a-f]{40} # v4\.3\.0\n with:\n pattern: 'capture-\*'\n path: 'captures'\n merge-multiple: true/);
|
|
124
|
+
assert.match(text, /- name: RightKit ownership[^\n]*\n if: \$\{\{ runner\.os != 'Linux' \}\}/);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("workflow validation rejects unsafe values, secrets, untrusted expressions, collisions and unknown fields", () => {
|
|
128
|
+
const bad = (patch, pattern) => {
|
|
129
|
+
const errors = errorsFor({ "render-windows": { ...RENDER, ...patch } });
|
|
130
|
+
assert.ok(errors.some((error) => pattern.test(error)), `${JSON.stringify(patch)} -> ${errors.join(" | ")}`);
|
|
131
|
+
};
|
|
132
|
+
bad({ file: "ci.yml" }, /collides with a built-in lane/);
|
|
133
|
+
bad({ file: "../x.yml" }, /plain workflow filename/);
|
|
134
|
+
bad({ on: { pull_request_target: true } }, /unknown render-windows\.on field|unknown workflows\.render-windows\.on field/);
|
|
135
|
+
bad({ on: { push: { paths: ["../x"] } } }, /paths must be/);
|
|
136
|
+
bad({ on: {} }, /at least one trigger/);
|
|
137
|
+
bad({ steps: [{ shell: "bash", run: "echo ${{ secrets.TOKEN }}" }] }, /must not reference secrets/);
|
|
138
|
+
bad({ steps: [{ shell: "bash", run: "echo ${{ github.head_ref }}" }] }, /untrusted event data/);
|
|
139
|
+
bad({ steps: [{ shell: "bash", run: "echo ${{ github.event.pull_request.title }}" }] }, /untrusted event data/);
|
|
140
|
+
bad({ steps: [{ shell: "zsh", run: "echo" }] }, /shell must be bash or pwsh/);
|
|
141
|
+
bad({ steps: [{ shell: "bash", run: " indented" }] }, /must not start with indentation/);
|
|
142
|
+
bad({ steps: [] }, /non-empty array/);
|
|
143
|
+
bad({ steps: [{ shell: "bash", run: "x", workingDirectory: "../up" }] }, /workingDirectory/);
|
|
144
|
+
bad({ runsOn: "${{ matrix.os }}" }, /safe runner label/);
|
|
145
|
+
bad({ concurrency: { group: "a b" } }, /concurrency must be/);
|
|
146
|
+
bad({ checkout: { sparse: ["../x"] } }, /checkout\.sparse/);
|
|
147
|
+
bad({ toolchain: { rust: "latest" } }, /toolchain\.rust/);
|
|
148
|
+
bad({ toolchain: { swift: { version: "6.4.0", sha256: "abc" } } }, /toolchain\.swift/);
|
|
149
|
+
bad({ artifact: { name: "x${{ secrets.A }}", path: "out" } }, /artifact\.name may contain only/);
|
|
150
|
+
bad({ artifact: { name: "x", path: "../out" } }, /artifact\.path/);
|
|
151
|
+
bad({ artifact: { name: "x", path: "out", retentionDays: 400 } }, /retentionDays/);
|
|
152
|
+
bad({ artifact: { name: "x", path: "out", ifNoFilesFound: "skip" } }, /ifNoFilesFound/);
|
|
153
|
+
bad({ timeoutMinutes: 0 }, /timeoutMinutes/);
|
|
154
|
+
bad({ bogus: true }, /unknown workflows\.render-windows field: bogus/);
|
|
155
|
+
assert.ok(errorsFor({ a: { ...RENDER }, b: { ...RENDER } }).some((error) => /is also used by workflows\.a/.test(error)));
|
|
156
|
+
assert.ok(errorsFor({ "Bad Name": RENDER }).some((error) => /workflow names are lowercase/.test(error)));
|
|
157
|
+
assert.ok(errorsFor({ x: { kind: "nope" } }).some((error) => /kind must be one of/.test(error)));
|
|
158
|
+
assert.ok(errorsFor({}).some((error) => /1 to 8 named workflows/.test(error)));
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("matrix workflows need an artifact name that differs per job; windows swift-host needs the toolchain pin", () => {
|
|
162
|
+
const multi = { ...RENDER, runsOn: ["windows-2025", "macos-15"], artifact: { name: "same", path: "out" } };
|
|
163
|
+
assert.ok(errorsFor({ "render-windows": multi }).some((error) => /differs per job/.test(error)));
|
|
164
|
+
assert.deepEqual(errorsFor({ "render-windows": { ...multi, artifact: { name: "out-{os}", path: "out" } } }), []);
|
|
165
|
+
const noSwift = { ...SWIFT_HOST, toolchain: undefined };
|
|
166
|
+
assert.ok(errorsFor({ "swift-host": noSwift }).some((error) => /toolchain\.swift is required/.test(error)));
|
|
167
|
+
assert.deepEqual(errorsFor({ "swift-host": { ...noSwift, os: ["macos-15"] } }), []);
|
|
168
|
+
const jobNoToken = { ...FACTORY, jobs: [{ ...FACTORY.jobs[0], artifact: { name: "fixed", path: "out" } }] };
|
|
169
|
+
assert.ok(errorsFor({ "factory-pairs": jobNoToken }).some((error) => /differs per job/.test(error)));
|
|
170
|
+
assert.ok(errorsFor({ "factory-pairs": { ...FACTORY, on: { push: true } } }).some((error) => /workflow_dispatch must be true/.test(error)));
|
|
171
|
+
assert.ok(errorsFor({ "factory-pairs": { ...FACTORY, jobs: [{ ...FACTORY.jobs[0], id: "plan" }] } }).some((error) => /job id other than plan/.test(error)));
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("sync writes the workflows, drift matches them and a hand edit is detected", async () => {
|
|
175
|
+
const repo = makeTempRepo(withWorkflows({ "render-windows": RENDER, "swift-host": SWIFT_HOST }));
|
|
176
|
+
const plan = await planSync(repo, PUBLIC_DEPS);
|
|
177
|
+
assert.equal(plan.ok, true, JSON.stringify(plan.errors));
|
|
178
|
+
assert.deepEqual(plan.changes.map((change) => change.filename).sort(), ["ci.yml", "render-windows.yml", "swift-host-tests.yml"]);
|
|
179
|
+
assert.equal(applyPlan(repo, plan).ok, true);
|
|
180
|
+
const clean = await driftCommand(repo, PUBLIC_DEPS);
|
|
181
|
+
assert.equal(clean.driftDetected, false);
|
|
182
|
+
fs.appendFileSync(path.join(repo, ".github", "workflows", "render-windows.yml"), "# edit\n");
|
|
183
|
+
const edited = await driftCommand(repo, PUBLIC_DEPS);
|
|
184
|
+
assert.ok(edited.findings.some((finding) => finding.filename === "render-windows.yml" && finding.status === "mismatch"));
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("removing a workflow from the manifest removes its managed file on the next sync", async () => {
|
|
188
|
+
const repo = makeTempRepo(withWorkflows({ "render-windows": RENDER }));
|
|
189
|
+
assert.equal(applyPlan(repo, await planSync(repo, PUBLIC_DEPS)).ok, true);
|
|
190
|
+
fs.writeFileSync(path.join(repo, ".rightgit.json"), `${JSON.stringify(BASE)}\n`);
|
|
191
|
+
const plan = await planSync(repo, PUBLIC_DEPS);
|
|
192
|
+
assert.ok(plan.changes.some((change) => change.filename === "render-windows.yml" && change.action === "remove"));
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("run scripts allow only static expression forms; everything else must use a quoted env variable", () => {
|
|
196
|
+
const stepErrors = (run) => errorsFor({ "render-windows": { ...RENDER, steps: [{ shell: "bash", run }] } });
|
|
197
|
+
for (const run of ["echo \"${{ github['event']['pull_request']['title'] }}\"", "echo ${{ inputs.cases }}", "echo ${{ github.token }}", "echo ${{ env.X }}", "echo ${{ github.sha"]) {
|
|
198
|
+
assert.ok(stepErrors(run).some((error) => /pass any other value through a quoted env: variable/.test(error)), run);
|
|
199
|
+
}
|
|
200
|
+
for (const run of ["echo ${{ github.sha }} ${{ runner.os }} ${{ matrix.case }} ${{ github.run_id }} ${{ github.run_attempt }} ${{ 'lit-eral' }}", "echo \"$RIGHT_GIT_INPUT_CASES\""]) {
|
|
201
|
+
assert.deepEqual(stepErrors(run), [], run);
|
|
202
|
+
}
|
|
203
|
+
const files = renderByFile(withWorkflows({ "factory-pairs": FACTORY }));
|
|
204
|
+
assert.match(files["factory-pairs.yml"], /RIGHT_GIT_INPUT_CASES: \$\{\{ inputs\.cases \}\}/);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("step names are quoted scalars and swift-host os must be an array", () => {
|
|
208
|
+
const manifest = withWorkflows({ "render-windows": { ...RENDER, steps: [{ name: "Build: Windows", shell: "bash", run: "true" }] } });
|
|
209
|
+
assert.deepEqual(validateManifest(manifest).errors, []);
|
|
210
|
+
assert.match(renderByFile(manifest)["render-windows.yml"], /- name: 'Build: Windows'/);
|
|
211
|
+
const errors = errorsFor({ "swift-host": { ...SWIFT_HOST, os: "macos-15" } });
|
|
212
|
+
assert.ok(errors.some((error) => /swift-host\.os must be an array/.test(error)), errors.join(" | "));
|
|
213
|
+
});
|