Skip to content

Commit 9e28bfe

Browse files
committed
ci: adopt standards reusable workflows for Scorecard, Hypatia, and Governance
1 parent 279bb44 commit 9e28bfe

4 files changed

Lines changed: 26 additions & 430 deletions

File tree

.github/workflows/governance.yml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,16 @@
1-
# // Copyright (c) Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
2-
# SPDX-License-Identifier: MPL-2.0
3-
# governance.yml — single wrapper calling the shared estate governance bundle
4-
# in hyperpolymath/standards instead of carrying per-repo copies.
5-
#
6-
# Replaces the per-repo governance scaffolding removed in the same commit:
7-
# quality.yml, guix-nix-policy.yml, npm-bun-blocker.yml, ts-blocker.yml,
8-
# security-policy.yml, rsr-antipattern.yml, wellknown-enforcement.yml,
9-
# workflow-linter.yml
10-
#
11-
# Load-bearing build/security workflows stay standalone in the repo
12-
# (rust-ci, codeql, dependabot, release, scan/mirror/pages plumbing).
13-
1+
# SPDX-License-Identifier: PMPL-1.0-or-later
142
name: Governance
3+
154
on:
165
push:
176
branches: [main, master]
187
pull_request:
8+
branches: [main, master]
199
workflow_dispatch:
20-
# Estate guardrail: cancel superseded runs so re-pushes / rebased PR
21-
# updates do not pile up queued runs against the shared account-wide
22-
# Actions concurrency pool. Applied only to read-only check workflows
23-
# (no publish/mutation), so cancelling a superseded run is always safe.
24-
concurrency:
25-
group: ${{ github.workflow }}-${{ github.ref }}
26-
cancel-in-progress: true
10+
2711
permissions:
2812
contents: read
13+
2914
jobs:
3015
governance:
31-
uses: hyperpolymath/standards/.github/workflows/governance-reusable.yml@861b5e911d9e5dcfb3c0ab3dd2a9a3c8fd0a1613
32-
timeout-minutes: 10
16+
uses: hyperpolymath/standards/.github/workflows/governance-reusable.yml@5a93d9d57cc04de4002d6d0ecd336fc7a8698910

.github/workflows/hypatia-scan.yml

