Skip to content

Commit 4322116

Browse files
committed
CodeQL gate: wait for scan on current commit (max 30 min)
1 parent f3e4eea commit 4322116

2 files changed

Lines changed: 77 additions & 5 deletions

File tree

.github/workflows/dry-run.yml

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,47 @@ jobs:
7575
- name: "Layer 8: Vendored dependency integrity"
7676
run: scripts/security-vendored.sh
7777

78-
# ── Step 1c: CodeQL SAST gate (checks for open alerts) ──────
79-
# CodeQL runs on push/PR via codeql.yml. This gate checks if
80-
# there are any open critical/high code scanning alerts.
78+
# ── Step 1c: CodeQL SAST gate ────────────────────────────────
8179
codeql-gate:
8280
if: ${{ !inputs.skip_lint }}
8381
runs-on: ubuntu-latest
8482
steps:
83+
- name: Wait for CodeQL on current commit (max 30 min)
84+
env:
85+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
run: |
87+
CURRENT_SHA="${{ github.sha }}"
88+
echo "Current commit: $CURRENT_SHA"
89+
echo "Waiting for CodeQL to complete on this commit..."
90+
91+
for attempt in $(seq 1 60); do
92+
LATEST=$(gh api repos/${{ github.repository }}/actions/workflows/codeql.yml/runs?per_page=5 \
93+
--jq '.workflow_runs[] | select(.head_sha == "'"$CURRENT_SHA"'") | "\(.conclusion) \(.status)"' 2>/dev/null | head -1 || echo "")
94+
95+
if [ -z "$LATEST" ]; then
96+
echo " Attempt $attempt/60: No CodeQL run found for $CURRENT_SHA yet..."
97+
sleep 30
98+
continue
99+
fi
100+
101+
CONCLUSION=$(echo "$LATEST" | cut -d' ' -f1)
102+
STATUS=$(echo "$LATEST" | cut -d' ' -f2)
103+
104+
if [ "$STATUS" = "completed" ] && [ "$CONCLUSION" = "success" ]; then
105+
echo "=== CodeQL completed successfully on current commit ==="
106+
exit 0
107+
elif [ "$STATUS" = "completed" ]; then
108+
echo "BLOCKED: CodeQL completed with conclusion: $CONCLUSION"
109+
exit 1
110+
fi
111+
112+
echo " Attempt $attempt/60: CodeQL status=$STATUS (waiting 30s)..."
113+
sleep 30
114+
done
115+
116+
echo "BLOCKED: CodeQL did not complete within 30 minutes"
117+
exit 1
118+
85119
- name: Check for open code scanning alerts
86120
env:
87121
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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 }}
@@ -91,7 +129,7 @@ jobs:
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

Comments
 (0)