1
1
name : CI
2
2
3
3
on :
4
+ push :
5
+ branches : [main, master]
4
6
pull_request :
7
+ branches : [main, master]
8
+
9
+ permissions :
10
+ contents : read
11
+ pull-requests : write # 用于 PR 评论(如测试覆盖率报告)
5
12
6
13
jobs :
7
- build :
14
+ lint :
15
+ name : Lint Code
8
16
runs-on : ubuntu-latest
9
17
steps :
10
18
- name : Checkout code
@@ -15,18 +23,88 @@ jobs:
15
23
with :
16
24
version : 9
17
25
18
- - name : Install Node.js
26
+ - name : Setup Node.js
19
27
uses : actions/setup-node@v4
20
28
with :
21
- node-version : ' 20.x'
22
- registry-url : https://registry.npmjs.org
29
+ node-version : ' 20'
23
30
cache : ' pnpm'
24
31
25
32
- name : Install dependencies
26
- run : pnpm install
33
+ run : pnpm install --frozen-lockfile
27
34
28
35
- name : Run ESLint
29
36
run : pnpm run lint
30
37
31
- - name : Compile TypeScript
38
+ test :
39
+ name : Test (Node ${{ matrix.node-version }})
40
+ runs-on : ubuntu-latest
41
+ strategy :
42
+ matrix :
43
+ node-version : ['18', '20', '22']
44
+ steps :
45
+ - name : Checkout code
46
+ uses : actions/checkout@v4
47
+
48
+ - name : Install pnpm
49
+ uses : pnpm/action-setup@v4
50
+ with :
51
+ version : 9
52
+
53
+ - name : Setup Node.js ${{ matrix.node-version }}
54
+ uses : actions/setup-node@v4
55
+ with :
56
+ node-version : ${{ matrix.node-version }}
57
+ cache : ' pnpm'
58
+
59
+ - name : Install dependencies
60
+ run : pnpm install --frozen-lockfile
61
+
62
+ - name : Run tests with coverage
63
+ run : pnpm run coverage
64
+
65
+ - name : Upload coverage reports
66
+ if : matrix.node-version == '20'
67
+ uses : codecov/codecov-action@v4
68
+ with :
69
+ token : ${{ secrets.CODECOV_TOKEN }}
70
+ fail_ci_if_error : false
71
+
72
+ build :
73
+ name : Build Package
74
+ runs-on : ubuntu-latest
75
+ needs : [lint, test]
76
+ steps :
77
+ - name : Checkout code
78
+ uses : actions/checkout@v4
79
+
80
+ - name : Install pnpm
81
+ uses : pnpm/action-setup@v4
82
+ with :
83
+ version : 9
84
+
85
+ - name : Setup Node.js
86
+ uses : actions/setup-node@v4
87
+ with :
88
+ node-version : ' 20'
89
+ cache : ' pnpm'
90
+
91
+ - name : Install dependencies
92
+ run : pnpm install --frozen-lockfile
93
+
94
+ - name : Build package
32
95
run : pnpm run build
96
+
97
+ - name : Check build output
98
+ run : |
99
+ ls -la dist/
100
+ if [ ! -f "dist/index.js" ] || [ ! -f "dist/index.mjs" ] || [ ! -f "dist/index.d.ts" ]; then
101
+ echo "Build output missing required files"
102
+ exit 1
103
+ fi
104
+
105
+ - name : Upload build artifacts
106
+ uses : actions/upload-artifact@v4
107
+ with :
108
+ name : dist
109
+ path : dist/
110
+ retention-days : 7
0 commit comments