11# SPDX-License-Identifier: MPL-2.0
2- # Hypatia Neurosymbolic CI/CD Security Scan
2+ # Thin wrapper around hyperpolymath/standards hypatia-scan-reusable.yml.
3+ # See standards#191 for the reusable's purpose and design.
4+
35name : Hypatia Security Scan
46
57on :
68 push :
7- branches : [ main, master, develop ]
9+ branches : [main, master, develop]
810 pull_request :
9- branches : [ main, master ]
11+ branches : [main, master]
1012 schedule :
11- - cron : ' 0 0 * * 0' # Weekly on Sunday
13+ - cron : ' 0 0 * * 0'
1214 workflow_dispatch :
1315
16+ # Estate guardrail: cancel superseded runs so re-pushes don't pile up.
17+ concurrency :
18+ group : ${{ github.workflow }}-${{ github.ref }}
19+ cancel-in-progress : true
20+
1421permissions :
1522 contents : read
16- # security-events: read lets the built-in GITHUB_TOKEN query this
17- # repo\'s own Dependabot alerts via the Hypatia DependabotAlerts rule.
18- security-events : read
23+ security-events : write
24+ pull-requests : write
1925
2026jobs :
21- scan :
22- name : Hypatia Neurosymbolic Analysis
23- runs-on : ubuntu-latest
24-
25- steps :
26- - name : Checkout repository
27- uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
28- with :
29- fetch-depth : 0 # Full history for better pattern analysis
30-
31- - name : Setup Elixir for Hypatia scanner
32- id : beam
33- continue-on-error : true
34- uses : erlef/setup-beam@e6d7c94229049569db56a7ad5a540c051a010af9 # v1.18.2
35- with :
36- elixir-version : ' 1.19.4'
37- otp-version : ' 28.3'
38-
39- # Upstream hyperpolymath/hypatia was refactored to shell entrypoints;
40- # it no longer has a scanner/ subdir. Build the escript at the repo
41- # root only if no prebuilt binary exists, and never hard-fail on a
42- # missing/unbuildable scanner — mirrors the resilient pattern in
43- # static-analysis-gate.yml so a tooling outage cannot block merges.
44- - name : Clone and build Hypatia
45- id : build
46- continue-on-error : true
47- run : |
48- git clone https://github.com/hyperpolymath/hypatia.git "$HOME/hypatia" 2>/dev/null || true
49- if [ -f "$HOME/hypatia/mix.exs" ]; then
50- cd "$HOME/hypatia"
51- if [ ! -f hypatia ] && [ ! -f hypatia-v2 ]; then
52- mix deps.get
53- mix escript.build
54- fi
55- echo "ready=true" >> "$GITHUB_OUTPUT"
56- else
57- echo "::notice::Hypatia scanner not available — skipping scan"
58- echo "ready=false" >> "$GITHUB_OUTPUT"
59- fi
60-
61- - name : Run Hypatia scan
62- id : scan
63- if : steps.build.outputs.ready == 'true'
64- run : |
65- echo "Scanning repository: ${{ github.repository }}"
66- set +e
67- HYPATIA_FORMAT=json "$HOME/hypatia/hypatia-cli.sh" scan . > hypatia-findings.json 2>&1
68- set -e
69-
70- # Sanitize: ensure valid JSON array even if the scanner errored.
71- if [ ! -s hypatia-findings.json ] || ! jq empty hypatia-findings.json 2>/dev/null; then
72- echo "[]" > hypatia-findings.json
73- fi
74-
75- FINDING_COUNT=$(jq '. | length' hypatia-findings.json 2>/dev/null || echo 0)
76- CRITICAL=$(jq '[.[] | select(.severity == "critical")] | length' hypatia-findings.json 2>/dev/null || echo 0)
77- HIGH=$(jq '[.[] | select(.severity == "high")] | length' hypatia-findings.json 2>/dev/null || echo 0)
78- MEDIUM=$(jq '[.[] | select(.severity == "medium")] | length' hypatia-findings.json 2>/dev/null || echo 0)
79-
80- echo "findings_count=$FINDING_COUNT" >> $GITHUB_OUTPUT
81- echo "critical=$CRITICAL" >> $GITHUB_OUTPUT
82- echo "high=$HIGH" >> $GITHUB_OUTPUT
83- echo "medium=$MEDIUM" >> $GITHUB_OUTPUT
84-
85- echo "## Hypatia Scan Results" >> $GITHUB_STEP_SUMMARY
86- echo "- Total findings: $FINDING_COUNT" >> $GITHUB_STEP_SUMMARY
87- echo "- Critical: $CRITICAL" >> $GITHUB_STEP_SUMMARY
88- echo "- High: $HIGH" >> $GITHUB_STEP_SUMMARY
89- echo "- Medium: $MEDIUM" >> $GITHUB_STEP_SUMMARY
90-
91- - name : Create stub findings (when Hypatia unavailable)
92- if : steps.build.outputs.ready != 'true'
93- run : |
94- echo "[]" > hypatia-findings.json
95- {
96- echo "## Hypatia Scan"
97- echo ""
98- echo "Skipped: Hypatia scanner not available in this environment."
99- } >> "$GITHUB_STEP_SUMMARY"
100-
101- - name : Upload findings artifact
102- uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
103- with :
104- name : hypatia-findings
105- path : hypatia-findings.json
106- retention-days : 90
107-
108- - name : Submit findings to gitbot-fleet (Phase 2)
109- if : steps.scan.outputs.findings_count > 0
110- # Phase 2 is the collaborative LEARNING side-channel ("bots share
111- # findings via gitbot-fleet"), not the security gate. The gate is
112- # the baseline-aware "Check for critical or high-severity issues"
113- # step below. A fleet-side regression (e.g. the submit script being
114- # moved/removed) must NEVER hard-fail every consuming repo's scan.
115- # Same reasoning as the "Comment on PR with findings" step.
116- # See hyperpolymath/hypatia#213 (gate decoupling) and the exit-127
117- # estate-wide breakage when gitbot-fleet/scripts/submit-finding.sh
118- # no longer existed on the default branch.
119- continue-on-error : true
120- env :
121- # All GitHub context values surface as env vars so the run
122- # block never interpolates `${{ … }}` inline (closes the
123- # workflow_audit/unsafe_curl_payload + actions_expression_injection
124- # findings).
125- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
126- FLEET_PUSH_TOKEN : ${{ secrets.HYPATIA_DISPATCH_PAT }}
127- FLEET_DISPATCH_TOKEN : ${{ secrets.HYPATIA_DISPATCH_PAT }}
128- GITHUB_REPOSITORY : ${{ github.repository }}
129- GITHUB_SHA : ${{ github.sha }}
130- FINDINGS_COUNT : ${{ steps.scan.outputs.findings_count }}
131- run : |
132- echo "📤 Submitting $FINDINGS_COUNT findings to gitbot-fleet..."
133-
134- # Clone gitbot-fleet to temp directory. A clone failure (network,
135- # repo gone) is non-fatal: learning submission is best-effort.
136- FLEET_DIR="/tmp/gitbot-fleet-$$"
137- if ! git clone --depth 1 https://github.com/hyperpolymath/gitbot-fleet.git "$FLEET_DIR"; then
138- echo "::warning::Could not clone gitbot-fleet — skipping Phase 2 learning submission (non-fatal)."
139- exit 0
140- fi
141-
142- # The submission script's location in gitbot-fleet has drifted
143- # before (it was absent from the default branch, which exit-127'd
144- # every consuming repo's scan). Probe known locations rather than
145- # hard-coding one path, and skip gracefully if none is present.
146- SUBMIT_SCRIPT=""
147- for cand in \
148- "$FLEET_DIR/scripts/submit-finding.sh" \
149- "$FLEET_DIR/scripts/submit_finding.sh" \
150- "$FLEET_DIR/bin/submit-finding.sh" \
151- "$FLEET_DIR/submit-finding.sh"; do
152- if [ -f "$cand" ]; then
153- SUBMIT_SCRIPT="$cand"
154- break
155- fi
156- done
157-
158- if [ -z "$SUBMIT_SCRIPT" ]; then
159- 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."
160- rm -rf "$FLEET_DIR"
161- exit 0
162- fi
163-
164- # Run submission script. Pass the findings path as ABSOLUTE —
165- # the script cd's into its own working dir before reading the
166- # file, so a relative path would resolve to the wrong place.
167- # A submission-script failure is logged but non-fatal.
168- if bash "$SUBMIT_SCRIPT" "$GITHUB_WORKSPACE/hypatia-findings.json"; then
169- echo "✅ Finding submission complete"
170- else
171- echo "::warning::gitbot-fleet submission script exited non-zero — Phase 2 learning submission skipped (non-fatal)."
172- fi
173-
174- # Cleanup
175- rm -rf "$FLEET_DIR"
176-
177- - name : Check for critical issues
178- if : steps.scan.outputs.critical > 0
179- run : |
180- echo "⚠️ Critical security issues found!"
181- echo "Review hypatia-findings.json for details"
182- # Don't fail the build yet - just warn
183- # exit 1
184-
185- - name : Generate scan report
186- run : |
187- cat << EOF > hypatia-report.md
188- # Hypatia Security Scan Report
189-
190- **Repository:** ${{ github.repository }}
191- **Scan Date:** $(date -u +"%Y-%m-%d %H:%M:%S UTC")
192- **Commit:** ${{ github.sha }}
193-
194- ## Summary
195-
196- | Severity | Count |
197- |----------|-------|
198- | Critical | ${{ steps.scan.outputs.critical }} |
199- | High | ${{ steps.scan.outputs.high }} |
200- | Medium | ${{ steps.scan.outputs.medium }} |
201- | **Total**| ${{ steps.scan.outputs.findings_count }} |
202-
203- ## Next Steps
204-
205- 1. Review findings in the artifact: hypatia-findings.json
206- 2. Auto-fixable issues will be addressed by robot-repo-automaton (Phase 3)
207- 3. Manual review required for complex issues
208-
209- ## Learning
210-
211- These findings feed Hypatia's learning engine to improve future rules.
212-
213- ---
214- *Powered by [Hypatia](https://github.com/hyperpolymath/hypatia) - Neurosymbolic CI/CD Intelligence*
215- EOF
216-
217- cat hypatia-report.md >> $GITHUB_STEP_SUMMARY
218-
219- - name : Comment on PR with findings
220- if : github.event_name == 'pull_request' && steps.scan.outputs.findings_count > 0
221- uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7
222- with :
223- script : |
224- const fs = require('fs');
225- const findings = JSON.parse(fs.readFileSync('hypatia-findings.json', 'utf8'));
226-
227- const critical = findings.filter(f => f.severity === 'critical').length;
228- const high = findings.filter(f => f.severity === 'high').length;
229-
230- let comment = `## 🔍 Hypatia Security Scan\n\n`;
231- comment += `**Findings:** ${findings.length} issues detected\n\n`;
232- comment += `| Severity | Count |\n|----------|-------|\n`;
233- comment += `| 🔴 Critical | ${critical} |\n`;
234- comment += `| 🟠 High | ${high} |\n`;
235- comment += `| 🟡 Medium | ${findings.length - critical - high} |\n\n`;
236-
237- if (critical > 0) {
238- comment += `⚠️ **Action Required:** Critical security issues found!\n\n`;
239- }
240-
241- comment += `<details><summary>View findings</summary>\n\n`;
242- comment += `\`\`\`json\n${JSON.stringify(findings.slice(0, 10), null, 2)}\n\`\`\`\n`;
243- comment += `</details>\n\n`;
244- comment += `*Powered by Hypatia Neurosymbolic CI/CD Intelligence*`;
245-
246- github.rest.issues.createComment({
247- owner: context.repo.owner,
248- repo: context.repo.repo,
249- issue_number: context.issue.number,
250- body: comment
251- });
27+ hypatia :
28+ uses : hyperpolymath/standards/.github/workflows/hypatia-scan-reusable.yml@97df762107501909f50bb770e9bc200b6c415600
29+ secrets : inherit
0 commit comments