11name : CI
22
33on :
4+ push :
5+ branches : [main, master]
46 pull_request :
7+ branches : [main, master]
8+
9+ permissions :
10+ contents : read
11+ pull-requests : write # 用于 PR 评论(如测试覆盖率报告)
512
613jobs :
7- build :
14+ lint :
15+ name : Lint Code
816 runs-on : ubuntu-latest
917 steps :
1018 - name : Checkout code
@@ -15,18 +23,88 @@ jobs:
1523 with :
1624 version : 9
1725
18- - name : Install Node.js
26+ - name : Setup Node.js
1927 uses : actions/setup-node@v4
2028 with :
21- node-version : ' 20.x'
22- registry-url : https://registry.npmjs.org
29+ node-version : ' 20'
2330 cache : ' pnpm'
2431
2532 - name : Install dependencies
26- run : pnpm install
33+ run : pnpm install --frozen-lockfile
2734
2835 - name : Run ESLint
2936 run : pnpm run lint
3037
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
3295 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