-
Notifications
You must be signed in to change notification settings - Fork 429
281 lines (261 loc) · 10.5 KB
/
deploy.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
name: Deploy
concurrency:
group: deploy
on:
workflow_dispatch:
inputs:
ci_required:
description: "CI Suite is required"
type: boolean
required: true
default: true
perform_deploy_main:
description: "Deploy Paradise Main/Secondary"
type: boolean
required: true
default: true
perform_deploy_vega:
description: "Deploy Paradise Vega"
type: boolean
required: true
default: true
perform_deploy_cleo:
description: "Deploy Paradise Cleo"
type: boolean
required: true
default: true
perform_deploy_prime:
description: "Deploy Paradise Prime"
type: boolean
required: true
default: true
perform_deploy_wl:
description: "Deploy Paradise WL"
type: boolean
required: true
default: true
perform_deploy_tutorial:
description: "Deploy Paradise Tutorial"
type: boolean
required: true
default: true
jobs:
check:
name: Check User Permission
runs-on: ubuntu-latest
steps:
- uses: skjnldsv/check-actor-permission@v3
with:
require: 'admin'
CI:
needs: [check]
uses: ./.github/workflows/ci.yml # use the callable tests job to run tests
if: ${{ inputs.ci_required }}
update-isp-lists:
name: Update ISP Lists
runs-on: ubuntu-latest
needs: [check]
steps:
- name: Update ISP Lists
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PRODUCTION_HOST }}
username: ${{ secrets.PRODUCTION_USERNAME }}
key: ${{ secrets.PRODUCTION_SSH_KEY }}
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }}
script: /var/lib/byond/update_isp_lists.sh
set-matrix:
name: Set Deployment Matrix
runs-on: ubuntu-latest
needs: [check]
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: |
MATRIX_JSON="{\"include\": ["
if ${{ github.event.inputs.perform_deploy_main }}; then
MATRIX_JSON="${MATRIX_JSON}{\"environment\": \"Main\"},"
MATRIX_JSON="${MATRIX_JSON}{\"environment\": \"Secondary\"},"
fi
if ${{ github.event.inputs.perform_deploy_vega }}; then
MATRIX_JSON="${MATRIX_JSON}{\"environment\": \"Vega\"},"
fi
if ${{ github.event.inputs.perform_deploy_cleo }}; then
MATRIX_JSON="${MATRIX_JSON}{\"environment\": \"Cleo\"},"
fi
if ${{ github.event.inputs.perform_deploy_prime }}; then
MATRIX_JSON="${MATRIX_JSON}{\"environment\": \"Prime\"},"
fi
if ${{ github.event.inputs.perform_deploy_wl }}; then
MATRIX_JSON="${MATRIX_JSON}{\"environment\": \"WL\"},"
fi
if ${{ github.event.inputs.perform_deploy_tutorial }}; then
MATRIX_JSON="${MATRIX_JSON}{\"environment\": \"Tutorial\"},"
fi
MATRIX_JSON="${MATRIX_JSON%?}]}" # Remove the trailing comma
echo "matrix=${MATRIX_JSON}" >> $GITHUB_OUTPUT
deploy:
name: Deploy Paradise
runs-on: ubuntu-latest
permissions:
deployments: write
strategy:
fail-fast: false
matrix: ${{fromJson(needs.set-matrix.outputs.matrix)}}
environment: ${{ matrix.environment }}
needs: [check, update-isp-lists, CI, set-matrix]
if: always() && !cancelled() && !failure()
steps:
- uses: chrnorm/deployment-action@v2
name: Create GitHub deployment
id: deployment
with:
token: "${{ github.token }}"
environment: ${{ matrix.environment }}
environment-url: ${{ vars.ENVIRONMENT_URL }}
log-url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
ref: ${{ vars.BRANCH }}
production-environment: true
initial-status: "in_progress"
- name: Update and Build Paradise Main
if: matrix.environment == 'Main' && inputs.perform_deploy_main
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PRODUCTION_HOST }}
username: ${{ secrets.PRODUCTION_USERNAME }}
key: ${{ secrets.PRODUCTION_SSH_KEY }}
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }}
script: |
TIME=$(date +'%Y-%m-%d%T')
sudo systemctl --wait start deploy-main
journalctl --since $TIME -u deploy-main --no-pager --all
systemctl is-failed deploy-main | grep -q "failed" && echo "Deployment Failed!" && exit 1 || exit 0
- name: Update and Build Paradise Secondary
if: matrix.environment == 'Secondary' && inputs.perform_deploy_main
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PRODUCTION_HOST }}
username: ${{ secrets.PRODUCTION_USERNAME }}
key: ${{ secrets.PRODUCTION_SSH_KEY }}
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }}
script: |
systemctl is-failed deploy-main | grep -q "failed" && echo "Deployment Failed!" && exit 1 || exit 0
- name: Update and Build Paradise Vega
if: matrix.environment == 'Vega' && inputs.perform_deploy_vega
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PRODUCTION_HOST }}
username: ${{ secrets.PRODUCTION_USERNAME }}
key: ${{ secrets.PRODUCTION_SSH_KEY }}
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }}
script: |
TIME=$(date +'%Y-%m-%d%T')
sudo systemctl --wait start deploy-vega
journalctl --since $TIME -u deploy-vega --no-pager --all
systemctl is-failed deploy-vega | grep -q "failed" && echo "Deployment Failed!" && exit 1 || exit 0
- name: Update and Build Paradise Cleo
if: matrix.environment == 'Cleo' && inputs.perform_deploy_cleo
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PRODUCTION_HOST }}
username: ${{ secrets.PRODUCTION_USERNAME }}
key: ${{ secrets.PRODUCTION_SSH_KEY }}
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }}
script: |
TIME=$(date +'%Y-%m-%d%T')
sudo systemctl --wait start deploy-cleo
journalctl --since $TIME -u deploy-cleo --no-pager --all
systemctl is-failed deploy-cleo | grep -q "failed" && echo "Deployment Failed!" && exit 1 || exit 0
- name: Update and Build Paradise Prime
if: matrix.environment == 'Prime' && inputs.perform_deploy_prime
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PRODUCTION_HOST }}
username: ${{ secrets.PRODUCTION_USERNAME }}
key: ${{ secrets.PRODUCTION_SSH_KEY }}
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }}
script: |
TIME=$(date +'%Y-%m-%d%T')
sudo systemctl --wait start deploy-prime
journalctl --since $TIME -u deploy-prime --no-pager --all
systemctl is-failed deploy-prime | grep -q "failed" && echo "Deployment Failed!" && exit 1 || exit 0
- name: Update and Build Paradise WL
if: matrix.environment == 'WL' && inputs.perform_deploy_wl
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PRODUCTION_HOST }}
username: ${{ secrets.PRODUCTION_USERNAME }}
key: ${{ secrets.PRODUCTION_SSH_KEY }}
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }}
script: |
TIME=$(date +'%Y-%m-%d%T')
sudo systemctl --wait start deploy-wl
journalctl --since $TIME -u deploy-wl --no-pager --all
systemctl is-failed deploy-wl | grep -q "failed" && echo "Deployment Failed!" && exit 1 || exit 0
- name: Update and Build Paradise Tutorial
if: matrix.environment == 'Tutorial' && inputs.perform_deploy_tutorial
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PRODUCTION_HOST }}
username: ${{ secrets.PRODUCTION_USERNAME }}
key: ${{ secrets.PRODUCTION_SSH_KEY }}
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }}
script: |
TIME=$(date +'%Y-%m-%d%T')
sudo systemctl --wait start deploy-tutorial
journalctl --since $TIME -u deploy-tutorial --no-pager --all
systemctl is-failed deploy-tutorial | grep -q "failed" && echo "Deployment Failed!" && exit 1 || exit 0
- name: Update deployment status (success)
if: |
success()
uses: chrnorm/deployment-status@v2
with:
token: "${{ github.token }}"
environment-url: ${{ steps.deployment.outputs.environment_url }}
log-url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
state: "success"
- name: Update deployment status (failure)
if: |
failure()
uses: chrnorm/deployment-status@v2
with:
token: "${{ github.token }}"
environment-url: ${{ steps.deployment.outputs.environment_url }}
log-url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
state: "failure"
delete-automatic-deployments:
name: Delete Automatic Deployments
runs-on: ubuntu-latest
needs: [deploy]
if: always()
steps:
- name: Delete previous automatic deployments
uses: actions/github-script@v7
env:
GITHUB_SHA_HEAD: ${{ github.sha }}
with:
script: |
const { GITHUB_SHA_HEAD } = process.env
const deployments = await github.rest.repos.listDeployments({
owner: context.repo.owner,
repo: context.repo.repo,
sha: GITHUB_SHA_HEAD
});
await Promise.all(
deployments.data.filter((d) => d.performed_via_github_app).map(async (deployment) => {
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.id,
state: 'inactive'
});
return github.rest.repos.deleteDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.id
});
})
);