|
| 1 | +# Branch Protection Setup: Static Analysis Gate |
| 2 | + |
| 3 | +> SPDX-License-Identifier: PMPL-1.0-or-later |
| 4 | +
|
| 5 | +This document explains how to wire the `static-analysis-gate.yml` workflow into |
| 6 | +GitHub branch protection so that every PR must pass panic-attack and hypatia |
| 7 | +before merging. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Required Status Checks |
| 12 | + |
| 13 | +In your repository's **Settings > Branches > Branch protection rules** for |
| 14 | +`main` (and/or `master`), enable: |
| 15 | + |
| 16 | +| Status check name | Source workflow | |
| 17 | +|-------------------------------------------|-----------------------------| |
| 18 | +| `panic-attack assail` | `static-analysis-gate.yml` | |
| 19 | +| `Hypatia neurosymbolic scan` | `static-analysis-gate.yml` | |
| 20 | +| `Deposit findings for gitbot-fleet` | `static-analysis-gate.yml` | |
| 21 | + |
| 22 | +### Recommended branch protection settings |
| 23 | + |
| 24 | +- **Require status checks to pass before merging** — enabled |
| 25 | +- **Require branches to be up to date before merging** — enabled |
| 26 | +- **Include administrators** — enabled (lead by example) |
| 27 | +- **Restrict who can push to matching branches** — optional, recommended |
| 28 | + |
| 29 | +> **Note:** The `Hypatia Security Scan` check from the older `hypatia-scan.yml` |
| 30 | +> workflow is a *separate* status check. You may keep both or retire the older |
| 31 | +> one; `static-analysis-gate.yml` is the unified replacement. |
| 32 | +
|
| 33 | +--- |
| 34 | + |
| 35 | +## Enabling the Workflow in Any Repo |
| 36 | + |
| 37 | +### From the RSR template |
| 38 | + |
| 39 | +Repos bootstrapped from `rsr-template-repo` already include |
| 40 | +`.github/workflows/static-analysis-gate.yml`. Replace `{{OWNER}}` with your |
| 41 | +GitHub org/user name: |
| 42 | + |
| 43 | +```bash |
| 44 | +sed -i 's/{{OWNER}}/hyperpolymath/g' .github/workflows/static-analysis-gate.yml |
| 45 | +``` |
| 46 | + |
| 47 | +### Adding to an existing repo |
| 48 | + |
| 49 | +Copy the workflow file into the target repo: |
| 50 | + |
| 51 | +```bash |
| 52 | +cp /path/to/rsr-template-repo/.github/workflows/static-analysis-gate.yml \ |
| 53 | + your-repo/.github/workflows/static-analysis-gate.yml |
| 54 | + |
| 55 | +cd your-repo |
| 56 | +sed -i 's/{{OWNER}}/hyperpolymath/g' .github/workflows/static-analysis-gate.yml |
| 57 | +git add .github/workflows/static-analysis-gate.yml |
| 58 | +git commit -m "ci: add static analysis gate for branch protection" |
| 59 | +git push |
| 60 | +``` |
| 61 | + |
| 62 | +Then add the status checks in **Settings > Branches** as described above. |
| 63 | + |
| 64 | +--- |
| 65 | + |
| 66 | +## Local Pre-Push Hook |
| 67 | + |
| 68 | +A local hook mirrors the CI gate so developers catch critical findings before |
| 69 | +pushing. Install it from `gitbot-fleet/hooks/pre-push-gate.sh`: |
| 70 | + |
| 71 | +```bash |
| 72 | +# Symlink (recommended — always picks up updates) |
| 73 | +ln -sf ~/Documents/hyperpolymath-repos/gitbot-fleet/hooks/pre-push-gate.sh \ |
| 74 | + .git/hooks/pre-push |
| 75 | + |
| 76 | +# Or copy |
| 77 | +cp ~/Documents/hyperpolymath-repos/gitbot-fleet/hooks/pre-push-gate.sh \ |
| 78 | + .git/hooks/pre-push |
| 79 | +chmod +x .git/hooks/pre-push |
| 80 | +``` |
| 81 | + |
| 82 | +The hook gracefully degrades: if neither panic-attack nor hypatia is installed |
| 83 | +locally, it prints a notice and allows the push (CI will catch it). |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +## How Findings Flow Back to Hypatia for Learning |
| 88 | + |
| 89 | +``` |
| 90 | +Developer pushes / opens PR |
| 91 | + | |
| 92 | + v |
| 93 | +static-analysis-gate.yml runs |
| 94 | + | |
| 95 | + +---> panic-attack assail ---> findings JSON artifact |
| 96 | + +---> hypatia scan ---> findings JSON artifact |
| 97 | + | |
| 98 | + v |
| 99 | +deposit-findings job |
| 100 | + | |
| 101 | + +---> Combines both into unified-findings.json |
| 102 | + +---> Uploads as "unified-findings" artifact (90-day retention) |
| 103 | + | |
| 104 | + v |
| 105 | +gitbot-fleet scanner (scheduled) |
| 106 | + | |
| 107 | + +---> Queries GitHub API for repos with unified-findings artifacts |
| 108 | + +---> Downloads and ingests into hypatia's learning corpus |
| 109 | + +---> Feeds rhodibot / echidnabot / sustainabot for pattern recognition |
| 110 | + | |
| 111 | + v |
| 112 | +Hypatia learning engine |
| 113 | + | |
| 114 | + +---> Updates neurosymbolic rules based on recurring patterns |
| 115 | + +---> Feeds improved rules back into hypatia-cli.sh |
| 116 | + +---> Cycle repeats with better detection on next scan |
| 117 | +``` |
| 118 | + |
| 119 | +### Artifact-based ingestion |
| 120 | + |
| 121 | +The `deposit-findings` job uploads a `unified-findings` artifact to each |
| 122 | +workflow run. The gitbot-fleet's `learning-monitor.sh` script periodically: |
| 123 | + |
| 124 | +1. Lists recent workflow runs across enrolled repos. |
| 125 | +2. Downloads `unified-findings` artifacts. |
| 126 | +3. Parses the JSON envelope (`schema_version`, `repository`, `commit_sha`, |
| 127 | + `timestamp`, `findings[]`). |
| 128 | +4. Deduplicates findings already in the learning corpus. |
| 129 | +5. Submits new findings to hypatia's pattern database. |
| 130 | + |
| 131 | +No secrets or special tokens are needed beyond the default `GITHUB_TOKEN` — |
| 132 | +artifacts are readable by the repo owner. |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +## Note on oikos/sustainabot |
| 137 | + |
| 138 | +The `sustainabot` bot was registered in the gitbot-fleet as a sustainability |
| 139 | +and maintenance scanner, but was never fully wired into the CI pipeline. |
| 140 | +`static-analysis-gate.yml` replaces the role sustainabot was intended to fill: |
| 141 | + |
| 142 | +- **What sustainabot was supposed to do:** Run periodic checks and flag |
| 143 | + maintenance debt. |
| 144 | +- **What static-analysis-gate does instead:** Runs on every PR and push, |
| 145 | + combining panic-attack (code quality / dangerous patterns) and hypatia |
| 146 | + (neurosymbolic security analysis) into a single required gate. |
| 147 | +- **sustainabot's remaining role:** It can still operate as a *scheduled* |
| 148 | + scanner for repos that have not yet adopted the gate workflow. Over time, |
| 149 | + as all repos adopt `static-analysis-gate.yml`, sustainabot's workload |
| 150 | + naturally decreases to zero. |
| 151 | + |
| 152 | +The gitbot-fleet coordinator (`fleet-coordinator.sh`) should be updated to |
| 153 | +recognise `unified-findings` artifacts as the primary input channel, replacing |
| 154 | +the ad-hoc sustainabot submission path. |
| 155 | + |
| 156 | +--- |
| 157 | + |
| 158 | +## Checklist for New Repos |
| 159 | + |
| 160 | +- [ ] Copy `static-analysis-gate.yml` into `.github/workflows/` |
| 161 | +- [ ] Replace `{{OWNER}}` placeholder |
| 162 | +- [ ] Push to trigger first run |
| 163 | +- [ ] Add required status checks in branch protection settings |
| 164 | +- [ ] Install local pre-push hook (optional but recommended) |
| 165 | +- [ ] Verify `unified-findings` artifact appears after first run |
0 commit comments