@biffo/cli 0.236.0 → 0.238.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/_skeletons/plugin-template/.githooks/pre-push +8 -5
- package/_skeletons/plugin-template/AGENTS.md +22 -4
- package/_skeletons/plugin-template/scripts/verify.sh +6 -2
- package/_skeletons/sibling-template/.githooks/pre-push +8 -5
- package/_skeletons/sibling-template/AGENTS.md +20 -2
- package/_skeletons/sibling-template/scripts/verify.sh +6 -2
- package/dist/index.js +65 -16
- package/package.json +7 -2
- package/_skeletons/sibling-template/scripts/branch-health.sh +0 -306
- package/_skeletons/sibling-template/scripts/claim.sh +0 -208
- package/_skeletons/sibling-template/scripts/hook-audit.sh +0 -145
- package/_skeletons/sibling-template/scripts/pg-test-db.sh +0 -275
- package/_skeletons/sibling-template/scripts/rewrite-scope-check.sh +0 -189
- /package/{_skeletons/plugin-template/scripts → scripts}/branch-health.sh +0 -0
- /package/{_skeletons/plugin-template/scripts → scripts}/claim.sh +0 -0
- /package/{_skeletons/plugin-template/scripts → scripts}/hook-audit.sh +0 -0
- /package/{_skeletons/plugin-template/scripts → scripts}/pg-test-db.sh +0 -0
- /package/{_skeletons/plugin-template/scripts → scripts}/rewrite-scope-check.sh +0 -0
|
@@ -31,11 +31,14 @@ cd "$root" || exit 0
|
|
|
31
31
|
# Why it exists: a force-push can quietly add a file to a branch's change set
|
|
32
32
|
# and record a stale copy of somebody else's merged work as your own change.
|
|
33
33
|
# That happened (tabsii-platform#446) and every local gate was green on it.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
# Runs from the version-pinned CLI rather than a per-repo copy (#1109).
|
|
35
|
+
#
|
|
36
|
+
# This used to warn and CONTINUE when the script was absent, which is a
|
|
37
|
+
# fail-open in a gate whose whole job is refusing a push: the one repo missing
|
|
38
|
+
# the file was the one where nothing checked. There is no absent case now --
|
|
39
|
+
# the bridge resolves the script from the package -- and if the bridge itself
|
|
40
|
+
# cannot run, that is a reason to stop, not to wave the push through.
|
|
41
|
+
sh scripts/biffo.sh rewrite-scope-check || exit 1
|
|
39
42
|
|
|
40
43
|
if [ ! -f scripts/verify.sh ]; then
|
|
41
44
|
echo "pre-push: no scripts/verify.sh — NO checks ran (see local-gates.md)" >&2
|
|
@@ -48,7 +48,7 @@ This file is distributed by the template and kept in step by
|
|
|
48
48
|
**Before starting work on an issue, run:**
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
|
-
sh scripts/
|
|
51
|
+
sh scripts/biffo.sh claim <issue-number> [-R owner/repo] # 0 free · 1 taken · 2 cannot tell
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
Several agent sessions run against this estate at once. The script asks four
|
|
@@ -127,7 +127,25 @@ it deliberately and say so in a comment; never steal a fresh one.
|
|
|
127
127
|
before merge: `git log origin/<branch> -1`. A green PR page is not proof your
|
|
128
128
|
latest local commit reached it.
|
|
129
129
|
|
|
130
|
-
## 7.
|
|
130
|
+
## 7. Verify post-merge
|
|
131
|
+
|
|
132
|
+
- A merge is not done when the PR closes. **Check the whole branch:**
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
sh scripts/biffo.sh branch-health [-R owner/repo] # 0 green · 1 red · 2 cannot tell
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
It reports the latest run of **every** workflow on the integration branch, so
|
|
139
|
+
the deploy cannot fall off the bottom of a short `gh run list` — and when
|
|
140
|
+
something is red it names the **first** failing commit, not the newest.
|
|
141
|
+
|
|
142
|
+
- **Check whether the branch was already failing before diagnosing your own
|
|
143
|
+
change.** A red deploy has no audience: the author who broke it has moved on,
|
|
144
|
+
and every later merge fails on damage it did not cause. On 2026-08-02 that
|
|
145
|
+
cost 2h25m and four people each diagnosed their own innocent change.
|
|
146
|
+
- Exit 2 is "cannot tell" and is never a pass.
|
|
147
|
+
|
|
148
|
+
## 8. Creating this repo correctly (read once, at birth)
|
|
131
149
|
|
|
132
150
|
**No `biffo` command creates a standalone plugin repo.** `biffo plugin create`
|
|
133
151
|
scaffolds a plugin _into an existing checkout_; a repo like this one is made by
|
|
@@ -159,7 +177,7 @@ biffo check branch-protection --repo <org>/<repo>
|
|
|
159
177
|
> that means merging with checks still running. Steps 1 and 2 together are what
|
|
160
178
|
> make the documented flow behave as documented; either alone is not enough.
|
|
161
179
|
|
|
162
|
-
##
|
|
180
|
+
## 9. CI runners — two steps this repo cannot do for itself
|
|
163
181
|
|
|
164
182
|
The workflows use `runs-on: ${{ vars.RUNNER_LABEL || 'ubuntu-latest' }}`, so they
|
|
165
183
|
work anywhere by default and route to a self-hosted fleet when one exists. Two
|
|
@@ -176,7 +194,7 @@ fleet:
|
|
|
176
194
|
If a job is queued and nothing is happening, check the grant before anything
|
|
177
195
|
else. It is the failure that looks exactly like patience.
|
|
178
196
|
|
|
179
|
-
##
|
|
197
|
+
## 10. Security
|
|
180
198
|
|
|
181
199
|
- **Never commit secrets** (keys, tokens, credentials, `.env` values).
|
|
182
200
|
- **Never silently disable a security gate.** If one must be loosened, do it in
|
|
@@ -662,8 +662,12 @@ _pg_modules=$(pg_test_modules)
|
|
|
662
662
|
# rebuild), so calling it is better than warning about it. Failure is silent
|
|
663
663
|
# BECAUSE the WARN below is the honest report of it -- no Docker, no server, no
|
|
664
664
|
# schema all end in the same place: the lane did not run, and the gate says so.
|
|
665
|
-
if [ -z "$PG_TEST_DSN" ] && [ -n "$_pg_modules" ] && [ -z "$LIST" ]
|
|
666
|
-
|
|
665
|
+
if [ -z "$PG_TEST_DSN" ] && [ -n "$_pg_modules" ] && [ -z "$LIST" ]; then
|
|
666
|
+
# Through the bridge since #1109; the `-f scripts/pg-test-db.sh` guard went
|
|
667
|
+
# with the copy. Failure stays silent here BECAUSE the WARN below is the
|
|
668
|
+
# honest report of it -- no Docker, no server, no schema and no CLI all end
|
|
669
|
+
# in the same place: the lane did not run, and the gate says so.
|
|
670
|
+
PG_TEST_DSN=$(sh scripts/biffo.sh pg-test-db 2>/dev/null | tail -1) || PG_TEST_DSN=""
|
|
667
671
|
case "$PG_TEST_DSN" in
|
|
668
672
|
postgres*) ;;
|
|
669
673
|
*) PG_TEST_DSN="" ;;
|
|
@@ -31,11 +31,14 @@ cd "$root" || exit 0
|
|
|
31
31
|
# Why it exists: a force-push can quietly add a file to a branch's change set
|
|
32
32
|
# and record a stale copy of somebody else's merged work as your own change.
|
|
33
33
|
# That happened (tabsii-platform#446) and every local gate was green on it.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
# Runs from the version-pinned CLI rather than a per-repo copy (#1109).
|
|
35
|
+
#
|
|
36
|
+
# This used to warn and CONTINUE when the script was absent, which is a
|
|
37
|
+
# fail-open in a gate whose whole job is refusing a push: the one repo missing
|
|
38
|
+
# the file was the one where nothing checked. There is no absent case now --
|
|
39
|
+
# the bridge resolves the script from the package -- and if the bridge itself
|
|
40
|
+
# cannot run, that is a reason to stop, not to wave the push through.
|
|
41
|
+
sh scripts/biffo.sh rewrite-scope-check || exit 1
|
|
39
42
|
|
|
40
43
|
if [ ! -f scripts/verify.sh ]; then
|
|
41
44
|
echo "pre-push: no scripts/verify.sh — NO checks ran (see local-gates.md)" >&2
|
|
@@ -48,7 +48,7 @@ This file is distributed by the template and kept in step by
|
|
|
48
48
|
**Before starting work on an issue, run:**
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
|
-
sh scripts/
|
|
51
|
+
sh scripts/biffo.sh claim <issue-number> [-R owner/repo] # 0 free · 1 taken · 2 cannot tell
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
Several agent sessions run against this estate at once. The script asks four
|
|
@@ -127,7 +127,25 @@ it deliberately and say so in a comment; never steal a fresh one.
|
|
|
127
127
|
before merge: `git log origin/<branch> -1`. A green PR page is not proof your
|
|
128
128
|
latest local commit reached it.
|
|
129
129
|
|
|
130
|
-
## 7.
|
|
130
|
+
## 7. Verify post-merge
|
|
131
|
+
|
|
132
|
+
- A merge is not done when the PR closes. **Check the whole branch:**
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
sh scripts/biffo.sh branch-health [-R owner/repo] # 0 green · 1 red · 2 cannot tell
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
It reports the latest run of **every** workflow on the integration branch, so
|
|
139
|
+
the deploy cannot fall off the bottom of a short `gh run list` — and when
|
|
140
|
+
something is red it names the **first** failing commit, not the newest.
|
|
141
|
+
|
|
142
|
+
- **Check whether the branch was already failing before diagnosing your own
|
|
143
|
+
change.** A red deploy has no audience: the author who broke it has moved on,
|
|
144
|
+
and every later merge fails on damage it did not cause. On 2026-08-02 that
|
|
145
|
+
cost 2h25m and four people each diagnosed their own innocent change.
|
|
146
|
+
- Exit 2 is "cannot tell" and is never a pass.
|
|
147
|
+
|
|
148
|
+
## 8. Security
|
|
131
149
|
|
|
132
150
|
- **Never commit secrets** (keys, tokens, credentials, `.env` values).
|
|
133
151
|
- **Never silently disable a security gate.** If one must be loosened, do it in
|
|
@@ -662,8 +662,12 @@ _pg_modules=$(pg_test_modules)
|
|
|
662
662
|
# rebuild), so calling it is better than warning about it. Failure is silent
|
|
663
663
|
# BECAUSE the WARN below is the honest report of it -- no Docker, no server, no
|
|
664
664
|
# schema all end in the same place: the lane did not run, and the gate says so.
|
|
665
|
-
if [ -z "$PG_TEST_DSN" ] && [ -n "$_pg_modules" ] && [ -z "$LIST" ]
|
|
666
|
-
|
|
665
|
+
if [ -z "$PG_TEST_DSN" ] && [ -n "$_pg_modules" ] && [ -z "$LIST" ]; then
|
|
666
|
+
# Through the bridge since #1109; the `-f scripts/pg-test-db.sh` guard went
|
|
667
|
+
# with the copy. Failure stays silent here BECAUSE the WARN below is the
|
|
668
|
+
# honest report of it -- no Docker, no server, no schema and no CLI all end
|
|
669
|
+
# in the same place: the lane did not run, and the gate says so.
|
|
670
|
+
PG_TEST_DSN=$(sh scripts/biffo.sh pg-test-db 2>/dev/null | tail -1) || PG_TEST_DSN=""
|
|
667
671
|
case "$PG_TEST_DSN" in
|
|
668
672
|
postgres*) ;;
|
|
669
673
|
*) PG_TEST_DSN="" ;;
|
package/dist/index.js
CHANGED
|
@@ -10770,7 +10770,7 @@ function resolveGithubToken4() {
|
|
|
10770
10770
|
);
|
|
10771
10771
|
}
|
|
10772
10772
|
|
|
10773
|
-
// src/
|
|
10773
|
+
// src/lib/packaged-script-command.ts
|
|
10774
10774
|
import { spawnSync } from "child_process";
|
|
10775
10775
|
import { dirname as dirname11 } from "path";
|
|
10776
10776
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
@@ -10794,22 +10794,66 @@ function packagedScriptMissing(relativePath) {
|
|
|
10794
10794
|
It ships with this package via cli/scripts/packaged-root-assets.mjs; if you are running from a checkout, run from inside the template repo. If you are running the published package, this is a packaging bug \u2014 the asset was not copied at prepack.`;
|
|
10795
10795
|
}
|
|
10796
10796
|
|
|
10797
|
-
// src/
|
|
10798
|
-
|
|
10799
|
-
|
|
10800
|
-
|
|
10801
|
-
|
|
10802
|
-
|
|
10803
|
-
|
|
10804
|
-
|
|
10805
|
-
|
|
10797
|
+
// src/lib/packaged-script-command.ts
|
|
10798
|
+
function packagedScriptCommand(spec) {
|
|
10799
|
+
const command = new Command26(spec.name).description(spec.description).allowExcessArguments(true).allowUnknownOption(true);
|
|
10800
|
+
if (spec.argument) command.argument(`<${spec.argument.name}>`, spec.argument.description);
|
|
10801
|
+
return command.action(() => {
|
|
10802
|
+
const here = dirname11(fileURLToPath6(import.meta.url));
|
|
10803
|
+
const script = findPackagedScript(here, spec.script);
|
|
10804
|
+
if (!script) {
|
|
10805
|
+
process.stderr.write(`${packagedScriptMissing(spec.script)}
|
|
10806
10806
|
`);
|
|
10807
|
-
|
|
10808
|
-
|
|
10809
|
-
|
|
10810
|
-
|
|
10811
|
-
|
|
10812
|
-
|
|
10807
|
+
process.exit(2);
|
|
10808
|
+
}
|
|
10809
|
+
const at = process.argv.indexOf(spec.name);
|
|
10810
|
+
const args = at === -1 ? [] : process.argv.slice(at + 1);
|
|
10811
|
+
const result = spawnSync("sh", [script, ...args], { stdio: "inherit" });
|
|
10812
|
+
process.exit(result.status === null ? 2 : result.status);
|
|
10813
|
+
});
|
|
10814
|
+
}
|
|
10815
|
+
|
|
10816
|
+
// src/commands/hook-audit.ts
|
|
10817
|
+
var hookAuditCommand = packagedScriptCommand({
|
|
10818
|
+
name: "hook-audit",
|
|
10819
|
+
script: "scripts/hook-audit.sh",
|
|
10820
|
+
description: "Report whether git hooks will actually fire in every working tree"
|
|
10821
|
+
});
|
|
10822
|
+
|
|
10823
|
+
// src/commands/pg-test-db.ts
|
|
10824
|
+
var pgTestDbCommand = packagedScriptCommand({
|
|
10825
|
+
name: "pg-test-db",
|
|
10826
|
+
script: "scripts/pg-test-db.sh",
|
|
10827
|
+
description: "Provision the local Postgres test database and print its DSN"
|
|
10828
|
+
});
|
|
10829
|
+
|
|
10830
|
+
// src/commands/rewrite-scope-check.ts
|
|
10831
|
+
var rewriteScopeCheckCommand = packagedScriptCommand({
|
|
10832
|
+
name: "rewrite-scope-check",
|
|
10833
|
+
script: "scripts/rewrite-scope-check.sh",
|
|
10834
|
+
description: "Refuse a push whose rewrite scope absorbs merged work from another branch"
|
|
10835
|
+
});
|
|
10836
|
+
|
|
10837
|
+
// src/commands/branch-health.ts
|
|
10838
|
+
var branchHealthCommand = packagedScriptCommand({
|
|
10839
|
+
name: "branch-health",
|
|
10840
|
+
script: "scripts/branch-health.sh",
|
|
10841
|
+
description: "Report every workflow on the integration branch (0 green, 1 red, 2 cannot tell)"
|
|
10842
|
+
});
|
|
10843
|
+
|
|
10844
|
+
// src/commands/claim.ts
|
|
10845
|
+
var claimCommand = packagedScriptCommand({
|
|
10846
|
+
name: "claim",
|
|
10847
|
+
script: "scripts/claim.sh",
|
|
10848
|
+
description: "Check and claim an issue before starting (0 free, 1 taken, 2 cannot tell)"
|
|
10849
|
+
});
|
|
10850
|
+
|
|
10851
|
+
// src/commands/wait-for-checks.ts
|
|
10852
|
+
var waitForChecksCommand = packagedScriptCommand({
|
|
10853
|
+
name: "wait-for-checks",
|
|
10854
|
+
script: "scripts/wait-for-checks.sh",
|
|
10855
|
+
description: "Wait for a PR\u2019s required checks on a positive signal (0 green, 1 failed, 2 cannot tell)",
|
|
10856
|
+
argument: { name: "pr", description: "Pull request number" }
|
|
10813
10857
|
});
|
|
10814
10858
|
|
|
10815
10859
|
// src/index.ts
|
|
@@ -10827,6 +10871,11 @@ program.addCommand(deployCommand);
|
|
|
10827
10871
|
program.addCommand(destroyCommand);
|
|
10828
10872
|
program.addCommand(teardownCommand);
|
|
10829
10873
|
program.addCommand(waitForChecksCommand);
|
|
10874
|
+
program.addCommand(branchHealthCommand);
|
|
10875
|
+
program.addCommand(claimCommand);
|
|
10876
|
+
program.addCommand(hookAuditCommand);
|
|
10877
|
+
program.addCommand(pgTestDbCommand);
|
|
10878
|
+
program.addCommand(rewriteScopeCheckCommand);
|
|
10830
10879
|
program.addCommand(pluginCommand);
|
|
10831
10880
|
program.addCommand(dataCommand);
|
|
10832
10881
|
program.addCommand(coreCommand);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@biffo/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.238.0",
|
|
4
4
|
"description": "Biffo project scaffolding CLI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,12 @@
|
|
|
24
24
|
"dist",
|
|
25
25
|
"schemas",
|
|
26
26
|
"_skeletons",
|
|
27
|
-
"scripts/wait-for-checks.sh"
|
|
27
|
+
"scripts/wait-for-checks.sh",
|
|
28
|
+
"scripts/branch-health.sh",
|
|
29
|
+
"scripts/claim.sh",
|
|
30
|
+
"scripts/hook-audit.sh",
|
|
31
|
+
"scripts/pg-test-db.sh",
|
|
32
|
+
"scripts/rewrite-scope-check.sh"
|
|
28
33
|
],
|
|
29
34
|
"scripts": {
|
|
30
35
|
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
# Is the integration branch actually healthy — including the deploy, and
|
|
4
|
-
# including who broke it?
|
|
5
|
-
#
|
|
6
|
-
# ## Why this exists
|
|
7
|
-
#
|
|
8
|
-
# On 2026-08-02 an instance's `dev` deploy went red at 10:43 and nobody noticed
|
|
9
|
-
# until 12:36. **1h53m, four further merges**, each of which also failed, and
|
|
10
|
-
# development was effectively blocked for 2h25m. Three separate things had to be
|
|
11
|
-
# true at once for that to happen, and this script answers all three (#1133).
|
|
12
|
-
#
|
|
13
|
-
# **1. The obvious command hides the deploy.** An instance runs five workflows on
|
|
14
|
-
# a merge to `dev` — `CI`, `CodeQL`, `Core Version Tag`, `Deploy Application`,
|
|
15
|
-
# `RLS Tests` — and the reflexive check is:
|
|
16
|
-
#
|
|
17
|
-
# gh run list --branch dev --limit 3
|
|
18
|
-
#
|
|
19
|
-
# which returns three that are *not* the deploy. "dev CI green" was reported
|
|
20
|
-
# truthfully and repeatedly by an agent following AGENTS.md, while the deploy was
|
|
21
|
-
# red the whole time. A truncated list is not a status; it is a sample. This
|
|
22
|
-
# script enumerates **every** workflow that ran on the branch and reports the
|
|
23
|
-
# latest conclusion of each, so nothing can fall off the bottom.
|
|
24
|
-
#
|
|
25
|
-
# **2. A red post-merge deploy has no audience.** A failing PR check is noticed
|
|
26
|
-
# because someone is watching their PR. A failing *post-merge* deploy is watched
|
|
27
|
-
# by nobody: the author has moved on, and the next person only discovers it by
|
|
28
|
-
# merging into it. So this notifies, reusing the desktop-alert channel
|
|
29
|
-
# `practices-daily.sh` established (`_notify`) — same opt-OUT posture, because an
|
|
30
|
-
# opt-in alert is how that notification once spent months existing and never
|
|
31
|
-
# firing.
|
|
32
|
-
#
|
|
33
|
-
# **3. A poisoned branch blames the wrong person.** Once `dev` is broken every
|
|
34
|
-
# subsequent merge fails too, so four people each saw *their* change fail. The
|
|
35
|
-
# expensive part was not the breakage, it was four independent diagnoses of an
|
|
36
|
-
# innocent change. On failure this walks the run history back to the **first
|
|
37
|
-
# failing run** and names its commit, author and time — so the fifth person in
|
|
38
|
-
# starts at the real cause instead of their own diff.
|
|
39
|
-
#
|
|
40
|
-
# ## Exit codes
|
|
41
|
-
#
|
|
42
|
-
# 0 every workflow observed on the branch concluded, none failed
|
|
43
|
-
# 1 something failed — the workflow names and the first bad commit are printed
|
|
44
|
-
# 2 cannot determine: no runs found, or the repo/branch is unreadable
|
|
45
|
-
#
|
|
46
|
-
# 2 is deliberately not 0, matching `wait-for-checks.sh` and `ci-wiring-audit.sh`.
|
|
47
|
-
# A check that cannot see its input must say so rather than passing: this
|
|
48
|
-
# estate's most repeated defect is a zero that means "could not look", and
|
|
49
|
-
# `protection-audit.sh` was reporting `27 branches, all protected` while silently
|
|
50
|
-
# dropping the four repos least likely to be protected (#1145).
|
|
51
|
-
#
|
|
52
|
-
# `cancelled` is reported but does not fail the branch. On self-hosted runners it
|
|
53
|
-
# is usually spot reclamation or a `cancel-in-progress` concurrency group — two
|
|
54
|
-
# merges landing seconds apart cancel the first run by design. It is called out
|
|
55
|
-
# by name so nobody debugs a phantom.
|
|
56
|
-
#
|
|
57
|
-
# ## Usage
|
|
58
|
-
#
|
|
59
|
-
# sh scripts/branch-health.sh [-R owner/repo] [--branch dev] [--quiet]
|
|
60
|
-
#
|
|
61
|
-
# Requires `gh`, authenticated. Uses gh's embedded jq, so no jq binary is needed.
|
|
62
|
-
|
|
63
|
-
set -uo pipefail
|
|
64
|
-
|
|
65
|
-
REPO=""
|
|
66
|
-
BRANCH=""
|
|
67
|
-
QUIET=""
|
|
68
|
-
|
|
69
|
-
usage() {
|
|
70
|
-
sed -n '2,60p' "$0" | sed 's/^# \{0,1\}//'
|
|
71
|
-
exit 2
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
while [ $# -gt 0 ]; do
|
|
75
|
-
case "$1" in
|
|
76
|
-
-R | --repo)
|
|
77
|
-
REPO="${2:-}"
|
|
78
|
-
shift 2
|
|
79
|
-
;;
|
|
80
|
-
--branch)
|
|
81
|
-
BRANCH="${2:-}"
|
|
82
|
-
shift 2
|
|
83
|
-
;;
|
|
84
|
-
--quiet)
|
|
85
|
-
QUIET=1
|
|
86
|
-
shift
|
|
87
|
-
;;
|
|
88
|
-
-h | --help) usage ;;
|
|
89
|
-
*)
|
|
90
|
-
echo "branch-health: unexpected argument '$1'" >&2
|
|
91
|
-
usage
|
|
92
|
-
;;
|
|
93
|
-
esac
|
|
94
|
-
done
|
|
95
|
-
|
|
96
|
-
RED=$(printf '\033[31m')
|
|
97
|
-
GREEN=$(printf '\033[32m')
|
|
98
|
-
YELLOW=$(printf '\033[33m')
|
|
99
|
-
DIM=$(printf '\033[90m')
|
|
100
|
-
OFF=$(printf '\033[0m')
|
|
101
|
-
|
|
102
|
-
# A real tab, built the same way the colours above are, and used as `IFS="$TAB"`.
|
|
103
|
-
#
|
|
104
|
-
# AGENTS.md invokes these scripts as `sh scripts/...`, and /bin/sh is dash here.
|
|
105
|
-
# The bash spelling `IFS=$'\t'` is NOT a syntax error under dash — it is read as
|
|
106
|
-
# the four literal characters `$ ' \ t`, so the field split then happens on any
|
|
107
|
-
# of them. The first draft of this script did exactly that and reported a
|
|
108
|
-
# workflow called "Deploy Applica", having split "Deploy Application" at its
|
|
109
|
-
# 't'. It printed one row instead of four and still exited 0.
|
|
110
|
-
#
|
|
111
|
-
# Same reason the colours use `$(printf '\033[31m')` rather than `$'\e[31m'`.
|
|
112
|
-
TAB=$(printf '\t')
|
|
113
|
-
|
|
114
|
-
gh_run() {
|
|
115
|
-
if [ -n "$REPO" ]; then gh run "$@" --repo "$REPO"; else gh run "$@"; fi
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
# The integration branch is `dev` in every Biffo repo (AGENTS.md §2). Resolved
|
|
119
|
-
# from the repo rather than hardcoded so this still works in the rare repo whose
|
|
120
|
-
# default has not been migrated — and so the failure is "cannot read repo"
|
|
121
|
-
# rather than a confident answer about a branch that does not exist.
|
|
122
|
-
if [ -z "$BRANCH" ]; then
|
|
123
|
-
if [ -n "$REPO" ]; then
|
|
124
|
-
BRANCH=$(gh repo view "$REPO" --json defaultBranchRef --jq .defaultBranchRef.name 2>/dev/null)
|
|
125
|
-
else
|
|
126
|
-
BRANCH=$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name 2>/dev/null)
|
|
127
|
-
fi
|
|
128
|
-
fi
|
|
129
|
-
|
|
130
|
-
if [ -z "$BRANCH" ]; then
|
|
131
|
-
echo "${RED}branch-health: cannot determine the integration branch.${OFF}" >&2
|
|
132
|
-
exit 2
|
|
133
|
-
fi
|
|
134
|
-
|
|
135
|
-
label=${REPO:-$(basename "$(git rev-parse --show-toplevel 2>/dev/null || pwd)")}
|
|
136
|
-
|
|
137
|
-
# --- Every workflow that ran on the branch, not the first three --------------
|
|
138
|
-
#
|
|
139
|
-
# 200 runs is deep enough to reach every workflow's latest run even when a busy
|
|
140
|
-
# one (CI) dominates the head of the list. `--json` on `gh run list` returns them
|
|
141
|
-
# newest-first, so the first row per workflow name IS its latest run.
|
|
142
|
-
|
|
143
|
-
# `group_by | max_by(.createdAt)` rather than "first occurrence in a newest-first
|
|
144
|
-
# list": the ordering is gh's to change, and a status tool that quietly reports
|
|
145
|
-
# an older run because an API changed its sort is the same class of defect as the
|
|
146
|
-
# truncated list this replaces. Ask for the newest explicitly.
|
|
147
|
-
summary=$(gh_run list --branch "$BRANCH" --limit 200 \
|
|
148
|
-
--json workflowName,status,conclusion,headSha,createdAt,url \
|
|
149
|
-
--jq 'group_by(.workflowName)
|
|
150
|
-
| map(max_by(.createdAt))
|
|
151
|
-
| .[]
|
|
152
|
-
| [ (if .status == "completed" then (.conclusion // "unknown") else .status end),
|
|
153
|
-
.workflowName, .headSha[0:8], .createdAt[0:16], .url ]
|
|
154
|
-
| @tsv' 2>/dev/null)
|
|
155
|
-
|
|
156
|
-
if [ -z "$summary" ]; then
|
|
157
|
-
echo "${RED}branch-health: no workflow runs readable on '$BRANCH' in $label.${OFF}" >&2
|
|
158
|
-
echo "${DIM} That is 'cannot tell', not 'healthy' — exiting 2.${OFF}" >&2
|
|
159
|
-
exit 2
|
|
160
|
-
fi
|
|
161
|
-
|
|
162
|
-
failed=""
|
|
163
|
-
pending=""
|
|
164
|
-
cancelled=""
|
|
165
|
-
skipped=""
|
|
166
|
-
ok=""
|
|
167
|
-
|
|
168
|
-
while IFS="$TAB" read -r state name sha when url; do
|
|
169
|
-
[ -n "$name" ] || continue
|
|
170
|
-
case "$state" in
|
|
171
|
-
success) ok="${ok}${name}\n" ;;
|
|
172
|
-
failure | timed_out | startup_failure)
|
|
173
|
-
failed="${failed}${state}\t${name}\t${sha}\t${when}\t${url}\n"
|
|
174
|
-
;;
|
|
175
|
-
cancelled) cancelled="${cancelled}${name}\n" ;;
|
|
176
|
-
skipped) skipped="${skipped}${name}\n" ;;
|
|
177
|
-
*) pending="${pending}${state}\t${name}\n" ;;
|
|
178
|
-
esac
|
|
179
|
-
done <<EOF
|
|
180
|
-
$summary
|
|
181
|
-
EOF
|
|
182
|
-
|
|
183
|
-
# --- Report -------------------------------------------------------------------
|
|
184
|
-
|
|
185
|
-
echo "${DIM}$label — branch '$BRANCH', latest run per workflow${OFF}"
|
|
186
|
-
echo
|
|
187
|
-
|
|
188
|
-
# `printf '%b'` FIRST, then sed. These lists are accumulated as strings holding
|
|
189
|
-
# literal `\n` two-character sequences (POSIX sh has no clean way to append a
|
|
190
|
-
# real newline to a variable), so piping them straight to sed hands it a single
|
|
191
|
-
# line and only the first entry gets its prefix — which read as a workflow with
|
|
192
|
-
# no status at all. Expand the escapes, then prefix each real line.
|
|
193
|
-
[ -n "$ok" ] && printf '%b' "$ok" | sed "s/^/ ${GREEN}ok${OFF} /"
|
|
194
|
-
[ -n "$skipped" ] && printf '%b' "$skipped" | sed "s/^/ ${DIM}skipped${OFF} /"
|
|
195
|
-
[ -n "$cancelled" ] && printf '%b' "$cancelled" | sed "s/^/ ${YELLOW}cancelled${OFF} /"
|
|
196
|
-
|
|
197
|
-
if [ -n "$pending" ]; then
|
|
198
|
-
printf '%b' "$pending" | awk -F'\t' -v d="$YELLOW" -v o="$OFF" 'NF{printf " %srunning%s %s (%s)\n", d, o, $2, $1}'
|
|
199
|
-
fi
|
|
200
|
-
|
|
201
|
-
if [ -z "$failed" ]; then
|
|
202
|
-
if [ -n "$cancelled" ]; then
|
|
203
|
-
echo
|
|
204
|
-
echo "${DIM}A cancelled run is usually spot reclamation or a superseded concurrency${OFF}"
|
|
205
|
-
echo "${DIM}group, not the code. Re-run it rather than debugging it.${OFF}"
|
|
206
|
-
fi
|
|
207
|
-
echo
|
|
208
|
-
echo "${GREEN}Nothing on '$BRANCH' is failing.${OFF}"
|
|
209
|
-
exit 0
|
|
210
|
-
fi
|
|
211
|
-
|
|
212
|
-
echo
|
|
213
|
-
printf '%b' "$failed" | awk -F'\t' -v r="$RED" -v o="$OFF" 'NF{printf " %s%s%s %s at %s %s\n", r, $1, o, $2, $3, $5}'
|
|
214
|
-
|
|
215
|
-
# --- Who actually broke it ----------------------------------------------------
|
|
216
|
-
#
|
|
217
|
-
# The whole point of #1133's third defect. Walk this workflow's runs on this
|
|
218
|
-
# branch backwards from the newest failure through consecutive failures, and
|
|
219
|
-
# report the OLDEST one in that unbroken streak. That run's commit is where the
|
|
220
|
-
# breakage started, which is very often not the person now reading this.
|
|
221
|
-
|
|
222
|
-
echo
|
|
223
|
-
printf '%b' "$failed" | while IFS="$TAB" read -r state name sha when url; do
|
|
224
|
-
[ -n "$name" ] || continue
|
|
225
|
-
|
|
226
|
-
# Sort newest-first ourselves, cut the list at the most recent SUCCESS, and
|
|
227
|
-
# take the oldest failure still inside that streak. Anything before a green run
|
|
228
|
-
# is a different, already-fixed breakage and must not be blamed for this one.
|
|
229
|
-
first=$(gh_run list --branch "$BRANCH" --workflow "$name" --limit 60 \
|
|
230
|
-
--json conclusion,headSha,createdAt,displayTitle,url \
|
|
231
|
-
--jq 'sort_by(.createdAt) | reverse
|
|
232
|
-
| (map(.conclusion == "success") | index(true)) as $green
|
|
233
|
-
| .[0: (if $green == null then length else $green end)]
|
|
234
|
-
| map(select(.conclusion == "failure"
|
|
235
|
-
or .conclusion == "timed_out"
|
|
236
|
-
or .conclusion == "startup_failure"))
|
|
237
|
-
| last
|
|
238
|
-
| select(. != null)
|
|
239
|
-
| [ .headSha[0:8], .createdAt[0:16], (.displayTitle // "")[0:72], .url ]
|
|
240
|
-
| @tsv' 2>/dev/null)
|
|
241
|
-
|
|
242
|
-
if [ -n "$first" ]; then
|
|
243
|
-
f_sha=$(printf '%s' "$first" | cut -f1)
|
|
244
|
-
f_when=$(printf '%s' "$first" | cut -f2)
|
|
245
|
-
f_title=$(printf '%s' "$first" | cut -f3)
|
|
246
|
-
f_url=$(printf '%s' "$first" | cut -f4)
|
|
247
|
-
echo " ${RED}$name${OFF} has been failing since ${YELLOW}$f_sha${OFF} ($f_when)"
|
|
248
|
-
echo " $f_title"
|
|
249
|
-
echo " ${DIM}$f_url${OFF}"
|
|
250
|
-
if [ "$f_sha" != "$sha" ]; then
|
|
251
|
-
echo " ${DIM}The newest failure is at $sha — but it is NOT where this started.${OFF}"
|
|
252
|
-
echo " ${DIM}Diagnose $f_sha, not your own merge.${OFF}"
|
|
253
|
-
fi
|
|
254
|
-
else
|
|
255
|
-
echo " ${RED}$name${OFF} is failing at $sha ${DIM}(could not establish when it started)${OFF}"
|
|
256
|
-
fi
|
|
257
|
-
done
|
|
258
|
-
|
|
259
|
-
# --- Tell somebody ------------------------------------------------------------
|
|
260
|
-
#
|
|
261
|
-
# Copied in posture, deliberately, from practices-daily.sh's `_notify`: opt-OUT
|
|
262
|
-
# via an env var rather than opt-in, because an opt-in alert is one that never
|
|
263
|
-
# fires. Replaces its own previous card rather than stacking, so a branch red for
|
|
264
|
-
# three days is one notification and not three.
|
|
265
|
-
|
|
266
|
-
_notify() {
|
|
267
|
-
[ -z "$QUIET" ] || return 0
|
|
268
|
-
command -v notify-send >/dev/null 2>&1 || return 0
|
|
269
|
-
[ -z "${BRANCH_HEALTH_NO_DESKTOP_ALERT:-}" ] || return 0
|
|
270
|
-
|
|
271
|
-
if [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ]; then
|
|
272
|
-
_bus="/run/user/$(id -u)/bus"
|
|
273
|
-
[ -S "$_bus" ] || return 0
|
|
274
|
-
DBUS_SESSION_BUS_ADDRESS="unix:path=$_bus"
|
|
275
|
-
export DBUS_SESSION_BUS_ADDRESS
|
|
276
|
-
fi
|
|
277
|
-
|
|
278
|
-
_slug=$(printf '%s' "$label-$BRANCH" | tr -c 'a-zA-Z0-9' '-')
|
|
279
|
-
_idfile="${XDG_RUNTIME_DIR:-/tmp}/biffo-branch-health-${_slug}.id"
|
|
280
|
-
_prev=""
|
|
281
|
-
[ -f "$_idfile" ] && _prev=$(cat "$_idfile" 2>/dev/null)
|
|
282
|
-
|
|
283
|
-
# Built as a plain variable rather than `${_prev:+--replace-id="$_prev"}`.
|
|
284
|
-
# That form nests double quotes inside a parameter expansion, which dash
|
|
285
|
-
# refuses to parse — and because the script is run as `sh`, the failure lands
|
|
286
|
-
# at RUNTIME, after all the useful output has already printed, turning a
|
|
287
|
-
# correct exit 1 into a confusing exit 2.
|
|
288
|
-
_replace=""
|
|
289
|
-
[ -n "$_prev" ] && _replace="--replace-id=$_prev"
|
|
290
|
-
|
|
291
|
-
_names=$(printf '%b' "$failed" | awk -F'\t' 'NF{printf "%s ", $2}')
|
|
292
|
-
# Deliberately unquoted: empty must expand to no argument at all.
|
|
293
|
-
# shellcheck disable=SC2086
|
|
294
|
-
_new=$(notify-send --print-id $_replace \
|
|
295
|
-
-u critical -a "biffo" \
|
|
296
|
-
"$label: $BRANCH is red" \
|
|
297
|
-
"$_names— nobody is watching a post-merge failure. sh scripts/branch-health.sh" 2>/dev/null)
|
|
298
|
-
[ -n "$_new" ] && printf '%s' "$_new" > "$_idfile" 2>/dev/null
|
|
299
|
-
return 0
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
_notify
|
|
303
|
-
|
|
304
|
-
echo
|
|
305
|
-
echo "${RED}'$BRANCH' is red. It blocks everyone — fixing it is the next task (AGENTS.md §6).${OFF}"
|
|
306
|
-
exit 1
|