-
Notifications
You must be signed in to change notification settings - Fork 23
87 lines (78 loc) · 2.92 KB
/
Copy pathcodeql.yaml
File metadata and controls
87 lines (78 loc) · 2.92 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
78
79
80
81
82
83
84
85
86
87
name: CodeQL
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
# Run every Tuesday at 5:30 AM UTC
- cron: '30 5 * * 2'
jobs:
analyze:
name: Analyze
# Trusted sources on our own runner; fork PRs on the hosted runner.
runs-on: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && 'self-hosted' || 'ubuntu-latest' }}
permissions:
actions: read
contents: read
packages: read
security-events: write
strategy:
fail-fast: false
matrix:
include:
- language: python
query_suite: security-extended
suppression_pack: +codeql/python-queries:AlertSuppression.ql
- language: actions
query_suite: security-and-quality,security-experimental
suppression_pack: ""
- language: javascript-typescript
query_suite: security-extended
suppression_pack: ""
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Start CodeQL
uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
with:
languages: ${{ matrix.language }}
queries: ${{ matrix.query_suite }}
packs: ${{ matrix.suppression_pack }}
config-file: ./codeql-config.yml
- name: Perform CodeQL analysis
id: analyze
uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
with:
category: "/language:${{ matrix.language }}"
output: sarif-results
- name: Show SARIF suppressed result statistics
id: sarif-stats
run: |
python - <<'PY'
import json, os, pathlib
sarif_dir = pathlib.Path("sarif-results")
sarif_files = list(sarif_dir.glob("*.sarif"))
if not sarif_files:
print("No SARIF files found in sarif-results/")
raise SystemExit(1)
p = sarif_files[0]
data = json.loads(p.read_text())
results = data["runs"][0].get("results", [])
suppressed = [r for r in results if r.get("suppressions")]
print(f"SARIF file: {p}")
print(f"Total results: {len(results)}")
print(f"Suppressed results: {len(suppressed)}")
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"sarif-file={p}\n")
PY
- name: Dismiss alerts of suppressed results
if: github.ref == 'refs/heads/main'
uses: advanced-security/dismiss-alerts@046d6b48d2e43cf563f96f67332c47c432eff83e # v2.0.2
with:
sarif-id: ${{ steps.analyze.outputs.sarif-id }}
sarif-file: ${{ steps.sarif-stats.outputs.sarif-file }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}