Skip to content

Commit

Permalink
Merge pull request #11 from storyprotocol/feat/add_reusable_forge_cod…
Browse files Browse the repository at this point in the history
…e_coverage

[feat] add reusable forge code coverage workflow
  • Loading branch information
AndyBoWu authored Apr 11, 2024
2 parents 9d617a1 + 9c1528a commit cf627f6
Showing 1 changed file with 67 additions and 0 deletions.
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

0 comments on commit cf627f6

Please sign in to comment.