|
1 |
| -name: Coverage |
| 1 | +name: Post coverage comment |
2 | 2 |
|
3 | 3 | on:
|
4 |
| - push: |
5 |
| - branches: |
6 |
| - - main |
7 |
| - workflow_dispatch: |
8 |
| - |
9 |
| -env: |
10 |
| - PYTHON_VERSION: 3.11 |
| 4 | + workflow_run: |
| 5 | + workflows: ["CI"] |
| 6 | + types: |
| 7 | + - completed |
11 | 8 |
|
12 | 9 | jobs:
|
13 |
| - generate-coverage: |
| 10 | + test: |
| 11 | + name: Run tests & display coverage |
14 | 12 | runs-on: ubuntu-latest
|
15 |
| - |
| 13 | + if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' |
| 14 | + permissions: |
| 15 | + # Gives the action the necessary permissions for publishing new |
| 16 | + # comments in pull requests. |
| 17 | + pull-requests: write |
| 18 | + # Gives the action the necessary permissions for editing existing |
| 19 | + # comments (to avoid publishing multiple comments in the same PR) |
| 20 | + contents: write |
| 21 | + # Gives the action the necessary permissions for looking up the |
| 22 | + # workflow that launched this workflow, and download the related |
| 23 | + # artifact that contains the comment to be published |
| 24 | + actions: read |
16 | 25 | steps:
|
17 |
| - - uses: actions/checkout@v3 |
18 |
| - with: |
19 |
| - fetch-depth: 1 |
20 |
| - |
21 |
| - - name: Install Poetry |
22 |
| - run: | |
23 |
| - pipx install poetry |
24 |
| - poetry config virtualenvs.path ~/.virtualenvs${{ env.PYTHON_VERSION }} |
25 |
| -
|
26 |
| - - name: Set up Python ${{ env.PYTHON_VERSION }} |
27 |
| - uses: actions/setup-python@v3 |
| 26 | + # DO NOT run actions/checkout here, for security reasons |
| 27 | + # For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ |
| 28 | + - name: Post comment |
| 29 | + uses: py-cov-action/python-coverage-comment-action@v3 |
28 | 30 | with:
|
29 |
| - python-version: ${{ env.PYTHON_VERSION }} |
30 |
| - cache: "poetry" |
31 |
| - |
32 |
| - - name: Install dependencies |
33 |
| - run: poetry install -E minify |
34 |
| - |
35 |
| - - name: Generate coverage badge |
36 |
| - run: | |
37 |
| - chmod +x generate_badge.sh |
38 |
| - ./generate_badge.sh |
39 |
| -
|
40 |
| - - name: Commit and push coverage badge |
41 |
| - continue-on-error: true |
42 |
| - env: |
43 | 31 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
44 |
| - run: | |
45 |
| - git config --global user.name "github-actions[bot]" |
46 |
| - git config --global user.email "github-actions[bot]@users.noreply.github.com" |
47 |
| - git config pull.rebase true |
48 |
| - git checkout -b py-code-coverage || git checkout py-code-coverage |
49 |
| - git pull origin py-code-coverage |
50 |
| - git add . |
51 |
| - git commit --verbose -m "Update coverage badge" |
52 |
| - git rebase --strategy-option=ours py-code-coverage --verbose |
53 |
| - git push --verbose origin py-code-coverage |
| 32 | + GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }} |
| 33 | + # Update those if you changed the default values: |
| 34 | + # COMMENT_ARTIFACT_NAME: python-coverage-comment-action |
| 35 | + # COMMENT_FILENAME: python-coverage-comment-action.txt |
0 commit comments