Skip to content

Commit 705489c

Browse files
committed
ci: 添加示例代码自动测试工作流
1 parent ac3d713 commit 705489c

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Test Examples
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- 'examples/**'
8+
- '.github/workflows/test-examples.yml'
9+
pull_request:
10+
branches: [ main ]
11+
paths:
12+
- 'examples/**'
13+
- '.github/workflows/test-examples.yml'
14+
15+
jobs:
16+
test-examples:
17+
runs-on: ubuntu-latest
18+
19+
services:
20+
# 启动API服务器作为测试环境
21+
api-server:
22+
image: golang:1.21
23+
ports:
24+
- 8080:8080
25+
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Set up Go
30+
uses: actions/setup-go@v5
31+
with:
32+
go-version: '1.21'
33+
cache: true
34+
35+
# 启动API服务器
36+
- name: Start API Server
37+
run: |
38+
go build -o cxsecurity ./main.go
39+
./cxsecurity api &
40+
# 等待服务器启动
41+
sleep 5
42+
env:
43+
API_TOKEN: test-token-123
44+
45+
# 测试基础搜索示例
46+
- name: Test Basic Search Example
47+
run: |
48+
cd examples/01-basic-search
49+
sed -i 's/your-api-token-here/test-token-123/g' main.go
50+
go run main.go
51+
env:
52+
API_TOKEN: test-token-123
53+
54+
# 测试分页搜索示例
55+
- name: Test Pagination Example
56+
run: |
57+
cd examples/02-pagination
58+
sed -i 's/your-api-token-here/test-token-123/g' main.go
59+
go run main.go
60+
env:
61+
API_TOKEN: test-token-123
62+
63+
# 测试高级搜索示例
64+
- name: Test Advanced Search Example
65+
run: |
66+
cd examples/03-advanced-search
67+
sed -i 's/your-api-token-here/test-token-123/g' main.go
68+
go run main.go
69+
env:
70+
API_TOKEN: test-token-123
71+
72+
# 测试漏洞详情示例
73+
- name: Test Vulnerability Detail Example
74+
run: |
75+
cd examples/04-vulnerability-detail
76+
sed -i 's/your-api-token-here/test-token-123/g' main.go
77+
go run main.go
78+
env:
79+
API_TOKEN: test-token-123
80+
81+
# 测试CVE详情示例
82+
- name: Test CVE Detail Example
83+
run: |
84+
cd examples/05-cve-detail
85+
sed -i 's/your-api-token-here/test-token-123/g' main.go
86+
go run main.go
87+
env:
88+
API_TOKEN: test-token-123
89+
90+
# 测试作者信息示例
91+
- name: Test Author Info Example
92+
run: |
93+
cd examples/06-author-info
94+
sed -i 's/your-api-token-here/test-token-123/g' main.go
95+
go run main.go
96+
env:
97+
API_TOKEN: test-token-123

0 commit comments

Comments
 (0)