-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from storyprotocol/feat/add_reusable_forge_cod…
…e_coverage [feat] add reusable forge code coverage workflow
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |