From ef8d1a8a2866d7dca86d2b33e7a3e8b37e0c4821 Mon Sep 17 00:00:00 2001 From: Andy Wu Date: Thu, 11 Apr 2024 14:11:51 -0700 Subject: [PATCH] [feat] add reusable forge code coverage workflow --- .../reusable-forge-code-coverage.yml | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/reusable-forge-code-coverage.yml diff --git a/.github/workflows/reusable-forge-code-coverage.yml b/.github/workflows/reusable-forge-code-coverage.yml new file mode 100644 index 0000000..151ff35 --- /dev/null +++ b/.github/workflows/reusable-forge-code-coverage.yml @@ -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 }} --ignore-errors category + + - name: Upload coverage report + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 + with: + name: coverage + path: coverage