Skip to content

Commit cc6c9b2

Browse files
authored
更新 Codeql.yml
1 parent 15f38cd commit cc6c9b2

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

.github/workflows/Codeql.yml

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,57 @@
1-
name: "CodeQL code Scan"
1+
name: "CodeQL Security Scan"
22

33
on:
44
pull_request:
55
types: [opened, synchronize, reopened]
6+
push:
7+
branches: [main, master]
8+
9+
permissions:
10+
security-events: write
11+
actions: read
12+
contents: read
613

714
jobs:
815
codeql:
916
name: "CodeQL Analysis"
1017
runs-on: ubuntu-latest
18+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
1119

1220
concurrency:
13-
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
21+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1422
cancel-in-progress: true
1523

1624
steps:
1725
# 1️⃣ Checkout the repository
1826
- name: Checkout repository
1927
uses: actions/checkout@v4
28+
with:
29+
# 必须深度检出以获取完整历史记录进行精确分析
30+
fetch-depth: 0
2031

2132
# 2️⃣ Initialize CodeQL
2233
- name: Initialize CodeQL
2334
uses: github/codeql-action/init@v3
2435
with:
25-
languages: ["python","javascript"] # Add more languages if needed
36+
languages: ["python","javascript"]
37+
# 如果是私有仓库或需要认证的依赖,配置这里
38+
# config-file: ./.github/codeql/codeql-config.yml
2639

2740
# 3️⃣ Auto-build the project for CodeQL
2841
- name: Autobuild
2942
uses: github/codeql-action/autobuild@v3
3043

31-
# 4️⃣ Perform CodeQL analysis and generate SARIF report
44+
# 4️⃣ Perform CodeQL analysis
3245
- name: Perform CodeQL Analysis
3346
uses: github/codeql-action/analyze@v3
3447
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
4156
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

Comments
 (0)