-
Notifications
You must be signed in to change notification settings - Fork 125
77 lines (68 loc) · 2.52 KB
/
Copy pathcodeql.yml
File metadata and controls
77 lines (68 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: CodeQL Security Analysis
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: "0 8 * * 1"
jobs:
analyze:
name: Analyze (${{ matrix.language }})
runs-on: ubuntu-latest
permissions:
security-events: write
actions: read
contents: read
strategy:
fail-fast: false
matrix:
language: [javascript-typescript]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: security-and-quality
- name: Autobuild
uses: github/codeql-action/autobuild@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
# Upload results to the Security tab; high-severity findings
# will be reported and can be enforced via branch protection rules
# (Settings → Branches → Require status checks → CodeQL).
upload: always
# ── Block PR merge on high CodeQL findings ──────────────────────────────────
# Enable this by adding "CodeQL Results Check" as a required status check
# in Settings → Branches → Branch protection rules for `main`.
check-results:
name: CodeQL Results Check
runs-on: ubuntu-latest
needs: analyze
if: github.event_name == 'pull_request'
permissions:
security-events: read
contents: read
steps:
- name: Check for high-severity CodeQL alerts
uses: actions/github-script@v7
with:
script: |
const alerts = await github.rest.codeScanning.listAlertsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
severity: 'high',
ref: context.payload.pull_request.head.sha,
});
const highAlerts = alerts.data.filter(a => a.rule.severity === 'high' || a.rule.severity === 'critical');
if (highAlerts.length > 0) {
const summary = highAlerts.map(a => `- ${a.rule.id}: ${a.rule.description} (${a.most_recent_instance.location.path})`).join('\n');
core.setFailed(`❌ ${highAlerts.length} high/critical CodeQL finding(s) block this PR:\n${summary}`);
} else {
core.info('✅ No high-severity CodeQL findings.');
}