-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
105 lines (89 loc) · 4.01 KB
/
action.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: 'Post PR artifacts'
description: 'Posts artifacts produced in a PR workflow as a comment to the PR.'
inputs:
app-id:
description: 'The app ID of the app.'
private-key:
description: 'The private key of the app.'
runs:
using: composite
steps:
- uses: myparcelnl/actions/setup-app-credentials@v4
id: credentials
with:
app-id: ${{ inputs.app-id }}
private-key: ${{ inputs.private-key }}
- name: 'Get artifact and PR info'
id: info
env:
GITHUB_TOKEN: ${{ steps.credentials.outputs.token }}
WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
shell: bash
#language=bash
run: |
HEAD_SHA=$(jq -r '.pull_requests[0].head.sha' <<< "$WORKFLOW_RUN_EVENT_OBJ")
PREVIOUS_JOB_ID=$(jq -r '.id' <<< "$WORKFLOW_RUN_EVENT_OBJ")
PR_NUMBER=$(jq -r '.pull_requests[0].number' <<< "$WORKFLOW_RUN_EVENT_OBJ")
SUITE_ID=$(jq -r '.check_suite_id' <<< "$WORKFLOW_RUN_EVENT_OBJ")
ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" --jq ".artifacts | map(select(.workflow_run.id == ${PREVIOUS_JOB_ID} and .expired == false)) | sort_by(.updated_at)[-1] | .id")
echo "artifact-id=$ARTIFACT_ID" >> $GITHUB_OUTPUT
echo "head-sha=$HEAD_SHA" >> $GITHUB_OUTPUT
echo "suite-id=$SUITE_ID" >> $GITHUB_OUTPUT
echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "previous-job-id=$PREVIOUS_JOB_ID" >> $GITHUB_OUTPUT
if [ -z "$ARTIFACT_ID" ]; then
echo "::error::No artifact found for job $PREVIOUS_JOB_ID."
exit 1
fi
if [ -z "$SUITE_ID" ]; then
echo "::error::No suite found for job $PREVIOUS_JOB_ID."
exit 1
fi
if [ -z "$HEAD_SHA" ]; then
echo "::error::No head SHA found for job $PREVIOUS_JOB_ID."
exit 1
fi
if [ -z "$PR_NUMBER" ]; then
echo "::error::No PR number found for job $PREVIOUS_JOB_ID."
exit 1
fi
- name: 'Create or update comment with success state'
if: github.event.workflow_run.conclusion == 'success'
uses: myparcelnl/actions/create-or-update-comment@v4
env:
JOB_PATH: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ steps.info.outputs.previous-job-id }}
ARTIFACT_URL: ${{ github.server_url }}/${{ github.repository }}/suites/${{ steps.info.outputs.suite-id }}/artifacts/${{ steps.info.outputs.artifact-id }}
HEAD_SHA: ${{ steps.info.outputs.head-sha }}
with:
app-id: ${{ inputs.app-id }}
private-key: ${{ inputs.private-key }}
identifier: 'pr-post-artifacts'
issue-number: ${{ steps.info.outputs.pr-number }}
body: |-
✅ Build successful!
You can find a link to the downloadable artifact below.
| Name | Link |
| -------- | ----------------------- |
| Commit | ${{ env.HEAD_SHA }} |
| Logs | ${{ env.JOB_PATH }} |
| Download | ${{ env.ARTIFACT_URL }} |
- name: 'Create or update comment with failure state'
if: github.event.workflow_run.conclusion == 'failure'
uses: myparcelnl/actions/create-or-update-comment@v4
env:
JOB_PATH: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ steps.info.outputs.previous-job-id }}
HEAD_SHA: ${{ steps.info.outputs.head-sha }}
with:
app-id: ${{ inputs.app-id }}
private-key: ${{ inputs.private-key }}
identifier: 'pr-post-artifacts'
issue-number: ${{ steps.info.outputs.pr-number }}
body: |-
❌ Build failed!
You can find a link to the logs below.
| Name | Link |
| -------- | ----------------------- |
| Commit | ${{ env.HEAD_SHA }} |
| Logs | ${{ env.JOB_PATH }} |