diff --git a/.github/workflows/forge-coverage.yml b/.github/workflows/forge-coverage.yml new file mode 100644 index 00000000..ccf6de89 --- /dev/null +++ b/.github/workflows/forge-coverage.yml @@ -0,0 +1,72 @@ +name: Coverage + +on: + push: + workflow_dispatch: {} + +jobs: + run-coverage: + name: CI + runs-on: ubuntu-latest + strategy: + fail-fast: false + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Load issue number + uses: actions/github-script@v6 + id: get_issue_number + with: + script: | + const pullRequests = await github.rest.repos.listPullRequestsAssociatedWithCommit({ + commit_sha: context.sha, + owner: context.repo.owner, + repo: context.repo.repo, + }); + + if (pullRequests.data.length > 0) { + return pullRequests.data[0].number; + } else { + throw new Error('No associated pull request found.'); + } + result-encoding: string + + - name: Install dependencies + run: | + sudo apt-get install lcov + id: lcov + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + + - name: Run coverage + run: FOUNDRY_PROFILE=ci forge coverage --report lcov + env: + RPC_MAINNET: ${{ secrets.RPC_MAINNET }} + RPC_HOLESKY: ${{ secrets.RPC_HOLESKY }} + + - name: Prune coverage report + run: lcov --remove ./lcov.info -o ./lcov.info.pruned 'src/test/*' 'script/*' '*Storage.sol' --ignore-errors inconsistent + + - name: Generate reports + run: genhtml -o report ./lcov.info.pruned + + - name: Upload coverage results + uses: actions/upload-artifact@v4 + with: + name: code-coverage-report + path: report/* + + - name: View and log coverage + id: print_coverage + run: | + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + echo "comment_contents<<$EOF" >> $GITHUB_OUTPUT + echo "$(lcov --list ./lcov.info.pruned --ignore-errors inconsistent)" >> $GITHUB_OUTPUT + echo "$EOF" >> $GITHUB_OUTPUT + - name: Log Coverage Report + run: echo "${{ steps.print_coverage.outputs.comment_contents }}" \ No newline at end of file