Added before and after to split recipe #460
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
name: coverage | |
on: [push, pull_request] | |
jobs: | |
coverage: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
branch: [pr, main] | |
outputs: | |
cov-pr: ${{ steps.coverage.outputs.cov-pr }} | |
cov-main: ${{ steps.coverage.outputs.cov-main }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
# for safety, `pull_request_target` changes the default checkout to be the target branch, so we have to request the merge (we're limited to `permissions: {contents: read}`, so this is ok) | |
ref: ${{ matrix.branch == 'main' && 'main' || (github.event.pull_request && format('refs/pull/{0}/merge', github.event.pull_request.number)) || '' }} | |
- name: Bazel cache | |
id: bazel-cache | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/bazel | |
key: ${{ runner.os }}-3.10-bazel-cache-${{ hashFiles('**/BUILD', '.bazelrc', '.bazelversion', 'WORKSPACE') }} | |
restore-keys: ${{ runner.os }}-3.10-bazel-cache- | |
- name: Install poetry | |
run: pipx install poetry | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
cache: poetry | |
- name: Install dependencies | |
run: poetry install --no-interaction --extras polars | |
- name: Run coverage | |
id: coverage | |
run: | | |
poetry run ./tools/coverage.sh | |
poetry run coverage json | |
content=$(cat ./coverage.json) | |
echo "cov-${{ matrix.branch }}=$content" >> $GITHUB_OUTPUT | |
comment: | |
runs-on: ubuntu-latest | |
needs: [coverage] | |
permissions: | |
# needed to add coverage comment to the pull request | |
pull-requests: write | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
script: | | |
const pr = ${{fromJson(needs.coverage.outputs.cov-pr).totals.percent_covered}}; | |
const main = ${{fromJson(needs.coverage.outputs.cov-main).totals.percent_covered}}; | |
const diff = pr - main; | |
const report = `### Coverage report | |
**Main**: ${main.toFixed(2)}% | **PR**: ${pr.toFixed(2)}% | **Diff: ${diff.toFixed(2)} ${diff >= 0 ? 'β ' : 'β οΈ'}**`; | |
await core.summary.addRaw(report, true).write(); |