Skip to content

Commit 1bb20de

Browse files
committed
ci: enhance GitHub Actions workflows
- consolidate CI/CD configuration into modular workflow files - add separate workflows for format checking, unit testing, documentation, and benchmarking - implement conditional execution logic for different GitHub events - improve test matrix and version compatibility checks - add artifact uploads for documentation and benchmark results
1 parent 9093519 commit 1bb20de

File tree

5 files changed

+219
-9
lines changed

5 files changed

+219
-9
lines changed

.github/workflows/benchmark.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Performance Benchmark
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_run:
9+
workflows: ["Unit Tests"]
10+
types:
11+
- completed
12+
workflow_dispatch:
13+
14+
jobs:
15+
benchmark:
16+
name: Run Benchmarks
17+
# 依赖 unit test 成功,或手动触发
18+
if: |
19+
github.event_name == 'workflow_dispatch' ||
20+
github.event_name == 'push' ||
21+
github.event_name == 'pull_request' ||
22+
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
- name: Setup Zig
29+
uses: goto-bus-stop/setup-zig@v2
30+
with:
31+
version: 0.15.1
32+
33+
- name: Build benchmark
34+
run: zig build bench -Doptimize=ReleaseFast
35+
36+
- name: Run benchmark
37+
run: zig-out/bin/msgpack-bench > benchmark-results.txt
38+
39+
- name: Upload benchmark results
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: benchmark-results-${{ github.sha }}
43+
path: benchmark-results.txt
44+
retention-days: 7
45+

.github/workflows/ci.yml

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,109 @@ name: CI
33
on:
44
push:
55
branches:
6-
- "*"
6+
- main
7+
pull_request:
78
schedule:
89
- cron: "0 2 * * *"
910
workflow_dispatch:
1011

1112
jobs:
12-
build:
13+
# Job 1: 格式检查
14+
format-check:
15+
name: Format Check
16+
runs-on: ubuntu-latest
17+
# 在 PR 和 push 到 main 时执行,但不在定时任务时执行
18+
if: github.event_name != 'schedule'
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Zig
24+
uses: goto-bus-stop/setup-zig@v2
25+
with:
26+
version: 0.15.1
27+
28+
- name: Check code formatting
29+
run: zig fmt --check .
30+
31+
# Job 2: 单元测试
32+
unit-test:
33+
name: Unit Test
34+
needs: format-check
35+
# 跳过 format-check 的失败,在定时任务时继续执行
36+
if: always() && (needs.format-check.result == 'success' || github.event_name == 'schedule')
1337
strategy:
1438
matrix:
1539
os: [ubuntu-latest]
16-
version: [0.14.1, 0.15.1, master]
40+
# 定时任务只测试 master 版本,其他情况测试所有版本
41+
version: ${{ github.event_name == 'schedule' && fromJSON('["master"]') || fromJSON('["0.14.1", "0.15.1", "master"]') }}
1742
fail-fast: false
1843
runs-on: ${{ matrix.os }}
1944
steps:
45+
- name: Checkout code
46+
uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 0
49+
2050
- name: Setup Zig
2151
uses: goto-bus-stop/setup-zig@v2
2252
with:
23-
version: ${{ matrix.version }}
24-
- uses: actions/checkout@v4
25-
with:
26-
fetch-depth: 0
27-
- name: Build and test with Zig
53+
version: ${{ matrix.version }}
54+
55+
- name: Run unit tests
2856
run: zig build test --summary all
57+
58+
# Job 3: 文档生成
59+
docs:
60+
name: Generate Documentation
61+
needs: unit-test
62+
# 只在 push 到 main 时执行
63+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
64+
runs-on: ubuntu-latest
65+
steps:
66+
- name: Checkout code
67+
uses: actions/checkout@v4
68+
69+
- name: Setup Zig
70+
uses: goto-bus-stop/setup-zig@v2
71+
with:
72+
version: 0.15.1
73+
74+
- name: Generate docs
75+
run: zig build docs
76+
77+
- name: Upload documentation
78+
uses: actions/upload-artifact@v4
79+
with:
80+
name: documentation
81+
path: zig-out/docs/
82+
retention-days: 90
83+
84+
# Job 4: 基准测试
85+
benchmark:
86+
name: Benchmark
87+
needs: unit-test
88+
# 在 PR 和 push 到 main 时执行,但不在定时任务时执行
89+
if: github.event_name != 'schedule'
90+
runs-on: ubuntu-latest
91+
steps:
92+
- name: Checkout code
93+
uses: actions/checkout@v4
94+
95+
- name: Setup Zig
96+
uses: goto-bus-stop/setup-zig@v2
97+
with:
98+
version: 0.15.1
99+
100+
- name: Build benchmark
101+
run: zig build bench -Doptimize=ReleaseFast
102+
103+
- name: Run benchmark
104+
run: zig-out/bin/msgpack-bench > benchmark-results.txt
105+
106+
- name: Upload benchmark results
107+
uses: actions/upload-artifact@v4
108+
with:
109+
name: benchmark-results-${{ github.sha }}
110+
path: benchmark-results.txt
111+
retention-days: 7

.github/workflows/deploy_docs.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
name: DeployDocs
1+
name: Documentation
22

33
on:
44
push:
55
branches: [main]
6+
workflow_run:
7+
workflows: ["Unit Tests"]
8+
types:
9+
- completed
10+
branches:
11+
- main
612

713
# Allows you to run this workflow manually from the Actions tab
814
workflow_dispatch:
@@ -30,6 +36,11 @@ jobs:
3036
# Build job
3137
generate_docs:
3238
runs-on: ubuntu-latest
39+
# 只在 push 到 main 或 unit test 成功后执行
40+
if: |
41+
github.event_name == 'workflow_dispatch' ||
42+
github.event_name == 'push' ||
43+
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
3344
steps:
3445
- name: Checkout
3546
uses: actions/checkout@v3

.github/workflows/format-check.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Code Format Check
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
format:
11+
name: Check Code Formatting
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Zig
18+
uses: goto-bus-stop/setup-zig@v2
19+
with:
20+
version: 0.15.1
21+
22+
- name: Check code formatting
23+
run: zig fmt --check .
24+

.github/workflows/test.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
schedule:
9+
# 每天凌晨 2 点执行
10+
- cron: "0 2 * * *"
11+
workflow_dispatch:
12+
workflow_run:
13+
workflows: ["Code Format Check"]
14+
types:
15+
- completed
16+
17+
jobs:
18+
test:
19+
name: Unit Test
20+
# 依赖 format check,但定时任务或手动触发时跳过
21+
if: |
22+
github.event_name == 'schedule' ||
23+
github.event_name == 'workflow_dispatch' ||
24+
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') ||
25+
github.event_name == 'push' ||
26+
github.event_name == 'pull_request'
27+
strategy:
28+
matrix:
29+
os: [ubuntu-latest]
30+
# 定时任务只测试 master 版本,其他情况测试所有版本
31+
version: ${{ github.event_name == 'schedule' && fromJSON('["master"]') || fromJSON('["0.14.1", "0.15.1", "master"]') }}
32+
fail-fast: false
33+
runs-on: ${{ matrix.os }}
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v4
37+
with:
38+
fetch-depth: 0
39+
40+
- name: Setup Zig
41+
uses: goto-bus-stop/setup-zig@v2
42+
with:
43+
version: ${{ matrix.version }}
44+
45+
- name: Run unit tests
46+
run: zig build test --summary all
47+

0 commit comments

Comments
 (0)