diff --git a/.github/workflows/static-analysis-gate.yml b/.github/workflows/static-analysis-gate.yml index ce221db..08c7266 100644 --- a/.github/workflows/static-analysis-gate.yml +++ b/.github/workflows/static-analysis-gate.yml @@ -2,7 +2,10 @@ # SPDX-License-Identifier: MPL-2.0 # This workflow is managed by gh actions-lock. # Static Analysis Gate — Required by branch protection rules. -# Runs panic-attack and hypatia, deposits findings for gitbot-fleet learning. +# Runs panic-attack and patch-bridge, deposits findings for gitbot-fleet learning. +# Hypatia does not run here: .github/workflows/hypatia-scan.yml runs it, once, +# as the rsr-template-repo gate does. This file used to run a second copy that +# passed even when the Hypatia build failed. name: Static Analysis Gate on: pull_request: @@ -46,7 +49,7 @@ jobs: PA_EXIT=$? set -e - # Same defect class as the Hypatia job below: `2>&1` folded the + # A defect class seen before in this workflow: `2>&1` folded the # scanner's stderr into the JSON payload, so every jq parse failed, # every count silently became 0 via `|| echo 0`, and "Fail on critical # findings" could never fire on any input. Keep stderr on the log. @@ -58,7 +61,7 @@ jobs: # release binary whose exit-code and output contract are not verified # here, and it has no confirmed --exit-zero equivalent, so we surface a # malformed payload in the log rather than block on an unverified tool. - # Promote to `exit 1` (as the Hypatia job does) once that contract is + # Promote to `exit 1` once that contract is # confirmed -- see the follow-up issue linked from this PR. if ! jq -e 'type == "array"' panic-attack-findings.json >/dev/null 2>&1; then echo "::warning::panic-attack output is not a JSON array (exit ${PA_EXIT}); counts below are unreliable" @@ -129,133 +132,7 @@ jobs: echo "::error::panic-attack found ${{ steps.assail.outputs.critical }} critical issue(s) — blocking merge" exit 1 # --------------------------------------------------------------------------- - # Job 2: hypatia-scan - # --------------------------------------------------------------------------- - hypatia-scan: - name: Hypatia neurosymbolic scan - runs-on: ubuntu-latest - timeout-minutes: 15 - steps: - - name: Checkout repository - uses: actions/checkout@v7.0.1 - with: - fetch-depth: 0 - - name: Setup Elixir for Hypatia scanner - id: beam - continue-on-error: true - uses: erlef/setup-beam@v1.24.1 - with: - elixir-version: '1.19.4' - otp-version: '27.3.4.19' - - name: Clone and build Hypatia - id: build - continue-on-error: true - run: | - git clone https://github.com/hyperpolymath/hypatia.git "$HOME/hypatia" 2>/dev/null || true - if [ -f "$HOME/hypatia/mix.exs" ]; then - cd "$HOME/hypatia" - # Build escript if neither hypatia nor hypatia-v2 exists - if [ ! -f hypatia ] && [ ! -f hypatia-v2 ]; then - mix deps.get - mix escript.build - fi - echo "ready=true" >> "$GITHUB_OUTPUT" - else - echo "::notice::Hypatia scanner not available — skipping scan" - echo "ready=false" >> "$GITHUB_OUTPUT" - fi - - name: Run Hypatia scan - id: scan - if: steps.build.outputs.ready == 'true' - run: | - set +e - HYPATIA_FORMAT=json "$HOME/hypatia/hypatia-cli.sh" scan . --exit-zero > hypatia-findings.json - HYP_EXIT=$? - set -e - - # --exit-zero is Hypatia's own documented CI recipe (lib/hypatia/cli.ex), - # for exactly this case: "use in CI when a downstream step gates on - # severity counts". Findings go to stdout, the one-line summary to - # stderr, and the process exits 0 unless the SCANNER itself failed. - # - # Do NOT redirect stderr into the payload with `2>&1`: that folds the - # summary line into the JSON, so every parse fails, the old `[]` - # fallback substituted a clean result, CRITICAL was always 0, and the - # gate below could never fire on any input. Keep stderr on the log. - if [ "$HYP_EXIT" -ne 0 ]; then - echo "::error::Hypatia scanner execution failed with exit ${HYP_EXIT}" - exit "$HYP_EXIT" - fi - # `jq empty` is NOT sufficient -- it succeeds on any valid JSON, - # including a bare string, object or null. Assert the array. - if [ ! -s hypatia-findings.json ] || ! jq -e 'type == "array"' hypatia-findings.json >/dev/null; then - echo "::error::Hypatia did not produce a valid JSON findings array" - exit 1 - fi - - TOTAL=$(jq '. | length' hypatia-findings.json 2>/dev/null || echo 0) - CRITICAL=$(jq '[.[] | select(.severity == "critical")] | length' hypatia-findings.json 2>/dev/null || echo 0) - HIGH=$(jq '[.[] | select(.severity == "high")] | length' hypatia-findings.json 2>/dev/null || echo 0) - MEDIUM=$(jq '[.[] | select(.severity == "medium")] | length' hypatia-findings.json 2>/dev/null || echo 0) - LOW=$(jq '[.[] | select(.severity == "low")] | length' hypatia-findings.json 2>/dev/null || echo 0) - - echo "total=$TOTAL" >> "$GITHUB_OUTPUT" - echo "critical=$CRITICAL" >> "$GITHUB_OUTPUT" - echo "high=$HIGH" >> "$GITHUB_OUTPUT" - echo "medium=$MEDIUM" >> "$GITHUB_OUTPUT" - echo "low=$LOW" >> "$GITHUB_OUTPUT" - - name: Emit check annotations - if: steps.build.outputs.ready == 'true' - run: | - # Findings carry no `.message` (keys: action,file,line,reason,rule_module, - # severity,type), so every annotation read "null". `.file` is an absolute - # runner path, which GitHub cannot anchor to the diff, so it is made - # workspace-relative here. - jq -r --arg ws "$GITHUB_WORKSPACE" '.[] | select(.file != null) | - (.file | ltrimstr($ws + "/")) as $f | - (.reason // .message // .type // "finding") as $m | - if .severity == "critical" then - "::error file=\($f),line=\(.line // 1)::[hypatia] \($m)" - elif .severity == "high" then - "::error file=\($f),line=\(.line // 1)::[hypatia] \($m)" - else - "::warning file=\($f),line=\(.line // 1)::[hypatia] \($m)" - end - ' hypatia-findings.json || true - - name: Write step summary - if: steps.build.outputs.ready == 'true' - run: | - cat <> "$GITHUB_STEP_SUMMARY" - ## Hypatia Scan Results - - | Severity | Count | - |----------|-------| - | Critical | ${{ steps.scan.outputs.critical }} | - | High | ${{ steps.scan.outputs.high }} | - | Medium | ${{ steps.scan.outputs.medium }} | - | Low | ${{ steps.scan.outputs.low }} | - | **Total**| ${{ steps.scan.outputs.total }} | - EOF - - name: Create stub findings (when Hypatia unavailable) - if: steps.build.outputs.ready != 'true' - run: | - echo "[]" > hypatia-findings.json - echo "## Hypatia Scan" >> "$GITHUB_STEP_SUMMARY" - echo "" >> "$GITHUB_STEP_SUMMARY" - echo "Skipped: Hypatia scanner not available in this environment." >> "$GITHUB_STEP_SUMMARY" - - name: Upload hypatia findings - uses: actions/upload-artifact@v7.0.2 - with: - name: hypatia-findings - path: hypatia-findings.json - retention-days: 90 - - name: Fail on critical security findings - if: steps.build.outputs.ready == 'true' && steps.scan.outputs.critical > 0 - run: | - echo "::error::Hypatia found ${{ steps.scan.outputs.critical }} critical security issue(s) — blocking merge" - exit 1 - # --------------------------------------------------------------------------- - # Job 3: patch-bridge triage (CVE contextual assessment) + # Job 2: patch-bridge triage (CVE contextual assessment) # --------------------------------------------------------------------------- patch-bridge-triage: name: Patch Bridge CVE triage @@ -337,13 +214,13 @@ jobs: # Warning only, not blocking. Unmitigable means the developer needs # to make an architectural decision, not that the PR is wrong. # --------------------------------------------------------------------------- - # Job 4: deposit-findings (combines + archives for gitbot-fleet) + # Job 3: deposit-findings (combines + archives for gitbot-fleet) # --------------------------------------------------------------------------- deposit-findings: name: Deposit findings for gitbot-fleet runs-on: ubuntu-latest timeout-minutes: 15 - needs: [panic-attack-assail, hypatia-scan, patch-bridge-triage] + needs: [panic-attack-assail, patch-bridge-triage] if: always() steps: - name: Download panic-attack findings @@ -351,11 +228,6 @@ jobs: with: name: panic-attack-findings path: findings/ - - name: Download hypatia findings - uses: actions/download-artifact@v8.0.2 - with: - name: hypatia-findings - path: findings/ - name: Download bridge report uses: actions/download-artifact@v8.0.2 with: @@ -365,18 +237,14 @@ jobs: id: combine run: | PA_FILE="findings/panic-attack-findings.json" - HYP_FILE="findings/hypatia-findings.json" - # Ensure both files exist and are valid JSON arrays - for f in "$PA_FILE" "$HYP_FILE"; do - if [ ! -s "$f" ] || ! jq empty "$f" 2>/dev/null; then - echo "[]" > "$f" - fi - done + # Ensure the file exists and is a valid JSON array + if [ ! -s "$PA_FILE" ] || ! jq empty "$PA_FILE" 2>/dev/null; then + echo "[]" > "$PA_FILE" + fi # Tag each finding with its source scanner jq '[.[] | . + {"scanner": "panic-attack"}]' "$PA_FILE" > /tmp/pa-tagged.json - jq '[.[] | . + {"scanner": "hypatia"}]' "$HYP_FILE" > /tmp/hyp-tagged.json # Read bridge report (CVE triage, not findings array) BRIDGE_FILE="findings/bridge-report.json" @@ -392,7 +260,6 @@ jobs: --arg run_id "${{ github.run_id }}" \ --arg ts "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ --slurpfile pa /tmp/pa-tagged.json \ - --slurpfile hyp /tmp/hyp-tagged.json \ --slurpfile bridge "$BRIDGE_FILE" \ '{ schema_version: "1.1.0", @@ -401,7 +268,7 @@ jobs: ref: $ref, run_id: $run_id, timestamp: $ts, - findings: ($pa[0] + $hyp[0]), + findings: $pa[0], patch_bridge: $bridge[0] }' > findings/unified-findings.json