@decohere/ci-tools 0.0.1-dev.20261110.287 → 0.0.1-dev.20261110.313

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.20261110.287",
3
+ "version": "0.0.1-dev.20261110.313",
4
4
  "description": "CI utility scripts for badge generation, coverage reporting, pages artifact assembly, and GitHub API tooling",
5
5
  "keywords": [
6
6
  "typescript",
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Prints the commit Publish compares a tested commit with, to see whether code changed: the last
4
+ * one that shipped (the newest `v*` tag behind it), or its parent when nothing has shipped yet.
5
+ * Not just the parent: the merge queue can land a code PR and a docs PR in one push, CI then runs
6
+ * on the docs commit only, and the code under it must still publish. Prints nothing for a first
7
+ * commit. Needs the history and the tags (`fetch-depth: 0`).
8
+ *
9
+ * node find-publish-base.mjs <sha>
10
+ */
11
+ import { execFileSync } from "node:child_process";
12
+ import { pathToFileURL } from "node:url";
13
+
14
+ function git(args, cwd) {
15
+ return execFileSync("git", args, {
16
+ cwd,
17
+ encoding: "utf8",
18
+ stdio: ["ignore", "pipe", "pipe"],
19
+ }).trim();
20
+ }
21
+
22
+ /** Runs git, and returns undefined when it exits with `notFound`: what it uses to say it found nothing. */
23
+ function tryGit(args, cwd, notFound) {
24
+ try {
25
+ return git(args, cwd);
26
+ } catch (error) {
27
+ if (error.status === notFound) return undefined;
28
+ throw error;
29
+ }
30
+ }
31
+
32
+ /**
33
+ * @param {string} sha the commit CI tested
34
+ * @param {string} [cwd] the repository
35
+ * @returns {string | undefined}
36
+ */
37
+ export function findPublishBase(sha, cwd = process.cwd()) {
38
+ const parent = tryGit(["rev-parse", "--verify", "--quiet", `${sha}^1`], cwd, 1);
39
+ if (parent == null) return undefined;
40
+ const tag = tryGit(
41
+ ["describe", "--tags", "--abbrev=0", "--match", "v[0-9]*", parent],
42
+ cwd,
43
+ 128,
44
+ );
45
+ return tag == null ? parent : git(["rev-parse", `${tag}^{commit}`], cwd);
46
+ }
47
+
48
+ if (import.meta.url === pathToFileURL(process.argv[1]).href) {
49
+ const base = findPublishBase(process.argv[2]);
50
+ if (base != null) console.log(base);
51
+ }
@@ -39,6 +39,14 @@ describe("publish.yml", () => {
39
39
  expect(guard).toContain("Give either tested_version or patch_branch");
40
40
  });
41
41
 
42
+ it("looks for code changes since the last shipped commit, not the parent", () => {
43
+ const guard = yml.slice(yml.indexOf("\n guard:"), yml.indexOf("\n release-build:"));
44
+
45
+ expect(guard).toContain("find-publish-base.mjs");
46
+ expect(guard).toContain("fetch-depth: 0");
47
+ expect(guard).not.toContain("HEAD^1");
48
+ });
49
+
42
50
  it("only releases a patch whose commit passed full CI", () => {
43
51
  const guard = yml.slice(yml.indexOf("\n guard:"), yml.indexOf("\n release-build:"));
44
52