-
Notifications
You must be signed in to change notification settings - Fork 5
214 lines (176 loc) · 5.89 KB
/
production.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
name: Production
on:
push:
branches:
- main
env:
FIREBASE_PROJECT_ID: mm-dev-site-production
FIREBASE_SERVICE_ACCOUNT: "${{ secrets.PRODUCTION_FIREBASE_SERVICE_ACCOUNT }}"
concurrency: production_deploy
jobs:
cache-keys:
name: Cache keys
runs-on: ubuntu-latest
outputs:
build: build-${{ steps.build.outputs.hash }}-v2
node-modules: node-modules-${{ steps.node-modules.outputs.hash }}-v1
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- id: build
run: echo "::set-output name=hash::${{ hashFiles('bin/**', 'content/**', 'firebase/**', 'functions/src/**', 'src/**', 'static/**', '**/package.json', '**/package-lock.json') }}"
- id: node-modules
run: echo "::set-output name=hash::${{ hashFiles('**/package-lock.json') }}"
build:
needs: cache-keys
name: Build
runs-on: ubuntu-latest
outputs:
is-cached-build: ${{ steps.cached-build.outputs.cache-hit }}
steps:
- name: Check Out repo
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Get cached dependencies
id: cache-node-modules
uses: actions/cache@v3
with:
path: |
node_modules
functions/node_modules
key: ${{ needs.cache-keys.outputs.node-modules }}
- if: steps.cache-node-modules.outputs.cache-hit != 'true'
name: Install dependencies
run: npm install
- name: Get cached build
id: cached-build
uses: actions/cache@v3
with:
path: |
functions/lib
public
firebase.json
key: ${{ needs.cache-keys.outputs.build }}
- if: steps.cached-build.outputs.cache-hit != 'true'
name: Build
env:
GATSBY_URL: https://dev.maxmind.com
run: npm run build
test-unit:
if: needs.build.outputs.is-cached-build != 'true'
name: Test – Unit
needs: [cache-keys, build]
runs-on: ubuntu-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Get cached dependencies
uses: actions/cache@v3
with:
path: |
node_modules
functions/node_modules
key: ${{ needs.cache-keys.outputs.node-modules }}
- name: Run unit tests
run: npm run test:unit
deploy-hosting:
name: Deploy – Hosting
needs: [cache-keys, build, test-unit]
# Only run this job if test jobs either ran successfully or were skipped
# because a previously tested build was cached.
# Inspired by https://github.com/actions/runner/issues/491#issuecomment-850884422
if: |
always() &&
(needs.test-unit.result == 'success' || needs.test-unit.result == 'skipped')
runs-on: ubuntu-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Get cached build
uses: actions/cache@v3
with:
path: |
functions/lib
public
firebase.json
key: ${{ needs.cache-keys.outputs.build }}
- name: Deploy Firebase live channel
uses: FirebaseExtended/action-hosting-deploy@4d0d0023f1d92b9b7d16dda64b3d7abd2c98974b # v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ env.FIREBASE_SERVICE_ACCOUNT }}"
projectId: ${{ env.FIREBASE_PROJECT_ID }}
channelId: live
deploy-functions:
name: Deploy - Functions
needs: [cache-keys, build, test-unit]
# Only run this job if test jobs either ran successfully or were skipped
# because a previously tested build was cached.
# Inspired by https://github.com/actions/runner/issues/491#issuecomment-850884422
if: |
always() &&
(needs.test-unit.result == 'success' || needs.test-unit.result == 'skipped')
runs-on: ubuntu-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Get cached build
uses: actions/cache@v3
with:
path: |
functions/lib
public
firebase.json
key: ${{ needs.cache-keys.outputs.build }}
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@ee9693ff89cdf73862b8a13988f6a71070e8fc58 # v0.2.1
with:
project_id: ${{ env.FIREBASE_PROJECT_ID }}
service_account_key: "${{ env.FIREBASE_SERVICE_ACCOUNT }}"
export_default_credentials: true
- name: Get cached dependencies
uses: actions/cache@v3
with:
path: |
node_modules
functions/node_modules
key: ${{ needs.cache-keys.outputs.node-modules }}
- name: Deploy all other Firebase resources
run: npm exec -- firebase deploy --except hosting --project ${{ env.FIREBASE_PROJECT_ID }} --force
test-e2e:
name: Test – End-to-end
needs: [cache-keys, deploy-hosting, deploy-functions]
# Force this step to run after successful deployment jobs
if: |
always() &&
needs.deploy-hosting.result == 'success' &&
needs.deploy-functions.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Get cached dependencies
uses: actions/cache@v3
with:
path: |
node_modules
functions/node_modules
key: ${{ needs.cache-keys.outputs.node-modules }}
- name: Run end-to-end tests
env:
E2E_TARGET_URL: https://dev.maxmind.com
run: npm run test:e2e