-
Notifications
You must be signed in to change notification settings - Fork 1
94 lines (82 loc) · 2.97 KB
/
codeql.yml
File metadata and controls
94 lines (82 loc) · 2.97 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
88
89
90
91
92
93
94
name: CodeQL
on:
pull_request:
branches: ["main"]
push:
branches: ["main"]
schedule:
- cron: "17 4 * * 1"
workflow_dispatch:
permissions:
actions: read
contents: read
jobs:
analyze:
name: Analyser (${{ matrix.language }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- language: javascript-typescript
build-mode: none
- language: python
build-mode: none
steps:
- name: Cloner le depot
uses: actions/checkout@v4
- name: Initialiser CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
queries: +security-and-quality
- name: Executer l'analyse CodeQL
uses: github/codeql-action/analyze@v4
with:
category: "/language:${{ matrix.language }}"
output: codeql-results
upload: never
- name: Echouer si CodeQL trouve des alertes
run: |
python - <<'PY'
import json
import pathlib
import sys
sarif_files = sorted(pathlib.Path("codeql-results").glob("*.sarif"))
if not sarif_files:
print("Aucun fichier SARIF CodeQL trouve.")
sys.exit(1)
findings = []
for sarif_file in sarif_files:
data = json.loads(sarif_file.read_text(encoding="utf-8"))
for run in data.get("runs", []):
rules = {
rule.get("id"): rule
for rule in run.get("tool", {}).get("driver", {}).get("rules", [])
}
for result in run.get("results", []):
rule_id = result.get("ruleId", "unknown-rule")
rule = rules.get(rule_id, {})
message = result.get("message", {}).get("text") or rule.get("shortDescription", {}).get("text", "")
location = result.get("locations", [{}])[0].get("physicalLocation", {})
artifact = location.get("artifactLocation", {}).get("uri", "unknown-file")
region = location.get("region", {})
line = region.get("startLine", 1)
findings.append((rule_id, artifact, line, message))
if not findings:
print("CodeQL n'a trouve aucune alerte.")
sys.exit(0)
print(f"CodeQL a trouve {len(findings)} alerte(s):")
for rule_id, artifact, line, message in findings[:50]:
print(f"- {rule_id}: {artifact}:{line} - {message}")
if len(findings) > 50:
print(f"... {len(findings) - 50} alerte(s) supplementaire(s).")
sys.exit(1)
PY
- name: Archiver les resultats SARIF
if: always()
uses: actions/upload-artifact@v4
with:
name: codeql-sarif-${{ matrix.language }}
path: codeql-results