Skip to content

Commit 1e13fe6

Browse files
committed
ci: Add comment to PR with link do the Kidiff of the changes.
1 parent e10357e commit 1e13fe6

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

.github/workflows/comment_pr_diff.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# comment_pr_diff.yml
2+
# From https://github.com/orgs/community/discussions/51403z
3+
name: Comment Artifact Diff files URL on PR
4+
5+
#on:
6+
# workflow_run:
7+
# types:
8+
# - "completed"
9+
# workflows:
10+
# - "Diff"
11+
12+
on:
13+
push:
14+
15+
jobs:
16+
comment-on-pr:
17+
if: github.event.workflow_run.conclusion == 'success'
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Test
21+
run: |
22+
pwd
23+
24+
- name: Get Artifact URL & PR Info
25+
env:
26+
GITHUB_TOKEN: ${{ github.token }}
27+
OWNER: ${{ github.repository_owner }}
28+
REPO: ${{ github.event.repository.name }}
29+
WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }}
30+
run: |
31+
32+
PREVIOUS_JOB_ID=$(jq -r '.id' <<< "$WORKFLOW_RUN_EVENT_OBJ")
33+
echo "Previous Job ID: $PREVIOUS_JOB_ID"
34+
echo "PREVIOUS_JOB_ID=$PREVIOUS_JOB_ID" >> "$GITHUB_ENV"
35+
36+
ARTIFACT_URL=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" \
37+
--jq ".artifacts.[] |
38+
select(.workflow_run.id==${PREVIOUS_JOB_ID}) |
39+
select(.expired==false) |
40+
.archive_download_url")
41+
42+
echo "ARTIFACT URL: $ARTIFACT_URL"
43+
echo "ARTIFACT_URL=$ARTIFACT_URL" >> "$GITHUB_ENV"
44+
45+
PR_NUMBER=$(jq -r '.pull_requests[0].number' \
46+
<<< "$WORKFLOW_RUN_EVENT_OBJ")
47+
48+
echo "PR Number: $PR_NUMBER"
49+
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV"
50+
51+
HEAD_SHA=$(jq -r '.pull_requests[0].head.sha' \
52+
<<< "$WORKFLOW_RUN_EVENT_OBJ")
53+
54+
echo "Head sha: $HEAD_SHA"
55+
echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV"
56+
57+
- name: Update Comment
58+
env:
59+
JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/\
60+
runs/${{ env.PREVIOUS_JOB_ID }}"
61+
HEAD_SHA: ${{ env.HEAD_SHA }}
62+
uses: peter-evans/create-or-update-comment@v2
63+
with:
64+
issue-number: ${{ env.PR_NUMBER }}
65+
body: |-
66+
## Diff preview files are ready!
67+
68+
[![badge]]($JOB_PATH)
69+
70+
You can find files attached to the below linked Workflow Run URL (Logs).
71+
72+
| Name | Link
73+
--------------------------------------------------------------------
74+
| Commit | ${{ env.HEAD_SHA }}
75+
76+
| Logs | ${{ env.JOB_PATH }}
77+
78+
| Jar Files | ${{ env. ARTIFACT_URL }}
79+
80+
[badge]: https://img.shields.io/badge/Build-Success!-3fb950?logo=github&style=for-the-badge

.github/workflows/production.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
types:
77
- closed
88
- pull_request
9+
- push
910

1011
jobs:
1112
build:

0 commit comments

Comments
 (0)