@@ -47,12 +47,46 @@ jobs:
4747 - name : Check forge snapshots
4848 run : forge snapshot --check --match-contract Gas
4949
50- - name : Check code coverage
50+ coverage :
51+ runs-on : ubuntu-latest
52+ steps :
53+ - uses : actions/checkout@v3
54+
55+ - name : Install Foundry
56+ uses : foundry-rs/foundry-toolchain@v1
57+
58+ - name : Run coverage
59+ run : forge coverage --report summary --report lcov
60+
61+ # To ignore coverage for certain directories modify the paths in this step as needed. The
62+ # below default ignores coverage results for the test and script directories. Alternatively,
63+ # to include coverage in all directories, comment out this step. Note that because this
64+ # filtering applies to the lcov file, the summary table generated in the previous step will
65+ # still include all files and directories.
66+ # The `--rc lcov_branch_coverage=1` part keeps branch info in the filtered report, since lcov
67+ # defaults to removing branch info.
68+ - name : Filter directories
5169 run : |
52- forge coverage --report lcov
53- id : coverage
70+ sudo apt update && sudo apt install -y lcov
71+ lcov --remove lcov.info 'test/*' 'script/*' --output-file lcov.info --rc lcov_branch_coverage=1
72+ # This step posts a detailed coverage report as a comment and deletes previous comments on
73+ # each push. The below step is used to fail coverage if the specified coverage threshold is
74+ # not met. The below step can post a comment (when it's `github-token` is specified) but it's
75+ # not as useful, and this action cannot fail CI based on a minimum coverage threshold, which
76+ # is why we use both in this way.
77+ - name : Post coverage report
78+ if : github.event_name == 'pull_request' # This action fails when ran outside of a pull request.
79+ 80+ with :
81+ delete-old-comments : true
82+ lcov-file : ./lcov.info
83+ github-token : ${{ secrets.GITHUB_TOKEN }} # Adds a coverage summary comment to the PR.
5484
55- - uses : codecov/codecov-action@v2
85+ - name : Verify minimum coverage
86+ uses : zgosalvez/github-actions-report-lcov@v2
87+ with :
88+ coverage-files : ./lcov.info
89+ minimum-coverage : 100 # Set coverage threshold.
5690
5791 slither-analyze :
5892 runs-on : ubuntu-latest
0 commit comments