Skip to content

Commit 35858f8

Browse files
authored
Upgrade Codeql.yml
1 parent cc6c9b2 commit 35858f8

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

.github/workflows/Codeql.yml

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
name: "CodeQL Security Scan"
1+
name: "CodeQL Python Security Scan (Top-N + PR Comment)"
22

33
on:
44
pull_request:
5+
branches: [ main, master ]
56
types: [opened, synchronize, reopened]
67
push:
7-
branches: [main, master]
8+
branches: [ main, master ]
89

910
permissions:
10-
security-events: write
11-
actions: read
1211
contents: read
12+
actions: read
13+
security-events: write
1314

1415
jobs:
15-
codeql:
16-
name: "CodeQL Analysis"
16+
codeql-analysis:
17+
name: "CodeQL Analysis (Python)"
1718
runs-on: ubuntu-latest
18-
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
19-
20-
concurrency:
21-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
22-
cancel-in-progress: true
19+
if: >
20+
github.event_name == 'push' ||
21+
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
2322
2423
steps:
25-
# 1️⃣ Checkout the repository
26-
- name: Checkout repository
27-
uses: actions/checkout@v4
28-
with:
29-
# 必须深度检出以获取完整历史记录进行精确分析
30-
fetch-depth: 0
31-
32-
# 2️⃣ Initialize CodeQL
33-
- name: Initialize CodeQL
34-
uses: github/codeql-action/init@v3
35-
with:
36-
languages: ["python","javascript"]
37-
# 如果是私有仓库或需要认证的依赖,配置这里
38-
# config-file: ./.github/codeql/codeql-config.yml
39-
40-
# 3️⃣ Auto-build the project for CodeQL
41-
- name: Autobuild
42-
uses: github/codeql-action/autobuild@v3
43-
44-
# 4️⃣ Perform CodeQL analysis
45-
- name: Perform CodeQL Analysis
46-
uses: github/codeql-action/analyze@v3
47-
with:
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
56-
with:
57-
moniker: codeql-analysis
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
29+
- name: Initialize CodeQL
30+
uses: github/codeql-action/init@v3
31+
with:
32+
languages: python
33+
34+
- name: Autobuild
35+
uses: github/codeql-action/autobuild@v3
36+
37+
- name: Perform CodeQL Analysis
38+
uses: github/codeql-action/analyze@v3
39+
with:
40+
upload-sarif: true
41+
42+
- name: Comment CodeQL Alerts on PR
43+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
44+
uses: marocchino/sticky-pull-request-comment@v2
45+
with:
46+
path: results.sarif
47+
header: "### :shield: CodeQL Python Security Alerts Summary"
48+
layout: "group-by-file"
49+
format: "markdown-table"
50+
sort-severity: true
51+
highlight: "Critical,High"
52+
collapse: "Medium,Low"
53+
max-items-per-file: 5
54+
show-summary: true
55+
show-file-overview: true
56+
overflow-text: "+{remaining} more alerts in this file"
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)