-
Notifications
You must be signed in to change notification settings - Fork 61
75 lines (66 loc) · 2.1 KB
/
pr-comment.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Comment on PR
on:
workflow_run:
workflows:
- Analyze PR Changes
- Test Spec
types:
- completed
jobs:
comment:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
ref: refs/heads/main
sparse-checkout: |
.github
- name: Download PR Comment Payload
uses: actions/download-artifact@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
name: pr-comment
run-id: ${{ github.event.workflow_run.id }}
- name: Parse Payload
shell: bash -eo pipefail {0}
run: |
PR_NUMBER=$(jq -r '.pr_number' ./pr-comment.json)
COMMENT_IDENTIFIER=$(jq -r '.comment_identifier' ./pr-comment.json)
TEMPLATE_NAME=$(jq -r '.template_name' ./pr-comment.json)
TEMPLATE_DATA=$(jq -c '.template_data' ./pr-comment.json)
vars=(
PR_NUMBER
COMMENT_IDENTIFIER
TEMPLATE_NAME
TEMPLATE_DATA
)
{
for var in "${vars[@]}"
do
echo "${var}=${!var}"
done
} | tee "$GITHUB_ENV"
- name: Render Comment Template
uses: chuhlomin/render-template@v1
id: render
with:
template: .github/pr-comment-templates/${{ env.TEMPLATE_NAME }}.template.md
vars: ${{ env.TEMPLATE_DATA }}
- name: Find Existing Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ env.PR_NUMBER }}
comment-author: 'github-actions[bot]'
body-includes: ${{ env.COMMENT_IDENTIFIER }}
- name: Create or Update Comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ env.PR_NUMBER }}
body: ${{ steps.render.outputs.result }}
edit-mode: replace