Skip to content

Commit

Permalink
chore: Merge foundry and hardhat coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bingen committed Jan 31, 2024
1 parent e99cefa commit 376855d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 49 deletions.
115 changes: 67 additions & 48 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,47 +48,6 @@ jobs:
forge test -vvv
id: test

coverage-foundry:
name: Foundry coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge coverage
run: |
forge coverage --report lcov
id: coverage

- name: Install lcov
run: sudo apt-get -y install lcov

- name: Filter out tests from coverage
run: |
lcov --remove lcov.info -o lcov.info 'src/test/*'
id: coverage_filter

- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
base-path: ./contracts/
# Potential improvement to include merge with hardhat tests: https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/e91c3100c29d2913d175df4b3d1790d6a057d36e/solidity/coverage.sh
path-to-lcov: ./contracts/lcov.info
debug: true

console-logs:
name: Check we didn’t forget to remove console imports
runs-on: ubuntu-latest
Expand Down Expand Up @@ -121,36 +80,96 @@ jobs:
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Test contracts
run: yarn test

coverage-hardhat:
name: Hardhat coverage
coverage:
name: Coverage
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.labels.*.name, 'coverage') }}
continue-on-error: true

steps:
- uses: actions/checkout@v4
- name: Git checkout
uses: actions/checkout@v4
with:
submodules: recursive

# Foundry
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge coverage
run: |
forge coverage --report lcov --report-file lcov_foundry.info
id: coverage

- name: Install lcov
run: sudo apt-get -y install lcov

#- name: Filter out tests from coverage
# run: |
# lcov --remove lcov_foundry.info -o lcov_foundry.info 'src/test/*'
# id: coverage_filter

# Hardhat
- uses: actions/setup-node@v3
with:
node-version: 16
cache: yarn
cache-dependency-path: "./contracts/yarn.lock"
env:
# Workaround for https://github.com/actions/setup-node/issues/317
FORCE_COLOR: 0

- run: yarn install --immutable
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Test contract coverage
- name: harhdat coverage
run: yarn coverage
continue-on-error: true
env:
NODE_OPTIONS: --max-old-space-size=4096

# Merge
- name: Merge coverage reports
id: coverage_merge
run: |
lcov \
--rc lcov_branch_coverage=1 \
--add-tracefile lcov_foundry.info \
--add-tracefile coverage/lcov.info \
--output-file lcov_merged.info
# Filter
- name: Filter out tests from coverage
run: |
lcov --remove lcov_merged.info -o lcov_merged.info \
'src/test/*' \
'src/TestContracts/*' \
'src/OldTestContracts/*' \
'src/Dependencies/*' \
'src/Interfaces/*'
id: coverage_filter

# Send to coveralls
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./packages/contracts/coverage/lcov.info
base-path: ./contracts/
path-to-lcov: ./contracts/lcov_merged.info
debug: true

3 changes: 2 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"lib": "lib"
},
"scripts": {
"test": "hardhat test"
"test": "hardhat test",
"coverage": "hardhat coverage"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 376855d

Please sign in to comment.