|
| 1 | +# Description: This workflow is triggered when the `pr-format-workflow` completes to post suggestions on the PR. |
| 2 | +# Since this pull request has write permissions on the target repo, we should **NOT** execute any untrusted code. |
| 3 | +# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ |
| 4 | +--- |
| 5 | +name: pr-suggestions-workflow |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_run: |
| 9 | + workflows: ["pr-format-workflow"] |
| 10 | + types: |
| 11 | + - completed |
| 12 | + |
| 13 | +jobs: |
| 14 | + post-suggestions: |
| 15 | + # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-a-workflow-based-on-the-conclusion-of-another-workflow |
| 16 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + actions: read |
| 20 | + pull-requests: write |
| 21 | + env: |
| 22 | + # https://docs.github.com/en/actions/reference/authentication-in-a-workflow#permissions-for-the-github_token |
| 23 | + ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + timeout-minutes: 10 |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + ref: ${{github.event.workflow_run.head_branch}} |
| 29 | + repository: ${{github.event.workflow_run.head_repository.full_name}} |
| 30 | + |
| 31 | + # Download the patch |
| 32 | + - uses: actions/download-artifact@v4 |
| 33 | + with: |
| 34 | + name: patch |
| 35 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + run-id: ${{ github.event.workflow_run.id }} |
| 37 | + - name: Apply patch |
| 38 | + run: | |
| 39 | + git apply git-diff.patch --allow-empty |
| 40 | + rm git-diff.patch |
| 41 | +
|
| 42 | + # Download the PR number |
| 43 | + - uses: actions/download-artifact@v4 |
| 44 | + with: |
| 45 | + name: pr_number |
| 46 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + run-id: ${{ github.event.workflow_run.id }} |
| 48 | + - name: Read pr_number.txt |
| 49 | + run: | |
| 50 | + PR_NUMBER=$(cat pr_number.txt) |
| 51 | + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV |
| 52 | + rm pr_number.txt |
| 53 | +
|
| 54 | + # Post suggestions as a comment on the PR |
| 55 | + - uses: googleapis/code-suggester@v4 |
| 56 | + with: |
| 57 | + command: review |
| 58 | + pull_number: ${{ env.PR_NUMBER }} |
| 59 | + git_dir: '.' |
0 commit comments