Skip to content

Commit 7ad3687

Browse files
committed
updated woflwo coverage script usage
1 parent b8e4e88 commit 7ad3687

File tree

1 file changed

+10
-161
lines changed

1 file changed

+10
-161
lines changed

.github/workflows/coverage.yml

Lines changed: 10 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -23,176 +23,25 @@ jobs:
2323

2424
- name: Print environment versions
2525
run: |
26-
echo "=================================================="
27-
echo "🔍 ENVIRONMENT VERSIONS (for debugging coverage differences)"
28-
echo "=================================================="
29-
echo ""
30-
echo "Node.js version:"
31-
node -v
32-
echo ""
33-
echo "NPM version:"
34-
npm -v
35-
echo ""
36-
echo "Hardhat version:"
26+
echo "Node.js: $(node -v)"
27+
echo "NPM: $(npm -v)"
3728
npx hardhat --version
38-
echo ""
39-
echo "Solidity compiler version:"
40-
npx solcjs --version 2>/dev/null || echo " (will be downloaded by Hardhat if needed)"
41-
echo ""
42-
echo "Key package versions:"
43-
npm ls hardhat solidity-coverage @nomicfoundation/hardhat-toolbox --depth=0
44-
echo ""
45-
echo "=================================================="
29+
npx solcjs --version 2>/dev/null || echo "(will be downloaded by Hardhat if needed)"
4630
4731
- name: Setup environment variables
4832
run: |
49-
if [ ! -f .env.example ]; then
50-
echo "❌ ERROR: .env.example file is missing!"
51-
echo "This file must exist with FORK_BLOCK_NUMBER_* variables for deterministic coverage."
52-
exit 1
53-
fi
5433
cp .env.example .env
55-
echo "✅ Copied .env.example to .env"
56-
echo "📋 Fork block numbers configured:"
57-
grep "FORK_BLOCK_NUMBER" .env | head -10 || echo " ⚠️ No FORK_BLOCK_NUMBER variables found in .env.example"
34+
echo "Fork block numbers configured:"
35+
grep "FORK_BLOCK_NUMBER" .env || echo " (none found)"
5836
59-
- name: Get baseline from main branch
37+
- name: Run coverage and verify
6038
run: |
61-
# Fetch main branch
62-
git fetch origin main
63-
# Get baseline from main (for comparison - must not decrease)
64-
git show origin/main:coverage-baseline.json > baseline-from-main.json 2>/dev/null || echo '{"lines":"0","functions":"0","branches":"0","statements":"0"}' > baseline-from-main.json
65-
echo "📊 Baseline from main branch:"
66-
cat baseline-from-main.json
67-
68-
- name: Get baseline from PR
69-
run: |
70-
# Get baseline from current PR branch (what developer committed)
71-
if [ -f coverage-baseline.json ]; then
72-
# Validate JSON format
73-
if jq empty coverage-baseline.json 2>/dev/null; then
74-
cp coverage-baseline.json baseline-from-pr.json
75-
echo "📊 Baseline from PR (committed by developer):"
76-
cat baseline-from-pr.json
77-
else
78-
echo "❌ ERROR: coverage-baseline.json is not valid JSON!"
79-
echo "Please run: npm run coverage:update-baseline"
80-
exit 1
81-
fi
82-
else
83-
echo "❌ ERROR: No coverage-baseline.json found in PR!"
84-
echo ""
85-
echo "You must run coverage locally and commit the baseline file."
86-
echo ""
87-
echo "📝 To fix: Run these commands locally and commit the result:"
88-
echo " npm run coverage"
89-
echo " npm run coverage:update-baseline"
90-
echo " git add coverage-baseline.json"
91-
echo " git commit -m 'chore: update coverage baseline'"
92-
echo ""
93-
exit 1
94-
fi
95-
96-
- name: Run coverage
97-
id: run_coverage
98-
timeout-minutes: 15
99-
run: |
100-
set -e # Exit immediately if coverage fails
39+
set -e
40+
echo "Running coverage..."
10141
npm run coverage
102-
echo "✅ Coverage completed successfully"
103-
104-
- name: Validate coverage
105-
run: |
106-
echo "=================================================="
107-
echo "🔍 COVERAGE VALIDATION"
108-
echo "=================================================="
109-
110-
# Diagnostic: Show environment setup
111-
echo ""
112-
echo "📋 Environment Diagnostics:"
113-
echo " Node version: $(node --version)"
114-
echo " NPM version: $(npm --version)"
115-
if [ -f .env ]; then
116-
echo " .env file: EXISTS"
117-
echo " Fork block numbers in .env:"
118-
grep "FORK_BLOCK_NUMBER" .env | head -5 || echo " (none found)"
119-
else
120-
echo " .env file: MISSING"
121-
fi
122-
if [ -f .env.example ]; then
123-
echo " .env.example file: EXISTS"
124-
echo " Fork block numbers in .env.example:"
125-
grep "FORK_BLOCK_NUMBER" .env.example | head -5 || echo " (none found)"
126-
else
127-
echo " .env.example file: MISSING ⚠️"
128-
fi
129-
echo ""
130-
131-
# Parse CI-generated coverage using dedicated script
132-
CI_LINES=$(npx ts-node --files scripts/get-coverage-percentage.ts)
133-
134-
# Get baselines
135-
PR_LINES=$(jq -r .lines baseline-from-pr.json)
136-
MAIN_LINES=$(jq -r .lines baseline-from-main.json)
137-
138-
echo ""
139-
echo "📊 Coverage Results:"
140-
echo " CI (actual): $CI_LINES%"
141-
echo " PR baseline: $PR_LINES%"
142-
echo " Main baseline: $MAIN_LINES%"
143-
echo ""
144-
145-
# Check 1: CI must match PR baseline (developer ran coverage correctly)
146-
echo "Check 1: Did developer run coverage locally?"
147-
if [ "$CI_LINES" = "$PR_LINES" ]; then
148-
echo " ✅ PASS - CI coverage matches PR baseline ($CI_LINES% == $PR_LINES%)"
149-
else
150-
echo " ❌ FAIL - CI coverage doesn't match PR baseline!"
151-
echo ""
152-
echo " Expected: $PR_LINES% (from your committed coverage-baseline.json)"
153-
echo " Actual: $CI_LINES% (from fresh CI coverage run)"
154-
echo " Difference: $(awk "BEGIN {printf \"%.2f\", $PR_LINES - $CI_LINES}")%"
155-
echo ""
156-
echo "💡 This means either:"
157-
echo " 1. You forgot to run 'npm run coverage:update-baseline' locally"
158-
echo " 2. You modified coverage-baseline.json manually (cheating)"
159-
echo " 3. Your local coverage differs from CI (check .env setup)"
160-
echo ""
161-
echo "📝 To fix: Run these commands locally and commit the result:"
162-
echo " npm run coverage"
163-
echo " npm run coverage:update-baseline"
164-
echo " git add coverage-baseline.json"
165-
echo " git commit -m 'chore: update coverage baseline'"
166-
echo ""
167-
exit 1
168-
fi
169-
170-
echo ""
171-
172-
# Check 2: CI must be >= main baseline (coverage didn't decrease)
173-
echo "Check 2: Did coverage decrease?"
174-
if awk "BEGIN {exit !($CI_LINES >= $MAIN_LINES)}"; then
175-
if awk "BEGIN {exit !($CI_LINES > $MAIN_LINES)}"; then
176-
echo " ✅ PASS - Coverage improved! ($MAIN_LINES% → $CI_LINES%)"
177-
else
178-
echo " ✅ PASS - Coverage maintained ($CI_LINES%)"
179-
fi
180-
else
181-
echo " ❌ FAIL - Coverage decreased!"
182-
echo ""
183-
echo " Main baseline: $MAIN_LINES%"
184-
echo " Your PR: $CI_LINES%"
185-
echo " Decrease: $(awk "BEGIN {print $MAIN_LINES - $CI_LINES}")%"
186-
echo ""
187-
echo "💡 Please add tests to maintain or improve coverage."
188-
echo ""
189-
exit 1
190-
fi
19142
192-
echo ""
193-
echo "=================================================="
194-
echo "✅ ALL CHECKS PASSED"
195-
echo "=================================================="
43+
echo "Verifying coverage against baseline..."
44+
npx ts-node --files scripts/verify-coverage.ts
19645
19746
- name: Upload coverage report (optional)
19847
if: always()

0 commit comments

Comments
 (0)