Skip to content

Commit 0fb5d15

Browse files
committed
chore(config): add cobertura coverage
1 parent 9517209 commit 0fb5d15

File tree

3 files changed

+69
-9
lines changed

3 files changed

+69
-9
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: 🧪 PR Coverage Comments
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, edited]
6+
branches: [main]
7+
jobs:
8+
coverage-comment-raw:
9+
name: 📊 Jest PR Coverage Table (Raw)
10+
runs-on: ubuntu-latest
11+
permissions:
12+
pull-requests: write
13+
contents: read
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Install dependencies
17+
run: npm ci
18+
19+
- name: Run coverage and extract table
20+
run: |
21+
npm run test:coverage > full-coverage.txt || true
22+
sed -n '/^-------------------------|---------|----------|---------|---------|/,$p' full-coverage.txt | \
23+
sed '/^=============================== Coverage summary ===============================/,$d' | \
24+
# Remove first and last border lines:
25+
sed '1d;$d' > coverage-table.txt
26+
27+
- name: Comment test results
28+
uses: marocchino/sticky-pull-request-comment@v2
29+
with:
30+
header: "jest-coverage-raw"
31+
recreate: true
32+
path: coverage-table.txt
33+
34+
coverage-comment:
35+
name: 📝 PR Coverage Summary
36+
runs-on: ubuntu-latest
37+
permissions:
38+
pull-requests: write
39+
contents: read
40+
steps:
41+
- uses: actions/checkout@v4
42+
- uses: actions/setup-node@v4
43+
with:
44+
node-version: 22
45+
cache: 'npm'
46+
- name: Install dependencies
47+
run: npm ci
48+
- name: Run coverage
49+
run: npm run test:coverage
50+
- name: Comment coverage summary
51+
uses: irongut/CodeCoverageSummary@v1.3.0
52+
with:
53+
filename: reports/coverage/cobertura-coverage.xml
54+
badge: true
55+
format: markdown
56+
output: both
57+
indicators: true
58+
- name: Post coverage comment
59+
uses: marocchino/sticky-pull-request-comment@v2
60+
with:
61+
header: "jest-coverage-summary"
62+
recreate: true
63+
path: code-coverage-results.md
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 🧪 Test Coverage
1+
name: 📤 Upload Coverage to Codecov
22

33
on:
44
push:
@@ -9,18 +9,15 @@ on:
99
workflow_dispatch:
1010

1111
jobs:
12-
coverage:
12+
coverage-upload-codecov:
13+
if: >
14+
github.event_name != 'pull_request' ||
15+
(!contains(github.event.pull_request.title, 'WIP') && !contains(github.event.pull_request.title, '!COV'))
1316
runs-on: ubuntu-latest
1417
steps:
1518
- name: ⬇️ Checkout repository
1619
uses: actions/checkout@v4
1720

18-
- name: ⏭ Skip tests & coverage
19-
if: github.event_name == 'pull_request' && (contains(github.event.pull_request.title, 'WIP') || contains(github.event.pull_request.title, '!COV'))
20-
run: |
21-
echo "Skipping tests and coverage upload due to PR title containing 'WIP' or '!COV'."
22-
exit 0
23-
2421
- name: 🟢 Setup Node.js
2522
uses: actions/setup-node@v4
2623
with:

jest.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
resetModules: true,
88
collectCoverageFrom: ['src/**/*.ts'],
99
coverageDirectory: 'reports/coverage',
10-
coverageReporters: ['text', 'text-summary', 'lcov'],
10+
coverageReporters: ['text', 'text-summary', 'lcov', 'cobertura'],
1111
reporters: [
1212
'default',
1313
[

0 commit comments

Comments
 (0)