-
Notifications
You must be signed in to change notification settings - Fork 2
112 lines (100 loc) · 3.76 KB
/
deploy-preview.yml
File metadata and controls
112 lines (100 loc) · 3.76 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
name: Netlify deploy-preview
on:
workflow_dispatch:
inputs:
issue:
description: Issue number
required: true
type: number
status:
description: Deployment status
required: true
type: choice
options:
- in_progress
- failure
- success
deploy_id:
description: Netlify deploy ID
required: true
type: string
log:
description: Netlify log URL
required: true
type: string
jobs:
debug:
name: Debug inputs
runs-on: ubuntu-latest
steps:
- name: Debug inputs
run: jq . <<< '${{ toJSON(github.event.inputs) }}'
notify:
name: Notify about deployment
runs-on: ubuntu-latest
steps:
- name: Create deployment
id: deployment
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GH_TOKEN_MANAGE_ENVS }}
ISSUE: ${{ github.event.inputs.issue }}
STATUS: ${{ github.event.inputs.status }}
DEPLOY: ${{ github.event.inputs.deploy_id }}
run: |
set -e ${RUNNER_DEBUG:+-x}
env=staging-$ISSUE
url=https://$env.cmbuckley.co.uk
echo "url=$url" >> $GITHUB_OUTPUT
ref=$(gh pr view $ISSUE --json headRefOid -q .headRefOid)
# create environment unless it exists already
gh api --silent repos/{owner}/{repo}/environments/$env 2>/dev/null \
|| gh api -X PUT repos/{owner}/{repo}/environments/$env
# find deployment for this Netlify ID
deployment=$(gh api repos/{owner}/{repo}/deployments?environment=$env \
-q "map(select(.payload.deploy == \"$DEPLOY\")) | first.id")
# create deployment if it doesn't exist
[ -z "$deployment" ] && deployment=$(gh api repos/{owner}/{repo}/deployments -q .id \
-f ref=$ref \
-f environment=$env \
-F auto_merge=false \
-F required_contexts[]$([ $STATUS == 'success' ] && echo '=netlify/{owner}/deploy-preview') \
-f payload[deploy]=$DEPLOY \
-f 'description=Deploy by Netlify')
# set status of the deployment
gh api -X POST repos/{owner}/{repo}/deployments/$deployment/statuses \
-f state=$STATUS \
-f environment_url=$url
- name: Get comment text
id: get-text
uses: actions/github-script@v8
with:
script: |
const status = context.payload.inputs.status,
data = {
in_progress: ['👷', 'in progress', false],
failure: ['❌', 'failed', false],
success: ['✅', 'ready', true],
};
core.setOutput('emoji', data[status][0]);
core.setOutput('title', data[status][1]);
core.setOutput('preview', data[status][2]);
- name: Find Comment
id: find-comment
uses: peter-evans/find-comment@v4
with:
issue-number: ${{ github.event.inputs.issue }}
comment-author: 'github-actions[bot]'
body-includes: Deploy Preview
- name: Create comment
uses: peter-evans/create-or-update-comment@v5
with:
issue-number: ${{ github.event.inputs.issue }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: |
### <span aria-hidden="true">${{ steps.get-text.outputs.emoji }}</span> Deploy Preview ${{ steps.get-text.outputs.title }}!
| Name | Link |
|----------------|------|
${{ steps.get-text.outputs.preview && format('| Deploy Preview | {0} |\n', steps.deployment.outputs.url) || ''}}
| Deploy Log | ${{ github.event.inputs.log }} |