Skip to content

Commit b0528d8

Browse files
committed
ci: adopt standards reusable workflows for Scorecard, Hypatia, and Governance
1 parent ef53e89 commit b0528d8

4 files changed

Lines changed: 20 additions & 426 deletions

File tree

.github/workflows/governance.yml

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

.github/workflows/hypatia-scan.yml

Lines changed: 6 additions & 303 deletions
Original file line numberDiff line numberDiff line change
@@ -1,316 +1,19 @@
1-
# SPDX-License-Identifier: MPL-2.0
2-
# Thin wrapper around hyperpolymath/standards hypatia-scan-reusable.yml.
3-
# See standards#191 for the reusable's purpose and design.
4-
1+
# SPDX-License-Identifier: PMPL-1.0-or-later
52
name: Hypatia Security Scan
3+
64
on:
75
push:
86
branches: [main, master, develop]
97
pull_request:
108
branches: [main, master]
119
schedule:
12-
- cron: '0 0 * * 0' # Weekly on Sunday
10+
- cron: '0 0 * * 0'
1311
workflow_dispatch:
1412

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

0 commit comments

Comments
 (0)