@maniumek/suwgate 0.13.0 → 0.14.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 CHANGED
@@ -103,7 +103,7 @@ Every subcommand answers `--help`. The `dev` section and what each command does:
103
103
 
104
104
  <picture>
105
105
  <source media="(prefers-color-scheme: dark)" srcset="docs/visual/board/img/readme/ci-dark.png">
106
- <img alt="CI, releases and dependencies. Reusable workflows, pinned by commit: gate.yml (proof, gate, smoke, stamp; tools installed with checksums; consumer: a kit tested in a real app); release-npm.yml (changesets: the Version Packages pull request, then build and pack; npm trusted publishing); release-nuget.yml (full history, dotnet pack in Release, the artifact nupkg; NuGet trusted publishing). Self-hosted fallback: private repositories move to local runners when the month's Actions minutes run out: CI_RUNNER=suw-local, set and cleared by a timer. Renovate for every repository: once a week (new pull requests on Monday before 6:00 Warsaw time); two pull requests (minor and patch in one, majors in the other); merged on green (Renovate merges once the checks pass, a red one stays open); holds follow peers (TypeScript held to what typescript-eslint accepts, moved by pull request). Left to people: the minimum SDK in global.json, PostgreSQL majors, Langfuse's stack, hash-pinned Python requirements." src="docs/visual/board/img/readme/ci-light.png" width="100%">
106
+ <img alt="CI, releases and dependencies. Reusable workflows, pinned by commit: gate.yml (proof, gate, smoke, stamp; tools installed with checksums; consumer: a kit tested in a real app); release-npm.yml (changesets: publish the version a merged branch moved, then build and pack; npm trusted publishing); release-nuget.yml (full history, dotnet pack in Release, the artifact nupkg; NuGet trusted publishing). Self-hosted fallback: private repositories move to local runners when the month's Actions minutes run out: CI_RUNNER=suw-local, set and cleared by a timer. Renovate for every repository: once a week (new pull requests on Monday before 6:00 Warsaw time); two pull requests (minor and patch in one, majors in the other); merged on green (Renovate merges once the checks pass, a red one stays open); holds follow peers (TypeScript held to what typescript-eslint accepts, moved by pull request). Left to people: the minimum SDK in global.json, PostgreSQL majors, Langfuse's stack, hash-pinned Python requirements." src="docs/visual/board/img/readme/ci-light.png" width="100%">
107
107
  </picture>
108
108
 
109
109
  A repository's whole `ci.yml` can be one job:
@@ -4,7 +4,11 @@ const CHANGESET = script([
4
4
  'base=""',
5
5
  "if git rev-parse --verify -q origin/master >/dev/null; then base=origin/master; elif git rev-parse --verify -q master >/dev/null; then base=master; fi",
6
6
  'if [ -z "$base" ] || [ "$(git rev-parse HEAD 2>/dev/null)" = "$(git rev-parse "$base")" ]; then echo "on $base itself or no master yet: nothing to compare with"; exit 0; fi',
7
- 'pnpm exec changeset status --since "$base"',
7
+ "pending=\"$(find .changeset -maxdepth 1 -name '*.md' ! -name README.md 2>/dev/null | sort)\"",
8
+ 'if [ -n "$pending" ]; then echo "$pending" >&2; echo "version these changesets in this branch: pnpm exec changeset version, then commit package.json and CHANGELOG.md; the merge publishes, with no Version Packages pull request" >&2; exit 1; fi',
9
+ 'version() { node -p \'JSON.parse(require("fs").readFileSync(0, "utf8")).version\'; }',
10
+ 'if [ "$(git show "$base:./package.json" | version)" != "$(version < package.json)" ]; then echo "the version moved since $base: the merge publishes it"; exit 0; fi',
11
+ 'pnpm exec changeset status --since "$base" || { echo "add a changeset (pnpm exec changeset), version it (pnpm exec changeset version) and commit package.json and CHANGELOG.md" >&2; exit 1; }',
8
12
  ]);
9
13
  const PUBLINT = script([
10
14
  'work="$(mktemp -d)"',
@@ -127,7 +131,7 @@ export const librarySteps = [
127
131
  },
128
132
  {
129
133
  id: "changeset",
130
- title: "a changeset for a change of the package since master (changeset status)",
134
+ title: "a change of the package since master carries its new version and CHANGELOG entry (changeset version, changeset status)",
131
135
  profile: "library",
132
136
  needs: ["pnpm"],
133
137
  after,
@@ -1,17 +1,27 @@
1
+ import { homedir } from "node:os";
2
+ import path from "node:path";
1
3
  import { hasShipRecord, treeOf } from "./shipRecord.js";
2
4
  const BUILT_IN = ["gh pr create"];
3
5
  const SKIPPED_HOOKS = /(?<![\w-])git\s+(?:\S+\s+)*?(?:push|commit)\b[^;&|]*\s--no-verify(?![\w-])/;
4
6
  const NO_RECORD = "No ship record for this commit: run /suwagent:ship first; it simplifies, checks the changed tests, then pushes and opens the pull request.";
5
- function commandOf(input) {
7
+ function callOf(input, root) {
6
8
  try {
7
9
  const parsed = JSON.parse(input);
8
10
  const command = parsed.tool_input?.command;
9
- return typeof command === "string" ? command : "";
11
+ return { command: typeof command === "string" ? command : "", cwd: typeof parsed.cwd === "string" ? parsed.cwd : root };
10
12
  }
11
13
  catch {
12
- return "";
14
+ return { command: "", cwd: root };
13
15
  }
14
16
  }
17
+ const CD = /(?:^|[;&|(]\s*)cd\s+("[^"]+"|'[^']+'|[^\s;&|)]+)/g;
18
+ function directoryOf(call) {
19
+ const last = [...call.command.matchAll(CD)].at(-1)?.[1];
20
+ if (last === undefined)
21
+ return call.cwd;
22
+ const unquoted = last.replace(/^(["'])(.*)\1$/, "$2").replace(/^~(?=\/|$)/, homedir());
23
+ return path.resolve(call.cwd, unquoted);
24
+ }
15
25
  function pattern(words) {
16
26
  const escaped = words
17
27
  .trim()
@@ -21,11 +31,12 @@ function pattern(words) {
21
31
  }
22
32
  const SKIPPING = "An agent never skips git hooks: drop --no-verify. A push needs a ship record: run /suwagent:ship, which pushes for you.";
23
33
  export function guardPr(input, root, prCommands) {
24
- const command = commandOf(input);
25
- if (SKIPPED_HOOKS.test(command))
34
+ const call = callOf(input, root);
35
+ if (SKIPPED_HOOKS.test(call.command))
26
36
  return { exitCode: 2, message: SKIPPING };
27
- const guarded = [...BUILT_IN, ...prCommands].filter((words) => words.trim() !== "").some((words) => pattern(words).test(command));
28
- if (!guarded || hasShipRecord(root, treeOf(root, "HEAD")))
37
+ const guarded = [...BUILT_IN, ...prCommands].filter((words) => words.trim() !== "").some((words) => pattern(words).test(call.command));
38
+ const directory = directoryOf(call);
39
+ if (!guarded || hasShipRecord(directory, treeOf(directory, "HEAD")))
29
40
  return { exitCode: 0, message: "" };
30
41
  return { exitCode: 2, message: NO_RECORD };
31
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maniumek/suwgate",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "One quality gate for every repository: suwgate check runs the steps of the repository's profiles and its guards, configured in suwgate.yml",
5
5
  "license": "MIT",
6
6
  "author": "Manomenu",