|
1 | 1 | name: Post coverage comment |
2 | | - |
3 | 2 | on: |
4 | 3 | workflow_run: |
5 | 4 | workflows: ["UnitTests"] |
6 | 5 | types: |
7 | 6 | - completed |
8 | | - workflow_dispatch: |
9 | 7 |
|
10 | 8 | jobs: |
11 | 9 | test: |
12 | 10 | name: Run tests & display coverage |
13 | 11 | runs-on: ubuntu-latest |
14 | | - if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' |
15 | 12 | permissions: |
16 | | - # Gives the action the necessary permissions for publishing new |
17 | | - # comments in pull requests. |
18 | 13 | pull-requests: write |
19 | | - # Gives the action the necessary permissions for editing existing |
20 | | - # comments (to avoid publishing multiple comments in the same PR) |
21 | 14 | contents: write |
22 | | - # Gives the action the necessary permissions for looking up the |
23 | | - # workflow that launched this workflow, and download the related |
24 | | - # artifact that contains the comment to be published |
25 | 15 | actions: read |
26 | 16 | steps: |
27 | | - # DO NOT run actions/checkout here, for security reasons |
28 | | - # For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ |
| 17 | + - name: Check if should run |
| 18 | + id: check |
| 19 | + run: | |
| 20 | + if [[ "${{ github.event.workflow_run.event }}" == "pull_request" ]] && [[ "${{ github.event.workflow_run.conclusion }}" == "success" ]]; then |
| 21 | + echo "should_run=true" >> $GITHUB_OUTPUT |
| 22 | + echo "✅ Running coverage comment for PR" |
| 23 | + else |
| 24 | + echo "should_run=false" >> $GITHUB_OUTPUT |
| 25 | + echo "✅ Skipping - not a PR event (event: ${{ github.event.workflow_run.event }})" |
| 26 | + fi |
| 27 | +
|
29 | 28 | - name: Post comment |
| 29 | + if: steps.check.outputs.should_run == 'true' |
30 | 30 | uses: py-cov-action/python-coverage-comment-action@v3 |
31 | 31 | with: |
32 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
33 | 32 | GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }} |
34 | | - # Update those if you changed the default values: |
35 | | - # COMMENT_ARTIFACT_NAME: python-coverage-comment-action |
36 | | - # COMMENT_FILENAME: python-coverage-comment-action.txt |
| 33 | + env: |
| 34 | + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
0 commit comments