From 10d704b557c36c843de0faba30767bf23bb4f259 Mon Sep 17 00:00:00 2001 From: Brandon McAnsh Date: Fri, 2 Oct 2026 14:34:41 -0400 Subject: [PATCH] fix(triage): count builds from origin/code/cash and load .env.local for the event fetch build-lookup.sh counted commits from the local HEAD, so on a checkout behind origin it rejected a real build (4718 against a local count of 4700). It now fetches and counts from origin/code/cash, the branch builds are cut from, with --ref to override, and checks that the resolved commit has exactly N ancestors. The triage skill's manual event fetch told the agent to source only .env, while bugsnag-top.sh also reads .env.local, where the token lives. --- .claude/skills/build-lookup/SKILL.md | 4 ++ .../build-lookup/scripts/build-lookup.sh | 37 +++++++++++++++---- .claude/skills/triage/SKILL.md | 8 +++- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/.claude/skills/build-lookup/SKILL.md b/.claude/skills/build-lookup/SKILL.md index 9cd82ba24c..0e1385e011 100644 --- a/.claude/skills/build-lookup/SKILL.md +++ b/.claude/skills/build-lookup/SKILL.md @@ -32,6 +32,10 @@ Run the helper script: bash .claude/skills/build-lookup/scripts/build-lookup.sh ``` +The script fetches and counts from `origin/code/cash`, the branch builds are cut +from, so a stale or detached local checkout does not matter. Pass `--ref ` +to count from another ref. + The script emits JSON: ```json diff --git a/.claude/skills/build-lookup/scripts/build-lookup.sh b/.claude/skills/build-lookup/scripts/build-lookup.sh index 6d761f7575..090354cb12 100755 --- a/.claude/skills/build-lookup/scripts/build-lookup.sh +++ b/.claude/skills/build-lookup/scripts/build-lookup.sh @@ -5,9 +5,14 @@ # apps/flipcash/app/build.gradle.kts:20-25). versionCode N = the Nth commit # from the root of the repo. # +# Builds are cut from code/cash, so commits are counted from origin/code/cash +# (fetched first), not from the local HEAD, which may be behind or on another +# branch. +# # Usage: # ./build-lookup.sh # ./build-lookup.sh 3797 +# ./build-lookup.sh 3797 --ref # count from another ref # # Output: JSON with commit_sha, commit_short, commit_message, and (if found) # the GitHub Actions run ID and URL for the Flipcash2 workflow. @@ -15,22 +20,34 @@ set -euo pipefail if [[ $# -lt 1 ]]; then - echo "Usage: build-lookup.sh " >&2 + echo "Usage: build-lookup.sh [--ref ]" >&2 exit 1 fi -VERSION_CODE="$1" +VERSION_CODE="$1"; shift +REF="origin/code/cash" +while [[ $# -gt 0 ]]; do + case "$1" in + --ref) REF="$2"; shift 2 ;; + *) echo "Unknown argument: $1" >&2; exit 1 ;; + esac +done + +if [[ "$REF" == "origin/code/cash" ]]; then + git fetch --quiet origin code/cash 2>/dev/null \ + || echo "WARN: could not fetch origin/code/cash; using the local copy" >&2 +fi WORKFLOW_ID="229420296" # "Flipcash2 Build and Deploy" # ── Resolve versionCode to commit ─────────────────────────────────── # versionCode = git rev-list --count HEAD at the time of build. -# The Nth commit (1-indexed from root) is at position N in `git rev-list --reverse HEAD`. -# Equivalently: git rev-list HEAD | sed -n 'p' where offset = total - N + 1. +# The Nth commit (1-indexed from root) is at position N in `git rev-list --reverse $REF`. +# Equivalently: git rev-list $REF | sed -n 'p' where offset = total - N + 1. -TOTAL=$(git rev-list --count HEAD) +TOTAL=$(git rev-list --count "$REF") if (( VERSION_CODE > TOTAL )); then - echo "ERROR: versionCode $VERSION_CODE exceeds current commit count ($TOTAL)" >&2 + echo "ERROR: versionCode $VERSION_CODE exceeds the commit count of $REF ($TOTAL)" >&2 exit 1 fi @@ -40,7 +57,13 @@ if (( VERSION_CODE < 1 )); then fi OFFSET=$(( TOTAL - VERSION_CODE + 1 )) -COMMIT_SHA=$(git rev-list HEAD | sed -n "${OFFSET}p") +COMMIT_SHA=$(git rev-list "$REF" | sed -n "${OFFSET}p") + +# The offset assumes linear history. Confirm the commit really is the Nth. +if [[ "$(git rev-list --count "$COMMIT_SHA")" != "$VERSION_CODE" ]]; then + echo "ERROR: commit ${COMMIT_SHA:0:9} on $REF has $(git rev-list --count "$COMMIT_SHA") ancestors, not $VERSION_CODE (non-linear history?)" >&2 + exit 1 +fi COMMIT_SHORT="${COMMIT_SHA:0:9}" COMMIT_MESSAGE=$(git log -1 --format='%s' "$COMMIT_SHA") COMMIT_DATE=$(git log -1 --format='%aI' "$COMMIT_SHA") diff --git a/.claude/skills/triage/SKILL.md b/.claude/skills/triage/SKILL.md index 33fc2803bd..19c86af201 100644 --- a/.claude/skills/triage/SKILL.md +++ b/.claude/skills/triage/SKILL.md @@ -64,7 +64,13 @@ If the script exits non-zero, stop and report the error to the user. ## Step 2 — Pull event detail Fetch `event_url` (include header `Authorization: token $BUGSNAG_TOKEN`). -Source `.env` from the repo root if the variable is not already set. +The token lives in `.env` or `.env.local` at the repo root, as the script reads +it; load both in the same shell as the request: + +```bash +set -a; [ -f .env ] && . ./.env; [ -f .env.local ] && . ./.env.local; set +a +curl -s -H "Authorization: token $BUGSNAG_TOKEN" "" +``` Parse the response using the event shape documented in `.claude/skills/triage/references/event-shape.md`.