Lines changed: 7 additions & 321 deletions
Original file line numberDiff line numberDiff line change
@@ -1,333 +1,19 @@
1-
# // Copyright (c) Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
2-
# SPDX-License-Identifier: MPL-2.0
3-
# Hypatia Neurosymbolic CI/CD Security Scan
1+
# SPDX-License-Identifier: PMPL-1.0-or-later
42
name: Hypatia Security Scan
3+
54
on:
65
push:
76
branches: [main, master, develop]
87
pull_request:
98
branches: [main, master]
109
schedule:
11-
- cron: '0 0 * * 0' # Weekly on Sunday
10+
- cron: '0 0 * * 0'
1211
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
12+
1913
permissions:
2014
contents: read
21-
# security-events: write serves two purposes (write implies read):
22-
# 1. read — lets the built-in GITHUB_TOKEN query this repo's own
23-
# Dependabot alerts via the Hypatia DependabotAlerts rule
24-
# (DA001-DA004). Without read, `scan_from_path` gets HTTP 403
25-
# and the rule silently returns no findings.
26-
# See 007-lang/audits/audit-dependabot-automation-gap-2026-04-17.md.
27-
# 2. write — lets the "Upload SARIF to code scanning" step publish
28-
# Hypatia findings to the Security → Code scanning page so they
29-
# are triaged/deduplicated like CodeQL alerts instead of living
30-
# only in a build artifact nobody is required to look at.
31-
# See hyperpolymath/burble#35 (SARIF integration).
32-
# This is a single-job workflow, so job-level scoping would not
33-
# narrow the grant further; it stays workflow-level and documented.
34-
security-events: write
35-
# pull-requests: write lets the advisory "Comment on PR with findings"
36-
# step post its summary. Without it the built-in GITHUB_TOKEN gets
37-
# "Resource not accessible by integration" and (absent continue-on-error)
38-
# hard-fails the scan — exactly what the gate-decoupling design forbids.
39-
pull-requests: write
15+
security-events: read
16+
4017
jobs:
4118
scan:
42-
name: Hypatia Neurosymbolic Analysis
43-
runs-on: ubuntu-latest
44-
timeout-minutes: 15
45-
steps:
46-
- name: Checkout repository
47-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
48-
with:
49-
fetch-depth: 0 # Full history for better pattern analysis
50-
- name: Setup Elixir for Hypatia scanner
51-
uses: erlef/setup-beam@fc68ffb90438ef2936bbb3251622353b3dcb2f93 # v1.18.2
52-
with:
53-
elixir-version: '1.18'
54-
otp-version: '27'
55-
- name: Clone Hypatia
56-
run: |
57-
if [ ! -d "$HOME/hypatia" ]; then
58-
git clone https://github.com/hyperpolymath/hypatia.git "$HOME/hypatia"
59-
fi
60-
- name: Build Hypatia scanner (if needed)
61-
run: |
62-
cd "$HOME/hypatia"
63-
if [ ! -f hypatia ]; then
64-
echo "Building hypatia scanner..."
65-
mix deps.get
66-
mix escript.build
67-
fi
68-
- name: Run Hypatia scan
69-
id: scan
70-
env:
71-
# Pass the built-in Actions token through to Hypatia so the
72-
# DependabotAlerts rule can query this repo's own alerts.
73-
# For cross-repo scanning (fleet-coordinator scan-supervised),
74-
# a PAT with `security_events` scope is required instead.
75-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76-
run: |
77-
echo "Scanning repository: ${{ github.repository }}"
78-
79-
# Run scanner (exits non-zero when findings exist — suppress to continue)
80-
HYPATIA_FORMAT=json "$HOME/hypatia/hypatia-cli.sh" scan . --exit-zero > hypatia-findings.json || true
81-
82-
# Count findings
83-
FINDING_COUNT=$(jq '. | length' hypatia-findings.json 2>/dev/null || echo 0)
84-
echo "findings_count=$FINDING_COUNT" >> $GITHUB_OUTPUT
85-
86-
# Extract severity counts
87-
CRITICAL=$(jq '[.[] | select(.severity == "critical")] | length' hypatia-findings.json)
88-
HIGH=$(jq '[.[] | select(.severity == "high")] | length' hypatia-findings.json)
89-
MEDIUM=$(jq '[.[] | select(.severity == "medium")] | length' hypatia-findings.json)
90-
91-
echo "critical=$CRITICAL" >> $GITHUB_OUTPUT
92-
echo "high=$HIGH" >> $GITHUB_OUTPUT
93-
echo "medium=$MEDIUM" >> $GITHUB_OUTPUT
94-
95-
echo "## Hypatia Scan Results" >> $GITHUB_STEP_SUMMARY
96-
echo "- Total findings: $FINDING_COUNT" >> $GITHUB_STEP_SUMMARY
97-
echo "- Critical: $CRITICAL" >> $GITHUB_STEP_SUMMARY
98-
echo "- High: $HIGH" >> $GITHUB_STEP_SUMMARY
99-
echo "- Medium: $MEDIUM" >> $GITHUB_STEP_SUMMARY
100-
- name: Upload findings artifact
101-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
102-
with:
103-
name: hypatia-findings
104-
path: hypatia-findings.json
105-
retention-days: 90
106-
- name: Convert Hypatia findings to SARIF
107-
# Always runs (no findings_count guard): an EMPTY SARIF run is
108-
# valid and intentional — uploading it clears stale Hypatia
109-
# alerts from the code-scanning page when a repo goes clean.
110-
# The converter is dependency-free Node (Node ships on
111-
# ubuntu-latest; no npm install — estate npm ban respected) and
112-
# is hardened against the heterogeneous Hypatia JSON schema:
113-
# most findings are {rule_module,severity,type,file,reason,
114-
# action}; only some carry an integer `line`; `file` may be
115-
# empty or absolute. See lib/hypatia/cli.ex (collect_findings).
116-
run: |
117-
cat > "$RUNNER_TEMP/hypatia-sarif.cjs" <<'CJS'
118-
const fs = require('fs');
119-
const path = require('path');
120-
const crypto = require('crypto');
121-
122-
const ws = process.env.GITHUB_WORKSPACE || process.cwd();
123-
124-
let findings = [];
125-
try {
126-
const parsed = JSON.parse(fs.readFileSync('hypatia-findings.json', 'utf8'));
127-
if (Array.isArray(parsed)) findings = parsed;
128-
} catch (_) {
129-
// Scanner unavailable / empty / malformed -> empty SARIF.
130-
// Intentionally clears stale alerts rather than erroring.
131-
findings = [];
132-
}
133-
134-
// Mirrors Hypatia's own "github" annotation mapping
135-
// (lib/hypatia/cli.ex output/2): critical|high -> error,
136-
// medium -> warning, everything else -> note.
137-
const levelFor = (sev) => {
138-
switch (String(sev || '').toLowerCase()) {
139-
case 'critical':
140-
case 'high': return 'error';
141-
case 'medium': return 'warning';
142-
default: return 'note';
143-
}
144-
};
145-
146-
// SARIF artifactLocation.uri must be a repo-relative POSIX
147-
// path. Hypatia may emit absolute paths (scanned under
148-
// $GITHUB_WORKSPACE) or "" / "." for repo-level findings.
149-
const relUri = (file) => {
150-
if (!file) return '.';
151-
let f = String(file);
152-
if (path.isAbsolute(f)) {
153-
const rel = path.relative(ws, f);
154-
f = (rel && !rel.startsWith('..')) ? rel : path.basename(f);
155-
}
156-
f = f.replace(/\\/g, '/').replace(/^\.\//, '');
157-
return f || '.';
158-
};
159-
160-
const rules = new Map();
161-
const results = findings.map((f) => {
162-
const mod = String(f.rule_module || 'hypatia');
163-
const type = String(f.type || 'finding');
164-
const ruleId = `hypatia/${mod}/${type}`;
165-
const level = levelFor(f.severity);
166-
if (!rules.has(ruleId)) {
167-
rules.set(ruleId, {
168-
id: ruleId,
169-
name: `${mod}.${type}`,
170-
shortDescription: { text: `Hypatia ${mod}: ${type}` },
171-
defaultConfiguration: { level }
172-
});
173-
}
174-
const uri = relUri(f.file);
175-
const msg = String(f.reason || f.type || 'Hypatia finding');
176-
const startLine =
177-
Number.isInteger(f.line) && f.line > 0 ? f.line : 1;
178-
// Stable cross-run fingerprint for dedupe (no line, so a
179-
// moved finding in the same file/rule stays one alert).
180-
const fp = crypto
181-
.createHash('sha256')
182-
.update([ruleId, uri, type, msg].join('|'))
183-
.digest('hex');
184-
return {
185-
ruleId,
186-
level,
187-
message: { text: msg },
188-
locations: [
189-
{
190-
physicalLocation: {
191-
artifactLocation: { uri },
192-
region: { startLine }
193-
}
194-
}
195-
],
196-
partialFingerprints: { 'hypatiaFindingHash/v1': fp }
197-
};
198-
});
199-
200-
const sarif = {
201-
$schema: 'https://json.schemastore.org/sarif-2.1.0.json',
202-
version: '2.1.0',
203-
runs: [
204-
{
205-
tool: {
206-
driver: {
207-
name: 'Hypatia',
208-
informationUri: 'https://github.com/hyperpolymath/hypatia',
209-
rules: Array.from(rules.values())
210-
}
211-
},
212-
results
213-
}
214-
]
215-
};
216-
217-
fs.writeFileSync('hypatia.sarif', JSON.stringify(sarif, null, 2));
218-
console.log(`hypatia.sarif written: ${results.length} result(s).`);
219-
CJS
220-
node "$RUNNER_TEMP/hypatia-sarif.cjs"
221-
- name: Upload SARIF to GitHub code scanning
222-
# Fork PRs get a read-only GITHUB_TOKEN, so security-events:write
223-
# is unavailable and upload-sarif cannot publish — skip there
224-
# rather than hard-fail (the push/schedule run on the default
225-
# branch is the authoritative upload). Same-repo PRs and pushes
226-
# do upload. This step is deliberately NOT continue-on-error:
227-
# if the security-surface integration breaks we want a loud red,
228-
# not a silently-ungated scanner (the exact failure mode #35
229-
# exists to end). The empty-SARIF "clear stale alerts" path is
230-
# handled in the converter above and does not error here.
231-
if: >-
232-
always() && (github.event_name != 'pull_request' ||
233-
234-
235-
236-
237-
238-
github.event.pull_request.head.repo.fork != true)
239-
uses: github/codeql-action/upload-sarif@0d579ffd059c29b07949a3cce3983f0780820c98 # v3.28.1
240-
with:
241-
sarif_file: hypatia.sarif
242-
# Distinct category so Hypatia results coexist with CodeQL's
243-
# (codeql.yml) instead of overwriting them on the same surface.
244-
category: hypatia
245-
- name: Submit findings to gitbot-fleet (Phase 2)
246-
if: steps.scan.outputs.findings_count > 0
247-
# Phase 2 is the collaborative LEARNING side-channel ("bots share
248-
# findings via gitbot-fleet"), not the security gate. The gate is
249-
# the baseline-aware "Check for critical or high-severity issues"
250-
# step below. A fleet-side regression (e.g. the submit script being
251-
# moved/removed) must NEVER hard-fail every consuming repo's scan.
252-
# Same reasoning as the "Comment on PR with findings" step.
253-
# See hyperpolymath/hypatia#213 (gate decoupling) and the exit-127
254-
# estate-wide breakage when gitbot-fleet/scripts/submit-finding.sh
255-
# no longer existed on the default branch.
256-
continue-on-error: true
257-
env:
258-
# All GitHub context values surface as env vars so the run
259-
# block never interpolates `${{ … }}` inline (closes the
260-
# workflow_audit/unsafe_curl_payload + actions_expression_injection
261-
# findings).
262-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
263-
FLEET_PUSH_TOKEN: ${{ secrets.HYPATIA_DISPATCH_PAT }}
264-
FLEET_DISPATCH_TOKEN: ${{ secrets.HYPATIA_DISPATCH_PAT }}
265-
GITHUB_REPOSITORY: ${{ github.repository }}
266-
GITHUB_SHA: ${{ github.sha }}
267-
FINDINGS_COUNT: ${{ steps.scan.outputs.findings_count }}
268-
run: "echo \"\U0001F4E4 Submitting $FINDINGS_COUNT findings to gitbot-fleet...\"\n\n# Clone gitbot-fleet to temp directory. A clone failure (network,\n# repo gone) is non-fatal: learning submission is best-effort.\nFLEET_DIR=\"/tmp/gitbot-fleet-$$\"\nif ! git clone --depth 1 https://github.com/hyperpolymath/gitbot-fleet.git \"$FLEET_DIR\"; then\n echo \"::warning::Could not clone gitbot-fleet — skipping Phase 2 learning submission (non-fatal).\"\n exit 0\nfi\n\n# The submission script's location in gitbot-fleet has drifted\n# before (it was absent from the default branch, which exit-127'd\n# every consuming repo's scan). Probe known locations rather than\n# hard-coding one path, and skip gracefully if none is present.\nSUBMIT_SCRIPT=\"\"\nfor cand in \\\n \"$FLEET_DIR/scripts/submit-finding.sh\" \\\n \"$FLEET_DIR/scripts/submit_finding.sh\" \\\n \"$FLEET_DIR/bin/submit-finding.sh\" \\\n \"$FLEET_DIR/submit-finding.sh\"; do\n if [ -f \"$cand\" ]; then\n SUBMIT_SCRIPT=\"$cand\"\n break\n fi\ndone\n\nif [ -z \"$SUBMIT_SCRIPT\" ]; then\n 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.\"\n rm -rf \"$FLEET_DIR\"\n exit 0\nfi\n\n# Run submission script. Pass the findings path as ABSOLUTE —\n# the script cd's into its own working dir before reading the\n# file, so a relative path would resolve to the wrong place.\n# A submission-script failure is logged but non-fatal.\nif bash \"$SUBMIT_SCRIPT\" \"$GITHUB_WORKSPACE/hypatia-findings.json\"; then\n echo \"✅ Finding submission complete\"\nelse\n echo \"::warning::gitbot-fleet submission script exited non-zero — Phase 2 learning submission skipped (non-fatal).\"\nfi\n\n# Cleanup\nrm -rf \"$FLEET_DIR\"\n"
269-
- name: Check for critical issues
270-
if: steps.scan.outputs.critical > 0
271-
# GATING POLICY (explicit, by design — not an oversight):
272-
# Hypatia is ADVISORY here. Critical findings are surfaced
273-
# (step annotation + SARIF alert on the code-scanning page +
274-
# PR comment) but do NOT fail this check. Enforcement is
275-
# delegated to the code-scanning surface: tighten by adding a
276-
# branch-protection "required" status on the `hypatia` SARIF
277-
# category, not by reintroducing an `exit 1` here. This keeps
278-
# the gate decision in one auditable place (hypatia#213 gate
279-
# decoupling) and lets a repo opt into fail-on-critical without
280-
# editing this canonical workflow. To change the policy, change
281-
# branch protection — deliberately no commented-out `exit 1`.
282-
run: |
283-
echo "::warning::Hypatia found critical security issue(s) — advisory."
284-
echo "See the Security → Code scanning page (category: hypatia)"
285-
echo "and the hypatia-findings.json artifact for details."
286-
- name: Generate scan report
287-
run: |
288-
cat << EOF > hypatia-report.md
289-
# Hypatia Security Scan Report
290-
291-
**Repository:** ${{ github.repository }}
292-
**Scan Date:** $(date -u +"%Y-%m-%d %H:%M:%S UTC")
293-
**Commit:** ${{ github.sha }}
294-
295-
## Summary
296-
297-
| Severity | Count |
298-
|----------|-------|
299-
| Critical | ${{ steps.scan.outputs.critical }} |
300-
| High | ${{ steps.scan.outputs.high }} |
301-
| Medium | ${{ steps.scan.outputs.medium }} |
302-
| **Total**| ${{ steps.scan.outputs.findings_count }} |
303-
304-
## Next Steps
305-
306-
1. Triage findings on the **Security → Code scanning** page
307-
(SARIF category \`hypatia\`) — dismiss/track them there like
308-
CodeQL alerts.
309-
2. The full finding set is also attached as the
310-
\`hypatia-findings.json\` build artifact for offline review.
311-
3. Findings are **advisory** today (surfaced, not gated); the
312-
gating policy is documented in the workflow's "Check for
313-
critical issues" step.
314-
315-
## Learning
316-
317-
These findings feed Hypatia's learning engine to improve future rules.
318-
319-
---
320-
*Powered by [Hypatia](https://github.com/hyperpolymath/hypatia) - Neurosymbolic CI/CD Intelligence*
321-
EOF
322-
323-
cat hypatia-report.md >> $GITHUB_STEP_SUMMARY
324-
- name: Comment on PR with findings
325-
if: github.event_name == 'pull_request' && steps.scan.outputs.findings_count > 0
326-
# Advisory only — posting findings as a PR comment must never gate
327-
# the scan (hypatia#213 gate decoupling). Belt-and-braces alongside
328-
# the pull-requests: write permission above: a token/API hiccup or
329-
# a fork PR (read-only token) skips the comment, not the check.
330-
continue-on-error: true
331-
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7
332-
with:
333-
script: "const fs = require('fs');\nconst findings = JSON.parse(fs.readFileSync('hypatia-findings.json', 'utf8'));\n\nconst critical = findings.filter(f => f.severity === 'critical').length;\nconst high = findings.filter(f => f.severity === 'high').length;\n\nlet comment = `## \U0001F50D Hypatia Security Scan\\n\\n`;\ncomment += `**Findings:** ${findings.length} issues detected\\n\\n`;\ncomment += `| Severity | Count |\\n|----------|-------|\\n`;\ncomment += `| \U0001F534 Critical | ${critical} |\\n`;\ncomment += `| \U0001F7E0 High | ${high} |\\n`;\ncomment += `| \U0001F7E1 Medium | ${findings.length - critical - high} |\\n\\n`;\n\nif (critical > 0) {\n comment += `⚠️ **Action Required:** Critical security issues found!\\n\\n`;\n}\n\ncomment += `<details><summary>View findings</summary>\\n\\n`;\ncomment += `\\`\\`\\`json\\n${JSON.stringify(findings.slice(0, 10), null, 2)}\\n\\`\\`\\`\\n`;\ncomment += `</details>\\n\\n`;\ncomment += `*Powered by Hypatia Neurosymbolic CI/CD Intelligence*`;\n\ngithub.rest.issues.createComment({\n owner: context.repo.owner,\n repo: context.repo.repo,\n issue_number: context.issue.number,\n body: comment\n});"
19+
uses: hyperpolymath/standards/.github/workflows/hypatia-scan-reusable.yml@5a93d9d57cc04de4002d6d0ecd336fc7a8698910

0 commit comments

Comments
 (0)