-
Notifications
You must be signed in to change notification settings - Fork 39
273 lines (235 loc) · 9.97 KB
/
app-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
name: Deploy App
on:
push:
paths-ignore:
- 'docs/**'
branches:
- master
- prod
jobs:
build:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: 10
- name: Get Cache Settings
id: cache-settings
run: |
echo "::set-output name=dir::$(yarn cache dir)"
echo "::set-output name=firebase-tools::$(yarn list -s --depth=0 --pattern firebase-tools | tail -n 1 | sed 's/.*@//g')"
- name: Cache App Dependencies
uses: actions/cache@v1
with:
path: ${{ steps.cache-settings.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- name: Cache Firebase Emulator Binaries
uses: actions/cache@v1
with:
path: ~/.cache/firebase/emulators
key: ${{ runner.os }}-firebase-${{ steps.cache-settings.outputs.firebase-tools }}
- name: Install Dependencies
env:
CYPRESS_INSTALL_BINARY: 0 # Skip installing of cypress
run: |
yarn install --frozen-lockfile
yarn --cwd functions install --frozen-lockfile
- name: Archive Error Logs
uses: actions/upload-artifact@v2
if: failure()
with:
name: error-logs
path: yarn-error.log
- name: Verify Functions
run: |
yarn functions:build
yarn --cwd functions test:cov || echo "::warning::Functions unit tests failed"
- name: Upload Functions Test Coverage
uses: codecov/codecov-action@v1
with:
file: functions/coverage/lcov.info
- name: Expose Application Environment Variables
env:
GITHUB_REF: ${{ github.ref }}
# Firebase token needed to authenticate firebase-tools to be able to load app configs
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
run: |
set -o pipefail
gitBranch=${GITHUB_REF##*/}
# Find the config associated to the firebase project in .firebaserc
gcloudProject=$(cat .firebaserc | jq -r --arg alias "$gitBranch" '.projects[$alias]')
echo Exporting Firebase SDK Config for $gcloudProject project...
# Use firebase SDK API to get the app's configuration (databaseURL is removed since it is set to the emulator URL above)
firebaseConfig=$($(yarn bin)/firebase --project $gcloudProject apps:sdkconfig WEB \
$($(yarn bin)/firebase --project $gcloudProject apps:list WEB | grep fireadmin | awk '{ print $4}') | \
tr '\n' ' ' | \
sed 's/.*initializeApp(//g' | \
sed 's/);//g' | \
jq -r 'to_entries[] | [.key, (.value | tojson)] | join("::")' | \
sed 's/:"/:/g; s/^/echo \"::set-env name=REACT_APP_FIREBASE_/g' \
)
# Set other app configs (settings within .firebaserc in the ci.setEnv section)
$(yarn bin)/firebase-ci setEnv
echo Begin evaluating project config to export as environment variables:
# Loop through each line of config and evaluate to export env vars
while IFS= read -r line; do
echo Evaluating: $line
eval $line
done <<< "$firebaseConfig"
- name: Verify App
run: |
yarn lint
- name: Build App
run: |
yarn build
# - name: Archive Build Artifact
# uses: actions/upload-artifact@v2
# with:
# name: app-build
# path: build
- name: Deploy to Firebase
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
GITHUB_REF: ${{ github.ref }}
run: |
targets=hosting:app$(if [ "${GITHUB_REF##*/}" = "stage" ]; then echo "Stage"; fi;),functions,storage,database,firestore
echo Deploying targets: $targets
$(yarn bin)/firebase-ci deploy --force --only $targets
# Write new version to core database (causes client to refresh)
- name: Update Version In Database
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
GITHUB_REF: ${{ github.ref }}
run: |
gitBranch=${GITHUB_REF##*/}
packageName=$(cat package.json | jq -r '.name')
packageVersion=$(cat package.json | jq -r '.version')
gcloudProject=$(cat .firebaserc | jq -r --arg alias "$gitBranch" '.projects[$alias] // .projects.default')
echo "::set-env name=PACKAGE_VERSION::$packageVersion"
echo Updating DB path \"/versionInfo/current\" value to version \"$packageVersion\"
$(yarn bin)/firebase database:update \
-d "$(jq -n --arg version "$packageVersion" '{current: $version}')" \
-y --project $gcloudProject \
"/versionInfo"
- name: Check if version has been updated
if: github.ref == 'refs/heads/prod'
id: check
uses: EndBug/version-check@v1
- name: Create Release In Sentry
if: github.ref == 'refs/heads/prod' && steps.check.outputs.changed == 'true'
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: pruvit
run: |
version=$(cat package.json | jq .version -r)
gitBranch=${GITHUB_REF##*/}
envName=$(if [ $gitBranch == "master" ]; then echo staging; else echo $gitBranch; fi;)
releaseName=$envName@$version
export SENTRY_PROJECT=fireadmin
echo ""
echo Creating Sentry release \"$releaseName\" for project \"$SENTRY_PROJECT\"
$(yarn bin)/sentry-cli releases new $releaseName
echo Uploading source maps to Sentry...
$(yarn bin)/sentry-cli releases files $releaseName upload-sourcemaps ./build/static/js --no-rewrite
echo Associating commits with the release...
$(yarn bin)/sentry-cli releases set-commits --auto $version
echo Finalizing the release...
$(yarn bin)/sentry-cli releases finalize $releaseName
echo Marking new release as deployed...
$(yarn bin)/sentry-cli releases deploys $releaseName new -e $envName
echo Release created successfully
- name: Create Release
if: github.ref == 'refs/heads/prod' && steps.check.outputs.changed == 'true'
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ github.token }}
with:
tag_name: v${{ env.PACKAGE_VERSION }}
release_name: v${{ env.PACKAGE_VERSION }}
draft: false
prerelease: false
# # Uncomment following job to enable UI testing after deployment
# ui-tests:
# name: UI Test Hosted App
# needs: build
# runs-on: ubuntu-16.04
# if: ${{ env.RUN_HOSTED_TESTS }} == true && github.ref == 'refs/heads/stage'
# strategy:
# fail-fast: false
# matrix:
# # Run multiple copies of the current job in parallel
# containers: [1, 2, 3, 4]
# steps:
# - name: Setup Node
# uses: actions/setup-node@v1
# with:
# node-version: 10
# - name: Checkout Repo
# uses: actions/checkout@v2
# - name: Get yarn cache
# id: yarn-cache
# run: echo "::set-output name=dir::$(yarn cache dir)"
# - name: Cache npm dependencies
# uses: actions/cache@v1
# with:
# path: ${{ steps.yarn-cache.outputs.dir }}
# key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
# - name: Get Library Versions For Binary Caching
# id: dep-versions
# run: |
# echo "::set-output name=cypress::$(cat package.json | jq -r .devDependencies.cypress)"
# - name: Cache Cypress Binary
# uses: actions/cache@v1
# with:
# path: ~/.cache/Cypress
# key: ${{ runner.os }}-cypress-${{ steps.dep-versions.outputs.cypress }}
# # Install is run separately from test so that dependencies are available
# # for other steps like Get Project Info and build test environment config
# - name: Install Dependencies
# run: |
# yarn install --frozen-lockfile
# $(yarn bin)/cypress verify
# - name: Archive Error Logs
# uses: actions/upload-artifact@v1
# if: failure()
# with:
# name: test-error-logs
# path: yarn-error.log
# - name: Set Test Environment Settings
# id: emulator-settings
# run: |
# export GIT_BRANCH=${GITHUB_REF##*/}
# export GCLOUD_PROJECT=$(cat .firebaserc | jq -r --arg GIT_BRANCH "$GIT_BRANCH" '.projects[$GIT_BRANCH] // .projects.master')
# echo "::set-output name=GCLOUD_PROJECT::$GCLOUD_PROJECT"
# echo "::set-env name=CYPRESS_BASE_URL::https://$GCLOUD_PROJECT.firebaseapp.com"
# # Cypress action manages installing/caching npm dependencies and Cypress binary.
# # Because of "record" and "parallel" parameters these containers will load
# # balance all found tests among themselves. The step tests a version of the app
# # which is running locally in the container on port 3000
# - name: Cypress Run
# uses: cypress-io/github-action@v1
# with:
# # we have already installed all dependencies above
# install: false
# browser: chrome
# tag: hosted
# parallel: true
# record: true
# headless: true
# group: 'UI Tests'
# env:
# # TODO: Look into if this can be moved to an npm script
# TZ: America/Los_Angeles
# CI: true
# # Pass the Dashboard record key as an environment variable
# GITHUB_HEAD_REF: ${{ github.head_ref }}
# GITHUB_REF: ${{ github.ref }}
# FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
# SERVICE_ACCOUNT: ${{ secrets.SERVICE_ACCOUNT }}
# CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# CYPRESS_TEST_UID: ${{ secrets.TEST_UID }}