-
Notifications
You must be signed in to change notification settings - Fork 292
380 lines (322 loc) · 12 KB
/
publish.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
name: Publish
on:
push:
branches: [master, dev, release/*, new-navigation]
tags:
- '*q1-2024*'
- '*staging*'
- '*production*'
concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: Build Docker image and Helm Chart
runs-on: buildjet-8vcpu-ubuntu-2204
outputs:
wire_builds_target_branches: ${{ steps.output_target_branches.outputs.targets }}
image_tag: ${{ steps.push_docker_image.outputs.image_tag }}
release_name: ${{ steps.push_docker_image.outputs.release_name }}
chart_version: ${{ steps.bump_chart_version.outputs.chart_version }}
changelog: ${{ steps.generate_changelog.outputs.changelog }}
unit_tests_report: ${{ env.UNIT_TEST_REPORT_FILE }}
build_artifact: ${{ env.BUILD_ARTIFACT }}
env:
BUILD_DIR: server/dist/s3/
BUILD_ARTIFACT: ebs.zip
COMMIT_URL: ${{github.event.head_commit.url}}
COMMITTER: ${{github.event.head_commit.committer.name}}
CHANGELOG_FILE: './changelog.md'
UNIT_TEST_REPORT_FILE: './unit-tests.log'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18.16.x
cache: 'yarn'
- name: Set environment variables
run: |
echo "BRANCH_NAME=$(git branch --show-current)" >> $GITHUB_ENV
echo "TAG=$(git tag --points-at ${{github.sha}})" >> $GITHUB_ENV
- name: Print environment variables
run: |
echo -e "BRANCH_NAME = ${BRANCH_NAME}"
echo -e "TAG = ${TAG}"
echo -e "COMMIT_URL = ${COMMIT_URL}"
echo -e "COMMITTER = ${COMMITTER}"
- name: Install JS dependencies
run: yarn --immutable
- name: Update configuration
run: yarn configure
- name: Test
run: |
set -o pipefail
yarn test --detectOpenHandles=false 2>&1 | tee ${{ env.UNIT_TEST_REPORT_FILE }}
echo -e "COMMIT SHA = ${{ github.sha }}" >> ${{env.UNIT_TEST_REPORT_FILE}}
echo -e "TEST RUN DATE = $(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> ${{env.UNIT_TEST_REPORT_FILE}}
- uses: actions/upload-artifact@v4
with:
name: 'unit-tests-report'
path: ${{env.UNIT_TEST_REPORT_FILE}}
- name: Install AWS CLI
run: |
sudo apt-get update
sudo apt-get install -y awscli
- name: Upload unit-tests.log to S3
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-west-1
run: |
TIMESTAMP=$(date -u +'%Y%m%dT%H%M%SZ')
aws s3 cp ${{env.UNIT_TEST_REPORT_FILE}} s3://wire-webapp/unit-tests-${TIMESTAMP}-${{ github.sha }}.log
- name: Build
run: yarn build:prod
- uses: actions/upload-artifact@v4
with:
name: 'build-artifact'
path: '${{env.BUILD_DIR}}${{env.BUILD_ARTIFACT}}'
- uses: kanga333/variable-mapper@master
id: changelog
with:
key: '${{github.ref}}'
map: |
{
"production": {
"changelog_type": "production"
},
"staging": {
"changelog_type": "staging"
}
}
export_to: env
- name: Generate changelog
id: generate_changelog
if: ${{ env.changelog_type }}
run: |
yarn changelog:${{ env.changelog_type }} > ${{ env.CHANGELOG_FILE }}
echo "changelog=${{ env.CHANGELOG_FILE }}" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@v4
if: ${{ env.changelog_type }}
with:
name: 'changelog'
path: ${{ env.CHANGELOG_FILE }}
- name: Push Docker image
id: push_docker_image
env:
DOCKER_PASSWORD: ${{secrets.WEBTEAM_QUAY_PASSWORD}}
DOCKER_USERNAME: ${{secrets.WEBTEAM_QUAY_USERNAME}}
aws_secret_key: ${{secrets.WEBTEAM_AWS_SECRET_ACCESS_KEY}}
run: |
version_tag="${TAG:-$BRANCH_NAME}"
yarn docker "$version_tag" ./image_tag.txt
image_tag="$(cat ./image_tag.txt)"
echo "image_tag=$image_tag" >> $GITHUB_OUTPUT
packageVersion=$(cat ./package.json | jq -r '.version')
release_name="${TAG:-v${packageVersion}}"
echo "release_name=$release_name" >> $GITHUB_OUTPUT
- uses: azure/setup-helm@v4
with:
version: '3.12.2'
- name: Bump helm chart version
shell: bash
id: bump_chart_version
env:
AWS_ACCESS_KEY_ID: ${{ secrets.CHARTS_WEBAPP_AUTOMATION_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CHARTS_WEBAPP_AUTOMATION_AWS_SECRET_ACCESS_KEY }}
run: |
set -eo pipefail
image_tag="${{steps.push_docker_image.outputs.image_tag}}"
helm plugin install https://github.com/hypnoglow/helm-s3.git --version 0.15.1
helm repo add charts-webapp s3://public.wire.com/charts-webapp
if [[ "${{github.ref}}" =~ "/refs/tags" ]]; then
chart_version="$(./bin/chart-next-version.sh release)"
else
chart_version="$(./bin/chart-next-version.sh prerelease)"
fi
echo "chart_version=$chart_version" >> $GITHUB_OUTPUT
chart_patched="$(yq -Mr ".version = \"$chart_version\" | .appVersion = \"$image_tag\"" ./charts/webapp/Chart.yaml)"
echo "$chart_patched" > ./charts/webapp/Chart.yaml
helm package ./charts/webapp
helm s3 push --relative webapp-*.tgz charts-webapp
# generates a mapping between branches/tag to wire-build branches
- name: Define target branches in wireapp/wire-builds to bump
uses: kanga333/variable-mapper@master
id: output_target_branches
with:
key: '${{github.ref}}'
# TODO Add staging if we ever use a wire-builds as a source for staging (we use k8s)
# "staging": {
# "targets": "[\"TBD\"]"
# },
map: |
{
"production": {
"targets": "[\"main\"]"
},
"dev": {
"targets": "[\"dev\"]"
},
"q1-2024": {
"targets": "[\"q1-2024\"]"
}
}
export_to: log,output
publish_wire_builds:
name: Bump webapp chart in wire-builds
runs-on: ubuntu-latest
needs: build
if: ${{needs.build.outputs.wire_builds_target_branches}}
strategy:
matrix:
target_branch: ${{fromJSON(needs.build.outputs.wire_builds_target_branches)}}
steps:
- name: Check out wire-builds
uses: actions/checkout@v4
with:
repository: wireapp/wire-builds
token: ${{secrets.WIRE_BUILDS_WRITE_ACCESS_GH_TOKEN}}
ref: ${{matrix.target_branch}}
fetch-depth: 1
- name: Create new build in wire-build
shell: bash
run: |
set -eo pipefail
chart_version="${{needs.build.outputs.chart_version}}"
image_tag="${{needs.build.outputs.image_tag}}"
git config --global user.email "[email protected]"
git config --global user.name "Zebot"
for retry in $(seq 3); do
set +e
(
set -e
if (( retry > 1 )); then
echo "Retrying..."
fi
git fetch --depth 1 origin "${{ matrix.target_branch }}"
git checkout "${{ matrix.target_branch }}"
git reset --hard @{upstream}
build_json=$(cat ./build.json | \
./bin/set-chart-fields webapp \
"version=$chart_version" \
"repo=https://s3-eu-west-1.amazonaws.com/public.wire.com/charts-webapp" \
"meta.appVersion=$image_tag" \
"meta.commitURL=${{github.event.head_commit.url}}" \
"meta.commit=${{github.event.head_commit.id}}" \
| ./bin/bump-prerelease )
echo "$build_json" > ./build.json
git add build.json
git commit -m "Bump webapp to $chart_version"
git push origin "${{ matrix.target_branch }}"
)
if [ $? -eq 0 ]; then
echo "pushing to wire-builds succeeded"
break
else
echo "pushing to wire-builds FAILED (in retry $retry)"
fi
set -e
done
if (( $? != 0 )); then
echo "Retrying didn't help. Failing the step."
exit 1
fi
set_deployment_targets:
name: 'Set deployment targets'
runs-on: ubuntu-latest
needs: build
outputs:
deployment_targets: ${{env.targets}}
steps:
# generates a mapping between branches/tag to aws envs to deploy to
- uses: kanga333/variable-mapper@master
id: targets
with:
key: '${{github.ref}}'
map: |
{
"dev": {
"targets": "[\"wire-webapp-dev\", \"wire-webapp-edge\"]"
},
"master": {
"targets": "[\"wire-webapp-main\"]"
},
"production": {
"targets": "[\"wire-webapp-prod\"]"
},
"release/q1-2024": {
"targets": "[\"wire-webapp-mls\"]"
},
"staging": {
"targets": "[\"wire-webapp-staging\"]"
}
}
export_to: env
deploy_to_aws:
name: 'Deploy to live environments'
runs-on: ubuntu-latest
needs: [build, set_deployment_targets]
if: ${{needs.set_deployment_targets.outputs.deployment_targets}}
strategy:
matrix:
target: ${{fromJson(needs.set_deployment_targets.outputs.deployment_targets)}}
steps:
- uses: actions/download-artifact@v4
with:
name: 'build-artifact'
- name: Deploy to ${{matrix.target}}
uses: einaregilsson/beanstalk-deploy@v22
with:
application_name: Webapp
aws_access_key: ${{secrets.WEBTEAM_AWS_ACCESS_KEY_ID}}
aws_secret_key: ${{secrets.WEBTEAM_AWS_SECRET_ACCESS_KEY}}
deployment_package: ${{needs.build.outputs.build_artifact}}
environment_name: ${{matrix.target}}
region: eu-central-1
use_existing_version_if_available: true
version_description: ${{github.sha}}
version_label: '${{github.run_id}}-${{matrix.target}}'
wait_for_deployment: false
wait_for_environment_recovery: 150
create_gh_release:
name: 'Create Github release'
runs-on: ubuntu-latest
needs: [deploy_to_aws, build]
if: ${{ needs.build.outputs.changelog }}
outputs:
release_url: ${{ steps.release.outputs.url }}
steps:
- uses: actions/download-artifact@v4
with:
name: 'changelog'
- uses: actions/download-artifact@v4
with:
name: 'unit-tests-report'
- name: Create GitHub release
id: 'release'
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{github.token}}
with:
tag_name: ${{needs.build.outputs.release_name}}
body_path: ${{ needs.build.outputs.changelog }}
files: ${{ needs.build.outputs.unit_tests_report }}
draft: true
prerelease: ${{contains(needs.build.outputs.release_name, 'staging')}}
announce_deployment:
name: 'Announce deployment to wire chats'
runs-on: ubuntu-latest
needs: create_gh_release
steps:
- name: Announce staging release
if: ${{ needs.create_gh_release.outputs.release_url }}
uses: wireapp/[email protected]
with:
email: ${{secrets.WIRE_BOT_EMAIL}}
password: ${{secrets.WIRE_BOT_PASSWORD}}
conversation: '697c93e8-0b13-4204-a35e-59270462366a'
send_text: 'New release done ([full changelog](${{ needs.create_gh_release.outputs.release_url }})) 🚀'