|
| 1 | +name: Comment on the pull request |
| 2 | + |
| 3 | +# see https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ |
| 4 | +# read-write repo token |
| 5 | +# access to secrets |
| 6 | +on: |
| 7 | + workflow_run: |
| 8 | + workflows: ["Test"] |
| 9 | + types: |
| 10 | + - completed |
| 11 | + |
| 12 | +jobs: |
| 13 | + upload: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + if: > |
| 16 | + github.event.workflow_run.event == 'pull_request' && |
| 17 | + github.event.workflow_run.conclusion == 'success' |
| 18 | + steps: |
| 19 | + - name: 'Download artifact' |
| 20 | + uses: actions/github-script@v3.1.0 |
| 21 | + with: |
| 22 | + script: | |
| 23 | + var artifacts = await github.actions.listWorkflowRunArtifacts({ |
| 24 | + owner: context.repo.owner, |
| 25 | + repo: context.repo.repo, |
| 26 | + run_id: ${{github.event.workflow_run.id }}, |
| 27 | + }); |
| 28 | + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
| 29 | + return artifact.name == "coverage" |
| 30 | + })[0]; |
| 31 | + var download = await github.actions.downloadArtifact({ |
| 32 | + owner: context.repo.owner, |
| 33 | + repo: context.repo.repo, |
| 34 | + artifact_id: matchArtifact.id, |
| 35 | + archive_format: 'zip', |
| 36 | + }); |
| 37 | + var fs = require('fs'); |
| 38 | + fs.writeFileSync('${{github.workspace}}/coverage.zip', Buffer.from(download.data)); |
| 39 | + - run: unzip pr.zip |
| 40 | + - name: 'get PR number' |
| 41 | + run: echo "pr_number=$(cat ./PR)">> $GITHUB_ENV |
| 42 | + |
| 43 | + - name: report coverage |
| 44 | + uses: Nef10/lcov-reporter-action@v0.4.0 |
| 45 | + with: |
| 46 | + lcov-file: lcov.info |
| 47 | + pr-number: ${{ env.pr_number }} |
| 48 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + output-file: comment.html |
| 50 | + - name: Post code coverage report |
| 51 | + uses: marocchino/sticky-pull-request-comment@v2.8.0 |
| 52 | + with: |
| 53 | + path: comment.html |
| 54 | + number: ${{ env.pr_number }} |
0 commit comments