Skip to content

Commit 5ae1fc3

Browse files
committed
fix: handle missing coverage files in CI workflows
- Check if coverage-summary.json exists before reading - Only upload coverage percentage if file was created - Handle missing artifacts gracefully in coverage workflow - Prevent CI failures when coverage data is not available
1 parent c35b2e2 commit 5ae1fc3

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

.github/workflows/ci.yml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,23 @@ jobs:
5353
- name: Update coverage badge
5454
if: matrix.node-version == '18.x' && github.ref == 'refs/heads/main' && github.event_name == 'push'
5555
run: |
56-
# Extract coverage percentage
57-
COVERAGE=$(node -e "
58-
const coverage = require('./coverage/coverage-summary.json');
59-
const pct = coverage.total.statements.pct;
60-
console.log(pct.toFixed(2));
61-
")
62-
63-
# Create a simple JSON for later use
64-
echo "{\"coverage\": \"$COVERAGE\"}" > coverage-percentage.json
56+
# Check if coverage file exists
57+
if [ -f "coverage/coverage-summary.json" ]; then
58+
# Extract coverage percentage
59+
COVERAGE=$(node -e "
60+
const coverage = require('./coverage/coverage-summary.json');
61+
const pct = coverage.total.statements.pct;
62+
console.log(pct.toFixed(2));
63+
")
64+
65+
# Create a simple JSON for later use
66+
echo "{\"coverage\": \"$COVERAGE\"}" > coverage-percentage.json
67+
else
68+
echo "Coverage file not found, skipping badge update"
69+
fi
6570
6671
- name: Upload coverage percentage
67-
if: matrix.node-version == '18.x' && github.ref == 'refs/heads/main' && github.event_name == 'push'
72+
if: matrix.node-version == '18.x' && github.ref == 'refs/heads/main' && github.event_name == 'push' && hashFiles('coverage-percentage.json') != ''
6873
uses: actions/upload-artifact@v4
6974
with:
7075
name: coverage-percentage

.github/workflows/coverage.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,22 @@ jobs:
2020

2121
- name: Download coverage artifact
2222
uses: actions/download-artifact@v4
23+
continue-on-error: true
24+
id: download
2325
with:
2426
name: coverage-percentage
2527
github-token: ${{ secrets.GITHUB_TOKEN }}
2628
run-id: ${{ github.event.workflow_run.id }}
2729

2830
- name: Update README badge
31+
if: steps.download.outcome == 'success'
2932
run: |
33+
# Check if coverage file exists
34+
if [ ! -f "coverage-percentage.json" ]; then
35+
echo "Coverage percentage file not found, skipping"
36+
exit 0
37+
fi
38+
3039
# Read coverage percentage
3140
COVERAGE=$(jq -r '.coverage' coverage-percentage.json)
3241

0 commit comments

Comments
 (0)