Skip to content

Commit d02dc56

Browse files
Merge pull request #5 from COMP1010UNSW/miguel-coverage-comment
Add coverage comment to workflow
2 parents e7a5356 + 769c024 commit d02dc56

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

.github/workflows/python-app.yml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,21 @@
33

44
name: Test and Lint
55

6-
on: [push]
6+
on:
7+
pull_request:
8+
branches:
9+
- main
10+
push:
11+
branches:
12+
- main
13+
14+
# Yoinked from https://github.com/MTES-MCT/apilos/pull/854/files
15+
# Explicitely set permissions to allow Dependabot workflow runs to write in the PR
16+
# for coverage's reporting.
17+
# By default, these are read-only when the actions are ran by Dependabot
18+
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#changing-github_token-permissions
19+
permissions:
20+
pull-requests: write
721

822
jobs:
923
Pytest:
@@ -17,7 +31,7 @@ jobs:
1731
with:
1832
python-version: 3.11
1933
- uses: Gr1N/setup-poetry@v8
20-
- uses: actions/cache@v2
34+
- uses: actions/cache@v3
2135
with:
2236
path: ~/.cache/pypoetry/virtualenvs
2337
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
@@ -26,9 +40,19 @@ jobs:
2640
- name: Test with pytest
2741
run: |
2842
poetry run coverage run -m pytest
29-
- name: Generate code coverage report
43+
- name: Print coverage output
3044
run: |
3145
poetry run coverage report
46+
- name: Generate code coverage report
47+
if: ${{ github.event_name == 'pull_request' }}
48+
run: |
49+
poetry run coverage xml
50+
- name: Create code coverage comment
51+
if: ${{ github.event_name == 'pull_request' }}
52+
uses: orgoro/coverage@v3
53+
with:
54+
coverageFile: coverage.xml
55+
token: ${{ secrets.GITHUB_TOKEN }}
3256

3357
Flake8:
3458
runs-on: ubuntu-latest
@@ -41,7 +65,7 @@ jobs:
4165
with:
4266
python-version: 3.11
4367
- uses: Gr1N/setup-poetry@v8
44-
- uses: actions/cache@v2
68+
- uses: actions/cache@v3
4569
with:
4670
path: ~/.cache/pypoetry/virtualenvs
4771
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
@@ -62,7 +86,7 @@ jobs:
6286
with:
6387
python-version: 3.11
6488
- uses: Gr1N/setup-poetry@v8
65-
- uses: actions/cache@v2
89+
- uses: actions/cache@v3
6690
with:
6791
path: ~/.cache/pypoetry/virtualenvs
6892
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}

0 commit comments

Comments
 (0)