Skip to content

Commit 61ef222

Browse files
committed
feat: add ci
1 parent c60e069 commit 61ef222

File tree

2 files changed

+177
-0
lines changed

2 files changed

+177
-0
lines changed

.github/workflows/codeql.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: CodeQL 代码安全分析
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
schedule:
9+
# 每周一 UTC 8:00(北京时间 16:00)自动扫描
10+
- cron: "0 8 * * 1"
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
analyze:
18+
name: CodeQL 分析 (${{ matrix.language }})
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 15
21+
22+
permissions:
23+
security-events: write
24+
contents: read
25+
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
language: [javascript-typescript, go]
30+
include:
31+
- language: go
32+
build-command: cd backend && go build ./...
33+
34+
steps:
35+
- name: 签出代码
36+
uses: actions/checkout@v6
37+
38+
- name: 初始化 CodeQL
39+
uses: github/codeql-action/init@v3
40+
with:
41+
languages: ${{ matrix.language }}
42+
43+
- name: 配置 Go
44+
if: matrix.language == 'go'
45+
uses: actions/setup-go@v6
46+
with:
47+
go-version-file: backend/go.mod
48+
cache-dependency-path: backend/go.sum
49+
50+
- name: 构建 Go 代码
51+
if: matrix.language == 'go'
52+
run: ${{ matrix.build-command }}
53+
54+
- name: 执行 CodeQL 分析
55+
uses: github/codeql-action/analyze@v3
56+
with:
57+
category: "/language:${{ matrix.language }}"
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: 安全扫描
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
schedule:
9+
# 每周三 UTC 8:00(北京时间 16:00)自动扫描
10+
- cron: "0 8 * * 3"
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
trivy-frontend:
18+
name: Trivy 前端依赖扫描
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 10
21+
22+
permissions:
23+
security-events: write
24+
contents: read
25+
26+
steps:
27+
- name: 签出代码
28+
uses: actions/checkout@v6
29+
30+
- name: Trivy 漏洞扫描(前端)
31+
uses: aquasecurity/trivy-action@master
32+
with:
33+
scan-type: fs
34+
scan-ref: .
35+
scanners: vuln
36+
severity: CRITICAL,HIGH
37+
format: sarif
38+
output: trivy-frontend.sarif
39+
40+
- name: 上传扫描结果到 GitHub Security
41+
uses: github/codeql-action/upload-sarif@v3
42+
if: always()
43+
with:
44+
sarif_file: trivy-frontend.sarif
45+
category: trivy-frontend
46+
47+
trivy-backend:
48+
name: Trivy 后端依赖扫描
49+
runs-on: ubuntu-latest
50+
timeout-minutes: 10
51+
52+
permissions:
53+
security-events: write
54+
contents: read
55+
56+
steps:
57+
- name: 签出代码
58+
uses: actions/checkout@v6
59+
60+
- name: Trivy 漏洞扫描(后端)
61+
uses: aquasecurity/trivy-action@master
62+
with:
63+
scan-type: fs
64+
scan-ref: backend
65+
scanners: vuln
66+
severity: CRITICAL,HIGH
67+
format: sarif
68+
output: trivy-backend.sarif
69+
70+
- name: 上传扫描结果到 GitHub Security
71+
uses: github/codeql-action/upload-sarif@v3
72+
if: always()
73+
with:
74+
sarif_file: trivy-backend.sarif
75+
category: trivy-backend
76+
77+
govulncheck:
78+
name: Go 官方漏洞检查
79+
runs-on: ubuntu-latest
80+
timeout-minutes: 10
81+
defaults:
82+
run:
83+
working-directory: backend
84+
85+
steps:
86+
- name: 签出代码
87+
uses: actions/checkout@v6
88+
89+
- name: 配置 Go
90+
uses: actions/setup-go@v6
91+
with:
92+
go-version-file: backend/go.mod
93+
cache-dependency-path: backend/go.sum
94+
95+
- name: 安装 govulncheck
96+
run: go install golang.org/x/vuln/cmd/govulncheck@latest
97+
98+
- name: 执行漏洞检查
99+
run: govulncheck ./...
100+
101+
gitleaks:
102+
name: Gitleaks 敏感信息泄露检测
103+
runs-on: ubuntu-latest
104+
timeout-minutes: 10
105+
106+
permissions:
107+
security-events: write
108+
contents: read
109+
110+
steps:
111+
- name: 签出代码
112+
uses: actions/checkout@v6
113+
with:
114+
fetch-depth: 0
115+
116+
- name: Gitleaks 扫描
117+
uses: gitleaks/gitleaks-action@v2
118+
env:
119+
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}
120+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)