@decohere/ci-tools 0.0.1-dev.20261106.217 → 0.0.1-dev.20261106.228
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decohere/ci-tools",
|
|
3
|
-
"version": "0.0.1-dev.20261106.
|
|
3
|
+
"version": "0.0.1-dev.20261106.228",
|
|
4
4
|
"description": "CI utility scripts for badge generation, coverage reporting, pages artifact assembly, and GitHub API tooling",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
package/src/badges/ci-status.mjs
CHANGED
|
@@ -13,10 +13,7 @@ if (repo == null || token == null) {
|
|
|
13
13
|
|
|
14
14
|
const workflowFileName = "ci.yml";
|
|
15
15
|
|
|
16
|
-
const branches = [
|
|
17
|
-
{ branch: "main", label: "CI Main", file: "ci-main.svg" },
|
|
18
|
-
{ branch: "release", label: "CI Release", file: "ci-release.svg" },
|
|
19
|
-
];
|
|
16
|
+
const branches = [{ branch: "main", label: "CI Main", file: "ci-main.svg" }];
|
|
20
17
|
|
|
21
18
|
async function getLatestWorkflowRun(branch) {
|
|
22
19
|
const url =
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Checks a patch release before it starts: the branch is a `release/<major>.<minor>` branch, the
|
|
4
|
+
* version belongs on it, and it's newer than npm `latest`. A patch of an older line would take
|
|
5
|
+
* `latest` backwards, and there's no separate dist-tag for those yet.
|
|
6
|
+
*
|
|
7
|
+
* node check-patch-release.mjs <branch> <version> <npm latest>
|
|
8
|
+
*/
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
10
|
+
|
|
11
|
+
const BRANCH = /^release\/(\d+)\.(\d+)$/;
|
|
12
|
+
const VERSION = /^(\d+)\.(\d+)\.(\d+)/;
|
|
13
|
+
|
|
14
|
+
/** A dev version such as 0.0.1-dev.1 sorts below 0.0.1. */
|
|
15
|
+
function isOlderOrSame(version, than) {
|
|
16
|
+
const parts = (text) => VERSION.exec(text)?.slice(1).map(Number) ?? [0, 0, 0];
|
|
17
|
+
const [a, b] = [parts(version), parts(than)];
|
|
18
|
+
for (const index of [0, 1, 2]) {
|
|
19
|
+
if (a[index] !== b[index]) return a[index] < b[index];
|
|
20
|
+
}
|
|
21
|
+
return !version.includes("-") && !than.includes("-");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @param {{ branch: string, version: string, latest: string }} options */
|
|
25
|
+
export function checkPatchRelease({ branch, version, latest }) {
|
|
26
|
+
const line = BRANCH.exec(branch);
|
|
27
|
+
if (line == null) {
|
|
28
|
+
throw new Error(`${branch} isn't a patch branch: expected release/<major>.<minor>`);
|
|
29
|
+
}
|
|
30
|
+
const parts = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
|
|
31
|
+
if (parts == null || parts[1] !== line[1] || parts[2] !== line[2]) {
|
|
32
|
+
throw new Error(`${version} isn't on ${branch}`);
|
|
33
|
+
}
|
|
34
|
+
if (Number(parts[3]) === 0) {
|
|
35
|
+
throw new Error(`${version} isn't a patch: its last number is 0`);
|
|
36
|
+
}
|
|
37
|
+
if (isOlderOrSame(version, latest)) {
|
|
38
|
+
throw new Error(`${version} isn't newer: it's older than latest (${latest}), or the same`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
43
|
+
const [branch, version, latest] = process.argv.slice(2);
|
|
44
|
+
try {
|
|
45
|
+
checkPatchRelease({ branch, version, latest });
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error(`::error::${error.message}`);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -17,6 +17,17 @@ describe("ci.yml and the merge queue", () => {
|
|
|
17
17
|
expect(gate).toContain('"${{ github.event_name }}" == "merge_group"');
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
it("runs the whole suite on a patch branch, whose commits weren't tested on main", () => {
|
|
21
|
+
const jobs = yml.slice(yml.indexOf("\njobs:"));
|
|
22
|
+
expect(triggers).toContain('branches: [main, "release/**"]');
|
|
23
|
+
for (const job of ["coverage", "build", "verify-release"]) {
|
|
24
|
+
const start = jobs.indexOf(`\n ${job}:`);
|
|
25
|
+
expect(jobs.slice(start, jobs.indexOf("runs-on:", start)), job).toContain(
|
|
26
|
+
"startsWith(github.ref, 'refs/heads/release/')",
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
20
31
|
it("makes the required check wait for every job, so a failing job can't be missed", () => {
|
|
21
32
|
const jobs = yml.slice(yml.indexOf("\njobs:"));
|
|
22
33
|
const names = [...jobs.matchAll(/^ {2}([a-z-]+):$/gm)].map((match) => match[1]);
|
|
@@ -30,6 +30,47 @@ describe("publish.yml", () => {
|
|
|
30
30
|
expect(build).not.toContain("forge --log-level info build");
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
+
it("takes either a tested version or a patch branch, and checks a patch before using it", () => {
|
|
34
|
+
const inputs = yml.slice(yml.indexOf("workflow_dispatch:"), yml.indexOf("\nconcurrency:"));
|
|
35
|
+
const guard = yml.slice(yml.indexOf("\n guard:"), yml.indexOf("\n release-build:"));
|
|
36
|
+
|
|
37
|
+
expect(inputs).toContain("patch_branch:");
|
|
38
|
+
expect(guard).toContain("check-patch-release.mjs");
|
|
39
|
+
expect(guard).toContain("Give either tested_version or patch_branch");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("only releases a patch whose commit passed full CI", () => {
|
|
43
|
+
const guard = yml.slice(yml.indexOf("\n guard:"), yml.indexOf("\n release-build:"));
|
|
44
|
+
|
|
45
|
+
expect(guard).toContain("event=push&status=success");
|
|
46
|
+
expect(guard.indexOf("git/ref/heads/")).toBeLessThan(
|
|
47
|
+
guard.indexOf("event=push&status=success"),
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("reads a patch's tested version from its build", () => {
|
|
52
|
+
const build = yml.slice(yml.indexOf("\n release-build:"), yml.indexOf("\n verify:"));
|
|
53
|
+
|
|
54
|
+
expect(build).toContain("dist/release/projects/cli/package.json");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("never lowers main's base version after a patch", () => {
|
|
58
|
+
const finish = yml.slice(
|
|
59
|
+
yml.indexOf("\n release-finish:"),
|
|
60
|
+
yml.indexOf("\n failure-report:"),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
expect(finish).toContain("sort -V");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("doesn't publish a patch branch by itself: only main publishes automatically", () => {
|
|
67
|
+
const on = yml.slice(0, yml.indexOf("workflow_dispatch:"));
|
|
68
|
+
const guard = yml.slice(yml.indexOf("\n guard:"), yml.indexOf("\n release-build:"));
|
|
69
|
+
|
|
70
|
+
expect(on).toContain("branches: [main]");
|
|
71
|
+
expect(guard).toContain("head_branch == 'main'");
|
|
72
|
+
});
|
|
73
|
+
|
|
33
74
|
it("only tags a version once npm and the images have shipped", () => {
|
|
34
75
|
const tag = yml.slice(yml.indexOf("\n tag:"));
|
|
35
76
|
const needs = /needs: \[(.+)\]/.exec(tag)?.[1].split(", ");
|