@@ -76,10 +76,48 @@ jobs:
7676 - name : " Layer 8: Vendored dependency integrity"
7777 run : scripts/security-vendored.sh
7878
79- # ── Step 1c: CodeQL SAST gate (checks for open alerts) ──────
79+ # ── Step 1c: CodeQL SAST gate ────────────────────────────────
80+ # Verifies CodeQL has run on the current commit AND has 0 open alerts.
81+ # Prevents false green from stale/missing scans.
8082 codeql-gate :
8183 runs-on : ubuntu-latest
8284 steps :
85+ - name : Wait for CodeQL on current commit (max 30 min)
86+ env :
87+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
88+ run : |
89+ CURRENT_SHA="${{ github.sha }}"
90+ echo "Current commit: $CURRENT_SHA"
91+ echo "Waiting for CodeQL to complete on this commit..."
92+
93+ for attempt in $(seq 1 60); do
94+ LATEST=$(gh api repos/${{ github.repository }}/actions/workflows/codeql.yml/runs?per_page=5 \
95+ --jq '.workflow_runs[] | select(.head_sha == "'"$CURRENT_SHA"'") | "\(.conclusion) \(.status)"' 2>/dev/null | head -1 || echo "")
96+
97+ if [ -z "$LATEST" ]; then
98+ echo " Attempt $attempt/60: No CodeQL run found for $CURRENT_SHA yet..."
99+ sleep 30
100+ continue
101+ fi
102+
103+ CONCLUSION=$(echo "$LATEST" | cut -d' ' -f1)
104+ STATUS=$(echo "$LATEST" | cut -d' ' -f2)
105+
106+ if [ "$STATUS" = "completed" ] && [ "$CONCLUSION" = "success" ]; then
107+ echo "=== CodeQL completed successfully on current commit ==="
108+ exit 0
109+ elif [ "$STATUS" = "completed" ]; then
110+ echo "BLOCKED: CodeQL completed with conclusion: $CONCLUSION"
111+ exit 1
112+ fi
113+
114+ echo " Attempt $attempt/60: CodeQL status=$STATUS (waiting 30s)..."
115+ sleep 30
116+ done
117+
118+ echo "BLOCKED: CodeQL did not complete within 30 minutes"
119+ exit 1
120+
83121 - name : Check for open code scanning alerts
84122 env :
85123 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
91129 echo "Fix them before releasing: https://github.com/${{ github.repository }}/security/code-scanning"
92130 exit 1
93131 fi
94- echo "=== CodeQL gate passed (0 open alerts) ==="
132+ echo "=== CodeQL gate passed (0 open alerts on current commit ) ==="
95133
96134 # ── Step 2: Unit tests (ASan + UBSan) ───────────────────────
97135 # macOS: use cc (Apple Clang) — GCC on macOS doesn't ship ASan runtime
0 commit comments