Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] add reusable forge code coverage workflow #11

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/reusable-forge-code-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Reusable workflow to run code coverage on Forge

on:
workflow_call:
inputs:
exclude_paths:
description: 'A comma-separated list of paths to exclude from the coverage report'
required: true
type: string
branch_coverage:
description: 'Whether to enable branch coverage'
type: boolean
required: false
default: true

# Permission can be added at job level or workflow level
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
code-coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2

- name: Run install
uses: borales/actions-yarn@v4
with:
cmd: install

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@8f1998e9878d786675189ef566a2e4bf24869773 # v1.2.0

- name: Install lcov
run: |
sudo apt-get update
sudo apt-get install lcov

- name: Print out paths
run: |
echo "[INFO] Excluded paths: ${{ inputs.exclude_paths }}"

- name: Transalte branch_coverage from string into int
id: branch_coverage_int
run: |
if [ "${{ inputs.branch_coverage }}" = "true" ]; then
echo "[INFO] Branch coverage is enabled"
echo "branch_coverage=1" >> $GITHUB_OUTPUT
else
echo "[INFO] Branch coverage is disabled"
echo "branch_coverage=0" >> $GITHUB_OUTPUT
fi

- name: Generate coverage report
run: |
mkdir -p coverage
forge coverage --report lcov
lcov --remove lcov.info '${{ inputs.exclude_paths }}' -o coverage/lcov.info --rc branch_coverage=${{ steps.branch_coverage_int.outputs.branch_coverage }}
genhtml coverage/lcov.info -o coverage --rc branch_coverage=${{ steps.branch_coverage_int.outputs.branch_coverage }}

- name: Upload coverage report
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: coverage
path: coverage