forked from coralproject/talk
-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (155 loc) · 5.18 KB
/
build-test-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
name: Build, Test, and Deploy
on:
workflow_dispatch:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
env:
DOCKERHUB_USERNAME: 'coralproject'
GOOGLE_CLOUD_BUCKET: 'coral-cdn'
IMAGE_REPOSITORY: 'coralproject/talk'
SENTRY_ORG: 'voxmedia'
SENTRY_PROJECT: 'coral'
jobs:
build-and-test:
name: Build, Test, and Deploy
runs-on: ubuntu-22.04
steps:
-
name: Checkout
uses: actions/checkout@v2
-
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.REPO_PATCHED_DEPLOY_KEY }}
-
name: Authenticate with GCP
id: 'auth'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GCR_JSON_KEY }}'
-
name: Set up Cloud SDK
uses: 'google-github-actions/setup-gcloud@v1'
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
-
name: Define SHORT_SHA with commit short sha
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
-
name: Define RC_TAG
run: echo "RC_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
-
name: Setup Node14.x
uses: actions/setup-node@v3
with:
node-version: '14.x'
-
name: Install npm 8
run: npm i -g [email protected] --registry=https://registry.npmjs.org
- name: npm Lockfile Version
uses: mansona/npm-lockfile-version@v1
with:
version: 2
-
name: Cache Dependencies
id: cache
uses: actions/cache@v3
with:
path: ./node_modules
key: modules-${{ hashFiles('package-lock.json') }}
restore-keys: npm-
-
name: npm ci
run: npm ci
-
name: Generate schemas and types
run: npm run generate
-
name: Lint Source Code
run: npm run lint
-
name: Lint Markdown
run: |
npm run doctoc
git diff --exit-code
-
name: Lint Versions
run: npx @coralproject/package-version-lint
-
name: Run Server Unit Tests
run: npm run test:server -- --ci --runInBand --reporters=default --reporters=jest-junit
-
name: Run Client Stream Unit Tests
run: npm run test:client:stream -- --ci --runInBand --reporters=default --reporters=jest-junit
-
name: Run Client Admin Unit Tests
run: npm run test:client:admin -- --ci --runInBand --reporters=default --reporters=jest-junit
-
name: Run Client Other Unit Tests
run: npm run test:client:other -- --ci --runInBand --reporters=default --reporters=jest-junit
-
name: Build
run: npm run build
-
name: Verify Bundle Size
run: ./node_modules/.bin/bundlesize --enable-github-checks
-
name: Verify Release Version
run: npx @coralproject/package-version-lint --expect ${RC_TAG/#v}
-
name: Create the Pre-Tag Names
run: |
echo "MAJOR=`echo ${RC_TAG/#v} | cut -d. -f1`" >> $GITHUB_ENV
echo "MINOR=`echo ${RC_TAG/#v} | cut -d. -f2`" >> $GITHUB_ENV
echo "PATCH=`echo ${RC_TAG/#v} | cut -d. -f3`" >> $GITHUB_ENV
-
name: Create Final Tag names
run: |
echo "MAJOR_TAG=${MAJOR}" >> $GITHUB_ENV
echo "MINOR_TAG=${MAJOR}.${MINOR}" >> $GITHUB_ENV
echo "PATCH_TAG=${MAJOR}.${MINOR}.${PATCH}" >> $GITHUB_ENV
-
name: Build, Tag, Push Major Tag
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ env.IMAGE_REPOSITORY }}:${{ env.MAJOR_TAG }}
build-args: |
REVISION_HASH=${{ env.GITHUB_SHA }}
-
name: Build, Tag, Push Minor Tag
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ env.IMAGE_REPOSITORY }}:${{ env.MINOR_TAG }}
build-args: |
REVISION_HASH=${{ env.GITHUB_SHA }}
-
name: Build, Tag, Push Patch Tag
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ env.IMAGE_REPOSITORY }}:${{ env.PATCH_TAG }}
build-args: |
REVISION_HASH=${{ env.GITHUB_SHA }}
-
name: Deploy Static Assets to GCS Bucket
run: |
CONTAINER_ID=$(docker create "coralproject/talk:${PATCH_TAG}")
docker cp "${CONTAINER_ID}:/usr/src/app/dist/static" static/
docker rm "${CONTAINER_ID}"
find ./static -type f -name "*.gz" -print -delete
gsutil -m -h "Cache-Control: public, max-age=86400, immutable" cp -r -z "js,css,map,txt,json" ./static/** "gs://${GOOGLE_CLOUD_BUCKET}/${PATCH_TAG}/"
-
name: Upload to Sentry
run: |
CONTAINER_ID=$(docker create "coralproject/talk:${PATCH_TAG}")
docker cp "${CONTAINER_ID}:/usr/src/app/dist" dist/
docker rm "${CONTAINER_ID}"
npx @sentry/cli -V
npx @sentry/cli releases files "coral@${PATCH_TAG}" upload-sourcemaps ./dist --auth-token ${{ secrets.SENTRY_AUTH_TOKEN }}