-
-
Notifications
You must be signed in to change notification settings - Fork 331
103 lines (87 loc) · 2.95 KB
/
Copy pathci.yaml
File metadata and controls
103 lines (87 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Check for project
description: Check for type errors and linting errors in the project.
on:
pull_request:
branches:
- main
workflow_dispatch:
permissions:
contents: read
jobs:
ci:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
package_json_file: "package.json"
run_install: false
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: "package.json"
cache: "pnpm"
cache-dependency-path: "pnpm-lock.yaml"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run type check
run: pnpm run check
- name: Run tests
run: pnpm run test --reporter=dot
timeout-minutes: 10
coverage:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
pull-requests: write
statuses: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
package_json_file: "package.json"
run_install: false
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: "package.json"
cache: "pnpm"
cache-dependency-path: "pnpm-lock.yaml"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run coverage check
run: pnpm run test:coverage --coverage.reporter=json-summary
timeout-minutes: 10
- name: Update Coverage Status
if: always()
uses: actions/github-script@v7
with:
script: |
// 1. read coverage summary
const fs = require('fs');
const summaryPath = './coverage/coverage-summary.json';
if (!fs.existsSync(summaryPath)) {
console.log('No coverage summary found.');
return;
}
const summary = JSON.parse(fs.readFileSync(summaryPath, 'utf8'));
// 2. Total coverage % calc
const total = summary.total.lines.pct;
const color = total >= 20 ? 'success' : 'failure'; // Green if >= 20%
const description = `Lines: ${total}% | Statements: ${summary.total.statements.pct}%`;
// 3. Github PR checklist update
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: color, // Build is success
context: 'Vitest Coverage', // List name
description: description, // e.g. "Lines: 85%"
target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}` // Click to see details
});