|
1 | | -name: PR Comment |
| 1 | +# By calling this ci via `workflow_call` from another ci it has permissions to comment on prs from forks |
| 2 | +# This action expects the a artifact named `content` to be present in the workflow run |
| 3 | +# If the artifact contains a pr_number.txt, the action will comment on that pr. If not it comments on the commit. |
| 4 | +# The content of the messages composed by concatinating all *.txt files within content into a single file |
| 5 | +# If you want to enforce a specific order, you need to name the files in a way that sorts in the desired order |
| 6 | +name: Comment |
2 | 7 |
|
3 | 8 | on: |
4 | 9 | workflow_run: |
5 | 10 | workflows: [Test] |
6 | 11 | types: |
7 | 12 | - completed |
8 | 13 |
|
9 | | -permissions: |
10 | | - actions: read |
11 | | - issues: write |
12 | | - checks: read |
13 | | - statuses: read |
14 | | - pull-requests: write |
15 | | - |
16 | 14 | jobs: |
17 | 15 | comment: |
18 | 16 | name: Comment Bot |
19 | 17 | runs-on: ubuntu-latest |
20 | | - # workflow run triggers on all types of "completed" including "cancelled" and similar |
21 | | - # we want this action to only run on a success & failure though |
22 | | - if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure' }} |
23 | 18 | steps: |
24 | 19 | - uses: actions/download-artifact@v4 |
25 | 20 | with: |
26 | | - name: pr_number |
27 | | - path: pr/ |
| 21 | + name: content |
| 22 | + path: /tmp/content |
28 | 23 | run-id: ${{ github.event.workflow_run.id }} |
29 | | - github-token: ${{ github.token }} |
| 24 | + github-token: ${{ secrets.READ_ONLY_PAT }} |
30 | 25 |
|
31 | 26 | - name: Read pr number |
32 | 27 | id: get_pr_number |
33 | | - run: echo "pr_number=$(cat pr/pr_number.txt)" >> $GITHUB_OUTPUT |
| 28 | + run: | |
| 29 | + echo "pr_number=$(cat /tmp/content/pr_number.txt)" >> $GITHUB_OUTPUT |
| 30 | + rm /tmp/content/pr_number.txt |
34 | 31 |
|
35 | | - - uses: actions/download-artifact@v4 |
36 | | - with: |
37 | | - name: ${{ github.event.workflow_run.head_sha }} |
38 | | - path: tmp/ |
39 | | - run-id: ${{ github.event.workflow_run.id }} |
40 | | - github-token: ${{ github.token }} |
| 32 | + - name: Combine |
| 33 | + id: combine |
| 34 | + run: cat /tmp/content/*.txt > /tmp/all.txt |
41 | 35 |
|
42 | 36 | - name: Find Comment |
43 | | - uses: peter-evans/find-comment@782f37b1a8a2b3e2eb9e86a994f0871e9dc146e3 |
| 37 | + uses: peter-evans/find-comment@v3 |
44 | 38 | id: fc |
45 | 39 | if: ${{ steps.get_pr_number.outputs.pr_number != null }} |
46 | 40 | with: |
47 | 41 | issue-number: ${{ steps.get_pr_number.outputs.pr_number }} |
48 | 42 | comment-author: "github-actions[bot]" |
49 | | - body-includes: Foundry report |
50 | 43 |
|
51 | 44 | - name: Create or update pr comment |
52 | | - uses: peter-evans/create-or-update-comment@48bb05bd5554c378187694936d277d48652922e7 |
| 45 | + uses: peter-evans/create-or-update-comment@v4 |
53 | 46 | if: ${{ steps.get_pr_number.outputs.pr_number != null }} |
54 | 47 | with: |
55 | 48 | comment-id: ${{ steps.fc.outputs.comment-id }} |
56 | 49 | issue-number: ${{ steps.get_pr_number.outputs.pr_number }} |
57 | | - body-file: tmp/template.md |
| 50 | + body-file: /tmp/all.txt |
58 | 51 | edit-mode: replace |
59 | 52 |
|
60 | | - - id: get-comment-body |
61 | | - if: ${{ steps.get_pr_number.outputs.pr_number == null }} |
62 | | - run: | |
63 | | - body="$(cat tmp/template.md)" |
64 | | - delimiter="$(openssl rand -hex 8)" |
65 | | - echo "body<<$delimiter" >> $GITHUB_OUTPUT |
66 | | - echo "$body" >> $GITHUB_OUTPUT |
67 | | - echo "$delimiter" >> $GITHUB_OUTPUT |
68 | | -
|
69 | 53 | - name: Create or update commit comment |
70 | | - uses: peter-evans/commit-comment@ae7c3825ead23dab7a1ad8cd4df9617ab4bf0b37 |
| 54 | + uses: peter-evans/commit-comment@v3 |
71 | 55 | if: ${{ steps.get_pr_number.outputs.pr_number == null }} |
72 | 56 | with: |
73 | 57 | sha: ${{ github.event.workflow_run.head_sha }} |
74 | | - body: ${{ steps.get-comment-body.outputs.body }} |
| 58 | + body-file: /tmp/all.txt |
0 commit comments