|
3 | 3 |
|
4 | 4 | name: Test and Lint |
5 | 5 |
|
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 |
7 | 21 |
|
8 | 22 | jobs: |
9 | 23 | Pytest: |
|
17 | 31 | with: |
18 | 32 | python-version: 3.11 |
19 | 33 | - uses: Gr1N/setup-poetry@v8 |
20 | | - - uses: actions/cache@v2 |
| 34 | + - uses: actions/cache@v3 |
21 | 35 | with: |
22 | 36 | path: ~/.cache/pypoetry/virtualenvs |
23 | 37 | key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }} |
|
26 | 40 | - name: Test with pytest |
27 | 41 | run: | |
28 | 42 | poetry run coverage run -m pytest |
29 | | - - name: Generate code coverage report |
| 43 | + - name: Print coverage output |
30 | 44 | run: | |
31 | 45 | 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 }} |
32 | 56 |
|
33 | 57 | Flake8: |
34 | 58 | runs-on: ubuntu-latest |
|
41 | 65 | with: |
42 | 66 | python-version: 3.11 |
43 | 67 | - uses: Gr1N/setup-poetry@v8 |
44 | | - - uses: actions/cache@v2 |
| 68 | + - uses: actions/cache@v3 |
45 | 69 | with: |
46 | 70 | path: ~/.cache/pypoetry/virtualenvs |
47 | 71 | key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }} |
|
62 | 86 | with: |
63 | 87 | python-version: 3.11 |
64 | 88 | - uses: Gr1N/setup-poetry@v8 |
65 | | - - uses: actions/cache@v2 |
| 89 | + - uses: actions/cache@v3 |
66 | 90 | with: |
67 | 91 | path: ~/.cache/pypoetry/virtualenvs |
68 | 92 | key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }} |
|
0 commit comments