-
Notifications
You must be signed in to change notification settings - Fork 143
56 lines (50 loc) · 1.9 KB
/
pr-comment-artifact-url.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
name: Comment Artifact URL on PRs
on:
workflow_run:
types:
- 'completed'
workflows:
- 'Artifact Upload'
jobs:
comment-on-pr:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- name: Get Artifact URL & PR Info
env:
GITHUB_TOKEN: ${{ github.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }}
GITHUB_WORKFLOW_RUN_CHECK_SUITE_ID: ${{ github.event.workflow_run.check_suite_id }}
WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }}
run: |
set -e
HEAD_SHA=$(jq -r '.pull_requests[0].head.sha' <<< "$WORKFLOW_RUN_EVENT_OBJ")
PR_NUMBER=$(jq -r '.pull_requests[0].number' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "PR Number: $PR_NUMBER"
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV"
gh api "/repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_WORKFLOW_RUN_ID/artifacts" \
--jq "[.artifacts | .[] | {"id": .id, "name": .name}]" \
> artifacts.json
PR_COMMENT=$(
echo "Builds for commit $HEAD_SHA:"
while IFS="§" read -r name url; do
echo "* [$name]($url)"
done < <(jq -r ".[] | \
.name + \"§\" \
+ ( .id | tostring | \"https://github.com/$GITHUB_REPOSITORY/suites/$GITHUB_WORKFLOW_RUN_CHECK_SUITE_ID/artifacts/\" + . )" \
artifacts.json)
)
echo -e "PR COMMENT: \n$PR_COMMENT"
{
echo 'PR_COMMENT<<EOF'
echo -e "$PR_COMMENT"
echo EOF
} >> "$GITHUB_ENV"
- name: Update Comment
env:
HEAD_SHA: ${{ env.HEAD_SHA }}
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ env.PR_NUMBER }}
body: ${{ env.PR_COMMENT }}