-
Notifications
You must be signed in to change notification settings - Fork 91
125 lines (101 loc) · 3.89 KB
/
coverage-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: Compare Test Coverage
# This compares test coverage and throws an error if test coverage is lower than the previous run.
on:
push:
branches: [development]
pull_request:
branches: [development]
jobs:
test-coverage:
name: Compare Test Coverage
runs-on: ubuntu-22.04
permissions:
contents: read
steps:
- name: Checkout development branch
uses: actions/checkout@v3
with:
ref: development
- name: Setup Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly-d369d2486f85576eec4ca41d277391dfdae21ba7
- name: Install dependencies
run: sudo apt-get install lcov
- name: Get development branch coverage
id: coverage-development
run: |
cd ./packages/contracts
# generates lcov.info
forge coverage --report lcov
# Foundry uses relative paths but Hardhat uses absolute paths.
# Convert absolute paths to relative paths for consistency.
sed -i -e 's/\/.*solidity.//g' lcov.info
# Merge lcov files
lcov \
--rc lcov_branch_coverage=1 \
--add-tracefile lcov.info \
--output-file merged-lcov.info
# Filter out node_modules, test, and mock files
lcov \
--rc lcov_branch_coverage=1 \
--remove merged-lcov.info \
--output-file filtered-lcov.info \
"*node_modules*" \
"*test*" \
"*mock*" \
"*scripts*" \
"src/dollar/mocks/*" \
"src/dollar/utils/*" \
"test/*" \
# Generate summary
COVERAGE_DEVELOPMENT_OUTPUT=$(lcov \
--rc lcov_branch_coverage=1 \
--list filtered-lcov.info)
echo COVERAGE=$(echo "${COVERAGE_DEVELOPMENT_OUTPUT}" | tail -n 1 | cut -d % -f 1 | cut -d \| -f 2) >> $GITHUB_OUTPUT
- name: Checkout code in PR branch
uses: actions/checkout@v3
- name: Get PR branch coverage
id: coverage-pr
run: |
cd ./packages/contracts
# generates lcov.info
forge coverage --report lcov
# Foundry uses relative paths but Hardhat uses absolute paths.
# Convert absolute paths to relative paths for consistency.
sed -i -e 's/\/.*solidity.//g' lcov.info
# Merge lcov files
lcov \
--rc lcov_branch_coverage=1 \
--add-tracefile lcov.info \
--output-file merged-lcov.info
# Filter out node_modules, test, and mock files
lcov \
--rc lcov_branch_coverage=1 \
--remove merged-lcov.info \
--output-file filtered-lcov.info \
"*node_modules*" \
"*test*" \
"*mock*" \
"*scripts*" \
"src/dollar/mocks/*" \
"src/dollar/utils/*" \
"test/*" \
# Generate summary
COVERAGE_DEVELOPMENT_OUTPUT=$(lcov \
--rc lcov_branch_coverage=1 \
--list filtered-lcov.info)
echo COVERAGE=$(echo "${COVERAGE_DEVELOPMENT_OUTPUT}" | tail -n 1 | cut -d % -f 1 | cut -d \| -f 2) >> $GITHUB_OUTPUT
- name: Print coverages
run: |
echo Development branch coverage: ${{ steps.coverage-development.outputs.COVERAGE }}
echo PR branch coverage: ${{ steps.coverage-pr.outputs.COVERAGE }}
- name: Compare coverages
if: ${{ steps.coverage-development.outputs.COVERAGE > steps.coverage-pr.outputs.COVERAGE }}
run: |
echo "Error: test coverage decreased"
exit 1
- name: Upload test coverage report to coveralls.io
uses: coverallsapp/github-action@v2
with:
file: packages/contracts/filtered-lcov.info