Skip to content

Commit a60bbf8

Browse files
update GitHub Actions workflow for unit testing and coverage reporting
1 parent 3b9174f commit a60bbf8

1 file changed

Lines changed: 20 additions & 51 deletions

File tree

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
name: 'Coverage Check'
1+
name: 'TS SDK - Unit Testing'
22

33
on:
44
pull_request:
55
branches:
66
- development
77
- staging
88
- main
9-
push:
10-
branches:
11-
- development
12-
- staging
13-
- main
149

1510
jobs:
1611
coverage:
@@ -21,52 +16,26 @@ jobs:
2116
checks: write
2217

2318
steps:
24-
- name: Checkout code
25-
uses: actions/checkout@v4
26-
27-
- name: Setup Node.js
28-
uses: actions/setup-node@v4
19+
- uses: actions/checkout@v4
20+
21+
- uses: ArtiomTr/jest-coverage-report-action@v2
22+
id: coverage
2923
with:
30-
node-version: '18'
31-
cache: 'npm'
32-
33-
- name: Install dependencies
34-
run: npm ci
35-
36-
- name: Run unit tests with coverage
37-
run: npm test -- --coverage --testMatch="**/test/unit/**/*.spec.ts" --coverageReporters=json-summary --coverageReporters=text --coverageReporters=lcov
38-
39-
- name: Jest Coverage Report (PR Comment)
40-
if: github.event_name == 'pull_request'
41-
uses: artiomtr/jest-coverage-report-action@v2
42-
with:
43-
github-token: ${{ secrets.GITHUB_TOKEN }}
44-
coverage-file: ./reports/contentstack-delivery/coverage/coverage-summary.json
45-
base-coverage-file: ./reports/contentstack-delivery/coverage/coverage-summary.json
24+
test-script: npm test -- --coverage --testMatch="**/test/unit/**/*.spec.ts"
4625
threshold: 95
47-
working-directory: ./
48-
skip-step: all
49-
50-
- name: Verify coverage threshold
51-
run: |
52-
COVERAGE=$(node -pe "
53-
const c = JSON.parse(require('fs').readFileSync('reports/contentstack-delivery/coverage/coverage-summary.json')).total;
54-
const threshold = 95;
55-
const metrics = ['statements', 'branches', 'functions', 'lines'];
56-
const failed = metrics.filter(m => c[m].pct < threshold);
57-
if (failed.length) {
58-
console.log('❌ Coverage below 95%: ' + failed.join(', '));
59-
process.exit(1);
60-
}
61-
console.log('✅ All coverage metrics meet the 95% threshold');
62-
")
63-
64-
- name: Upload coverage reports
26+
output: report-markdown
27+
coverage-file: reports/contentstack-delivery/coverage/coverage-summary.json
28+
29+
- uses: marocchino/sticky-pull-request-comment@v2
6530
if: always()
66-
uses: actions/upload-artifact@v4
6731
with:
68-
name: coverage-report
69-
path: |
70-
reports/contentstack-delivery/coverage
71-
retention-days: 30
72-
32+
message: ${{ steps.coverage.outputs.report }}
33+
34+
- name: Test Report
35+
uses: dorny/test-reporter@v1
36+
if: success() || failure()
37+
with:
38+
name: Unit Tests
39+
path: /reports/contentstack-delivery/html
40+
reporter: jest-html-reporters
41+
fail-on-error: true

0 commit comments

Comments
 (0)