Skip to content

Commit baf01e7

Browse files
fix(ci): adopt canonical hypatia-scan.yml (env.HOME/scanner-layout + Comment-step gate) (#2)
1 parent 5c1b9f7 commit baf01e7

1 file changed

Lines changed: 74 additions & 10 deletions

File tree

.github/workflows/hypatia-scan.yml

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ on:
1010
schedule:
1111
- cron: '0 0 * * 0' # Weekly on Sunday
1212
workflow_dispatch:
13+
# Estate guardrail: cancel superseded runs so re-pushes don't pile up
14+
# queued runs across the estate. Safe here because this workflow only
15+
# performs read-only checks/lint/test/scan with no publish or mutation.
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: true
1319

1420
permissions:
1521
contents: read
@@ -19,6 +25,11 @@ permissions:
1925
# the rule silently returns no findings.
2026
# See 007-lang/audits/audit-dependabot-automation-gap-2026-04-17.md.
2127
security-events: read
28+
# pull-requests: write lets the advisory "Comment on PR with findings"
29+
# step post its summary. Without it the built-in GITHUB_TOKEN gets
30+
# "Resource not accessible by integration" and (absent continue-on-error)
31+
# hard-fails the scan — exactly what the gate-decoupling design forbids.
32+
pull-requests: write
2233

2334
jobs:
2435
scan:
@@ -32,7 +43,7 @@ jobs:
3243
fetch-depth: 0 # Full history for better pattern analysis
3344

3445
- name: Setup Elixir for Hypatia scanner
35-
uses: erlef/setup-beam@e6d7c94229049569db56a7ad5a540c051a010af9 # v1.18.2
46+
uses: erlef/setup-beam@fc68ffb90438ef2936bbb3251622353b3dcb2f93 # v1.18.2
3647
with:
3748
elixir-version: '1.19.4'
3849
otp-version: '28.3'
@@ -64,7 +75,7 @@ jobs:
6475
echo "Scanning repository: ${{ github.repository }}"
6576
6677
# Run scanner (exits non-zero when findings exist — suppress to continue)
67-
HYPATIA_FORMAT=json "$HOME/hypatia/hypatia-cli.sh" scan . > hypatia-findings.json || true
78+
HYPATIA_FORMAT=json "$HOME/hypatia/hypatia-cli.sh" scan . --exit-zero > hypatia-findings.json || true
6879
6980
# Count findings
7081
FINDING_COUNT=$(jq '. | length' hypatia-findings.json 2>/dev/null || echo 0)
@@ -86,33 +97,81 @@ jobs:
8697
echo "- Medium: $MEDIUM" >> $GITHUB_STEP_SUMMARY
8798
8899
- name: Upload findings artifact
89-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
100+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
90101
with:
91102
name: hypatia-findings
92103
path: hypatia-findings.json
93104
retention-days: 90
94105

95106
- name: Submit findings to gitbot-fleet (Phase 2)
96107
if: steps.scan.outputs.findings_count > 0
108+
# Phase 2 is the collaborative LEARNING side-channel ("bots share
109+
# findings via gitbot-fleet"), not the security gate. The gate is
110+
# the baseline-aware "Check for critical or high-severity issues"
111+
# step below. A fleet-side regression (e.g. the submit script being
112+
# moved/removed) must NEVER hard-fail every consuming repo's scan.
113+
# Same reasoning as the "Comment on PR with findings" step.
114+
# See hyperpolymath/hypatia#213 (gate decoupling) and the exit-127
115+
# estate-wide breakage when gitbot-fleet/scripts/submit-finding.sh
116+
# no longer existed on the default branch.
117+
continue-on-error: true
97118
env:
119+
# All GitHub context values surface as env vars so the run
120+
# block never interpolates `${{ … }}` inline (closes the
121+
# workflow_audit/unsafe_curl_payload + actions_expression_injection
122+
# findings).
98123
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124+
FLEET_PUSH_TOKEN: ${{ secrets.HYPATIA_DISPATCH_PAT }}
125+
FLEET_DISPATCH_TOKEN: ${{ secrets.HYPATIA_DISPATCH_PAT }}
99126
GITHUB_REPOSITORY: ${{ github.repository }}
100127
GITHUB_SHA: ${{ github.sha }}
128+
FINDINGS_COUNT: ${{ steps.scan.outputs.findings_count }}
101129
run: |
102-
echo "📤 Submitting ${{ steps.scan.outputs.findings_count }} findings to gitbot-fleet..."
130+
echo "📤 Submitting $FINDINGS_COUNT findings to gitbot-fleet..."
103131
104-
# Clone gitbot-fleet to temp directory
132+
# Clone gitbot-fleet to temp directory. A clone failure (network,
133+
# repo gone) is non-fatal: learning submission is best-effort.
105134
FLEET_DIR="/tmp/gitbot-fleet-$$"
106-
git clone https://github.com/hyperpolymath/gitbot-fleet.git "$FLEET_DIR"
135+
if ! git clone --depth 1 https://github.com/hyperpolymath/gitbot-fleet.git "$FLEET_DIR"; then
136+
echo "::warning::Could not clone gitbot-fleet — skipping Phase 2 learning submission (non-fatal)."
137+
exit 0
138+
fi
107139
108-
# Run submission script
109-
bash "$FLEET_DIR/scripts/submit-finding.sh" hypatia-findings.json
140+
# The submission script's location in gitbot-fleet has drifted
141+
# before (it was absent from the default branch, which exit-127'd
142+
# every consuming repo's scan). Probe known locations rather than
143+
# hard-coding one path, and skip gracefully if none is present.
144+
SUBMIT_SCRIPT=""
145+
for cand in \
146+
"$FLEET_DIR/scripts/submit-finding.sh" \
147+
"$FLEET_DIR/scripts/submit_finding.sh" \
148+
"$FLEET_DIR/bin/submit-finding.sh" \
149+
"$FLEET_DIR/submit-finding.sh"; do
150+
if [ -f "$cand" ]; then
151+
SUBMIT_SCRIPT="$cand"
152+
break
153+
fi
154+
done
155+
156+
if [ -z "$SUBMIT_SCRIPT" ]; then
157+
echo "::warning::gitbot-fleet submit-finding script not found at any known path — skipping Phase 2 learning submission (non-fatal). Findings are still uploaded as an artifact and gated below."
158+
rm -rf "$FLEET_DIR"
159+
exit 0
160+
fi
161+
162+
# Run submission script. Pass the findings path as ABSOLUTE —
163+
# the script cd's into its own working dir before reading the
164+
# file, so a relative path would resolve to the wrong place.
165+
# A submission-script failure is logged but non-fatal.
166+
if bash "$SUBMIT_SCRIPT" "$GITHUB_WORKSPACE/hypatia-findings.json"; then
167+
echo "✅ Finding submission complete"
168+
else
169+
echo "::warning::gitbot-fleet submission script exited non-zero — Phase 2 learning submission skipped (non-fatal)."
170+
fi
110171
111172
# Cleanup
112173
rm -rf "$FLEET_DIR"
113174
114-
echo "✅ Finding submission complete"
115-
116175
- name: Check for critical issues
117176
if: steps.scan.outputs.critical > 0
118177
run: |
@@ -157,6 +216,11 @@ jobs:
157216
158217
- name: Comment on PR with findings
159218
if: github.event_name == 'pull_request' && steps.scan.outputs.findings_count > 0
219+
# Advisory only — posting findings as a PR comment must never gate
220+
# the scan (hypatia#213 gate decoupling). Belt-and-braces alongside
221+
# the pull-requests: write permission above: a token/API hiccup or
222+
# a fork PR (read-only token) skips the comment, not the check.
223+
continue-on-error: true
160224
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7
161225
with:
162226
script: |

0 commit comments

Comments
 (0)