Repository navigation
130 lines (121 loc) · 4.13 KB
/
Copy pathbuild-notification.yml
File metadata and controls
130 lines (121 loc) · 4.13 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: update PR comment after Netlify notification
env:
repo: ${{ github.repository }}
on:
workflow_dispatch:
inputs:
prNumber:
description: PR to update with build status
required: true
type: number
buildStatus:
description: current build status from Netlify
required: true
type: choice
options:
- building
- ready
- error
deployUrl:
description: URL of live branch deploy
required: false
deployLogUrl:
description: URL of logs
required: true
sha:
description: SHA hash of the commit built
required: true
permissions:
statuses: write
pull-requests: write
jobs:
deploy-preview:
runs-on: ubuntu-latest
steps:
# set body of the PR comment
- name: construct message
id: construct-message
run: |
case '${{ inputs.buildStatus }}' in
"building")
comment_body=$(cat <<-END
### <span aria-hidden="true">⏳</span> Deploy Preview building!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | ${{ inputs.sha }} |
|<span aria-hidden="true">🔍</span> Latest deploy log | ${{ inputs.deployLogUrl }} |
---
END
)
;;
"ready")
comment_body=$(cat <<-END
### <span aria-hidden="true">✅</span> Deploy Preview ready!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | ${{ inputs.sha }} |
|<span aria-hidden="true">🔍</span> Latest deploy log | ${{ inputs.deployLogUrl }} |
|<span aria-hidden="true">😎</span> Deploy Preview | [${{ inputs.deployUrl }}](${{ inputs.deployUrl }}) |
---
END
)
;;
"error")
comment_body=$(cat <<-END
### <span aria-hidden="true">❌</span> Deploy Preview failed!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | ${{ inputs.sha }} |
|<span aria-hidden="true">🔍</span> Latest deploy log | ${{ inputs.deployLogUrl }} |
---
END
)
;;
esac
{
echo 'comment_body<<EOF'
echo "$comment_body"
echo EOF
} >> "$GITHUB_OUTPUT"
- name: update PR check - pending
if: ${{ inputs.buildStatus == 'building' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api \
--method POST \
-f state='pending' \
-f target_url='${{ inputs.deployLogUrl }}' \
-f description='The build has started' \
-f context='netlify/build' \
/repos/${{ env.repo }}/statuses/${{ inputs.sha }}
- name: update PR check - error
if: ${{ inputs.buildStatus == 'error' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api \
--method POST \
-f state='failure' \
-f target_url='${{ inputs.deployLogUrl }}' \
-f description='The build has failed' \
-f context='netlify/build' \
/repos/${{ env.repo }}/statuses/${{ inputs.sha }}
- name: update PR check - ready
if: ${{ inputs.buildStatus == 'ready' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api \
--method POST \
-f state='success' \
-f target_url='${{ inputs.deployLogUrl }}' \
-f description='The build has finished successfully' \
-f context='netlify/build' \
/repos/${{ env.repo }}/statuses/${{ inputs.sha }}
- name: update PR comment with Netlify status
uses: thollander/actions-comment-pull-request@v2
with:
message: ${{ steps.construct-message.outputs.comment_body }}
pr_number: ${{ inputs.prNumber }}
comment_tag: manual-build-comment