1
- name : " CodeQL code Scan"
1
+ name : " CodeQL Security Scan"
2
2
3
3
on :
4
4
pull_request :
5
5
types : [opened, synchronize, reopened]
6
+ push :
7
+ branches : [main, master]
8
+
9
+ permissions :
10
+ security-events : write
11
+ actions : read
12
+ contents : read
6
13
7
14
jobs :
8
15
codeql :
9
16
name : " CodeQL Analysis"
10
17
runs-on : ubuntu-latest
18
+ if : github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
11
19
12
20
concurrency :
13
- group : ${{ github.workflow }}-${{ github.event.pull_request.number }}
21
+ group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
14
22
cancel-in-progress : true
15
23
16
24
steps :
17
25
# 1️⃣ Checkout the repository
18
26
- name : Checkout repository
19
27
uses : actions/checkout@v4
28
+ with :
29
+ # 必须深度检出以获取完整历史记录进行精确分析
30
+ fetch-depth : 0
20
31
21
32
# 2️⃣ Initialize CodeQL
22
33
- name : Initialize CodeQL
23
34
uses : github/codeql-action/init@v3
24
35
with :
25
- languages : ["python","javascript"] # Add more languages if needed
36
+ languages : ["python","javascript"]
37
+ # 如果是私有仓库或需要认证的依赖,配置这里
38
+ # config-file: ./.github/codeql/codeql-config.yml
26
39
27
40
# 3️⃣ Auto-build the project for CodeQL
28
41
- name : Autobuild
29
42
uses : github/codeql-action/autobuild@v3
30
43
31
- # 4️⃣ Perform CodeQL analysis and generate SARIF report
44
+ # 4️⃣ Perform CodeQL analysis
32
45
- name : Perform CodeQL Analysis
33
46
uses : github/codeql-action/analyze@v3
34
47
with :
35
- output : results.sarif
36
- upload-sarif : true # Upload to GitHub Security tab
37
-
38
- # 5️⃣ Comment Top-N alerts per file + PR summary + file severity overview + overflow notice
39
- - name : Comment CodeQL Alerts with Top-N and File Severity Overview
40
- uses : marocchino/sticky-pull-request-comment@v2
48
+ category : " /language:python_and_javascript"
49
+ # 上传结果到GitHub安全选项卡
50
+ upload : true
51
+
52
+ # 5️⃣ 可选:添加PR注释(仅当不是fork PR时)
53
+ - name : Comment PR with CodeQL results
54
+ if : github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
55
+ uses : github/codeql-action/comment@v3
41
56
with :
42
- path : results.sarif
43
- header : " ### :shield: CodeQL Security Alerts Summary"
44
- layout : " group-by-file"
45
- format : " markdown-table"
46
- sort-severity : true # Sort alerts: Critical → High → Medium → Low
47
- highlight : " Critical,High" # Highlight most severe alerts
48
- collapse : " Medium,Low" # Collapse medium/low severity alerts
49
- max-items-per-file : 5 # Display top 5 alerts per file
50
- show-summary : true # Show total alert summary table for the PR
51
- show-file-overview : true # Show file-level Critical/High counts
52
- overflow-text : " +{remaining} more alerts in this file" # Folded notice for extra alerts
53
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
57
+ moniker : codeql-analysis
0 commit comments