-
Notifications
You must be signed in to change notification settings - Fork 18
230 lines (222 loc) · 8.42 KB
/
non-serverless-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
# This action is to orchestrate the non-serverless stuffs deployment
# to make sure playwright e2e test is run post-deployments.
# The reason we need to do this hack is because there's currently no way
# to use "workflow_run" trigger with requirement being all depdency workflows'
# complete. More here: https://github.com/community/community/discussions/16059
# Side note: we need to follow .github/workflows convention https://docs.github.com/en/actions/using-workflows/reusing-workflows
name: Deploy and E2E test non-serverless stuffs
on:
push:
branches:
- staging
- master
env:
SLACK_CHANNEL_ID: C04H0FTGS5P # postman-deploys
concurrency: deploy-non-serverless-${{ github.ref }}
jobs:
slack-prepare:
name: Escape commit message to send in slack
runs-on: ubuntu-latest
outputs:
commit_message: ${{ steps.extract-message.outputs.commit_message }}
steps:
- id: extract-message
run: |
message=$MESSAGE
# taking only the first line and removing double quotes and backslashes from string value
message="$(echo $message | sed -z 's/\\n.*//g; s/"//g; s/\\//g')"
echo $message
echo "commit_message=$message" >> $GITHUB_OUTPUT
env:
MESSAGE: ${{ toJSON(github.event.head_commit.message) }}
slack-started:
name: Send slack message when deployment starts
runs-on: ubuntu-latest
outputs:
message_id: ${{ steps.slack.outputs.ts }}
needs:
- slack-prepare
steps:
- uses: slackapi/slack-github-action@v1.23.0
id: slack
with:
channel-id: ${{ env.SLACK_CHANNEL_ID }}
payload: |
{
"attachments": [
{
"color": "warning",
"fields": [
{
"title": "Deployment",
"value": "Non serverless stuffs",
"short": true
},
{
"title": "Status",
"value": "STARTED",
"short": true
},
{
"title": "Workflow Run",
"value": "<https://github.com/opengovsg/postmangovsg/actions/runs/${{ github.run_id }} | ${{ needs.slack-prepare.outputs.commit_message }}>",
"short": true
},
{
"title": "Environment",
"value": "${{ github.ref == 'refs/heads/master' && 'production' || 'staging' }}",
"short": true
}
],
"footer_icon": "https://github.githubassets.com/favicon.ico",
"footer": "<https://github.com/opengovsg/postmangovsg | opengovsg/postmangovsg>"
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
deploy-backend:
name: Deploy backend to AWS Elastic Beanstalk
uses: ./.github/workflows/deploy-eb.yml
secrets: inherit
deploy-worker:
name: Deploy worker to AWS Elastic Container Service
uses: ./.github/workflows/deploy-worker.yml
secrets: inherit
deploy-frontend:
name: Deploy frontend to AWS Amplify
uses: ./.github/workflows/deploy-frontend.yml
secrets: inherit
e2e-test:
needs:
- deploy-backend
- deploy-frontend
- deploy-worker
name: End-to-end Test
uses: ./.github/workflows/e2e.yml
secrets: inherit
# revert-on-e2e-failure:
# runs-on: ubuntu-latest
# needs:
# - deploy-backend
# - deploy-frontend
# - deploy-worker
# - e2e-test
# if: always()
# steps:
# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v2
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-region: ap-southeast-1
# - run: |
# if [ "${{ needs.e2e-test.outputs.e2e_result }}" = "failure" ] && [ "${{ github.ref }}" = "refs/heads/master" ]; then
# ${{ needs.deploy-worker.outputs.sending_revert_command }}
# ${{ needs.deploy-worker.outputs.logging_revert_command }}
# ${{ needs.deploy-frontend.outputs.revert_command }}
# ${{ needs.deploy-backend.outputs.revert_command_backend }}
# ${{ needs.deploy-backend.outputs.revert_command_callback }}
# fi
slack-success:
needs:
- slack-prepare
- slack-started
- e2e-test
if: success()
name: Send Slack message about successful build
runs-on: ubuntu-latest
steps:
- uses: slackapi/slack-github-action@v1.23.0
with:
channel-id: ${{ env.SLACK_CHANNEL_ID }}
update-ts: ${{ needs.slack-started.outputs.message_id }}
payload: |
{
"attachments": [
{
"color": "good",
"fields": [
{
"title": "Deployment",
"value": "Non serverless stuffs",
"short": true
},
{
"title": "Status",
"value": "SUCCESSFUL",
"short": true
},
{
"title": "Workflow Run",
"value": "<https://github.com/opengovsg/postmangovsg/actions/runs/${{ github.run_id }} | ${{ needs.slack-prepare.outputs.commit_message }}>",
"short": true
},
{
"title": "Environment",
"value": "${{ github.ref == 'refs/heads/master' && 'production' || 'staging' }}",
"short": true
}
],
"footer_icon": "https://github.githubassets.com/favicon.ico",
"footer": "<https://github.com/opengovsg/postmangovsg | opengovsg/postmangovsg>"
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
slack-failure:
needs:
- slack-prepare
- slack-started
# we include the deploy jobs here as we want to update the message to FAILED
# as well when the deploy jobs fail. We didn't need to include for succes
# because e2e-test has a pre-requisite of deploy jobs to have succeeded
- deploy-backend
- deploy-frontend
- deploy-worker
- e2e-test
if: failure()
name: Send Slack message about failed build and tag engineers if it's prod
runs-on: ubuntu-latest
steps:
- uses: slackapi/slack-github-action@v1.23.0
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
DEPLOY_ENV: ${{ github.ref == 'refs/heads/master' && 'production' || 'staging' }}
with:
channel-id: ${{ env.SLACK_CHANNEL_ID }}
update-ts: ${{ needs.slack-started.outputs.message_id }}
payload: |
{
"text": "${{ env.DEPLOY_ENV == 'production' && '<!subteam^S03JWLMTBTK|postmangineers>' || '' }}",
"attachments": [
{
"color": "danger",
"fields": [
{
"title": "Deployment",
"value": "Non serverless stuffs",
"short": true
},
{
"title": "Status",
"value": "FAILED",
"short": true
},
{
"title": "Workflow Run",
"value": "<https://github.com/opengovsg/postmangovsg/actions/runs/${{ github.run_id }} | ${{ needs.slack-prepare.outputs.commit_message }}>",
"short": true
},
{
"title": "Environment",
"value": "${{ env.DEPLOY_ENV }}",
"short": true
}
],
"footer_icon": "https://github.githubassets.com/favicon.ico",
"footer": "<https://github.com/opengovsg/postmangovsg | opengovsg/postmangovsg>"
}
]
}