Skip to content

Commit 7a74c2a

Browse files
committed
Add GitHub Actions CI workflow
1 parent a62092a commit 7a74c2a

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master, develop ]
6+
pull_request:
7+
branches: [ master, develop ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 'lts/*'
21+
cache: 'npm'
22+
23+
- name: Install dependencies
24+
run: npm ci
25+
26+
- name: Run linter
27+
run: npm run lint
28+
29+
- name: Run tests
30+
run: npm test
31+
32+
coverage:
33+
runs-on: ubuntu-latest
34+
if: github.event_name == 'push'
35+
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v4
39+
40+
- name: Setup Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: 'lts/*'
44+
cache: 'npm'
45+
46+
- name: Install dependencies
47+
run: npm ci
48+
49+
- name: Run tests with coverage
50+
run: npm run test:coverage
51+
52+
- name: Read coverage summary
53+
id: coverage
54+
run: |
55+
echo "summary=$(cat coverage/coverage-summary.json)" >> $GITHUB_OUTPUT
56+
57+
- name: Generate coverage badge
58+
uses: emibcn/badge-action@v2.0.3
59+
with:
60+
label: 'coverage'
61+
status: ${{ fromJson(steps.coverage.outputs.summary).total.lines.pct }}%
62+
color: ${{ fromJson(steps.coverage.outputs.summary).total.lines.pct > 80 && 'brightgreen' || fromJson(steps.coverage.outputs.summary).total.lines.pct > 60 && 'yellow' || 'red' }}
63+
path: badges/coverage.svg
64+
style: flat
65+
66+
- name: Commit coverage badge
67+
run: |
68+
git config --local user.email "action@github.com"
69+
git config --local user.name "GitHub Action"
70+
mkdir -p badges
71+
git add badges/coverage.svg
72+
git diff --staged --quiet || git commit -m "Update coverage badge"
73+
git push
74+
75+
- name: Upload coverage reports
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: coverage-report
79+
path: coverage/

0 commit comments

Comments
 (0)