86 lines (77 loc) Β· 2.75 KB
/
coverage.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: coverage
on: [push]
permissions:
contents: read
pull-requests: write
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@v3
with:
ref: ${{ matrix.branch == 'main' && 'main' || '' }}
- 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
- 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]
steps:
- uses: actions/github-script@v6
env:
issue_number: ${{ github.event.issue.number }}
if: ${{ env.issue_number }}
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;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `### Coverage report
**Main**: ${main.toFixed(2)}% | **PR**: ${pr.toFixed(2)}% | **Diff: ${diff.toFixed(2)} ${diff >= 0 ? 'β
' : 'β οΈ'}**`
})
- env:
pr: ${{ fromJson(needs.coverage.outputs.cov-pr).totals.percent_covered }}
main: ${{fromJson(needs.coverage.outputs.cov-main).totals.percent_covered}}
run: |
diff=$(echo "$pr - $main" | bc)
main_fixed=$(echo "scale=2; $main/1" | bc)
pr_fixed=$(echo "scale=2; $pr/1" | bc)
diff_fixed=$(echo "scale=2; $diff/1" | bc)
if [ $(echo "scale=0; $diff/1" | bc) -gt 0 ]; then
icon='β
'
else
icon='β οΈ'
fi
echo "### Coverage report
**Main**: ${main_fixed}% | **PR**: ${pr_fixed}% | **Diff: ${diff_fixed} ${icon}**" >> "$GITHUB_STEP_SUMMARY"