-
Notifications
You must be signed in to change notification settings - Fork 5
255 lines (210 loc) · 7.27 KB
/
staging.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
name: Staging
on:
pull_request:
push:
env:
FIREBASE_CHANNEL_ID: "pr-${{github.event.number}}"
FIREBASE_PROJECT_ID: mm-dev-site-staging
FIREBASE_SERVICE_ACCOUNT: "${{ secrets.STAGING_FIREBASE_SERVICE_ACCOUNT }}"
jobs:
cache-keys:
name: Setup – Cache keys
runs-on: ubuntu-latest
outputs:
build: build-${{ steps.build.outputs.hash }}-v2
dot-cache: dot-cache-${{ github.event.number }}-v1
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/**', 'test/**', '**/package.json', '**/package-lock.json') }}"
- id: node-modules
run: echo "::set-output name=hash::${{ hashFiles('**/package-lock.json') }}"
build:
name: Build
needs: cache-keys
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
id: cache-node-modules
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 }}
- name: Get .cache cache
uses: actions/cache@v3
with:
path: |
.cache
key: ${{ needs.cache-keys.outputs.dot-cache }}
- if: steps.cached-build.outputs.cache-hit != 'true'
name: Build
env:
GATSBY_URL: https://dev.maxmind.com
run: npm run build
test-unit:
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
test-lint:
name: Test – Lint
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 linters
run: npm run lint
deploy-hosting:
name: Deploy – Hosting
needs: [cache-keys, build]
runs-on: ubuntu-latest
# Requires access to our secrets.
if: ${{ github.repository_owner == 'maxmind' && github.actor != 'dependabot[bot]' && github.event.pull_request.head.repo.fork == false }}
outputs:
hosting-url: ${{ steps.deploy-preview-channel.outputs.details_url }}
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 preview channel
id: deploy-preview-channel
uses: FirebaseExtended/action-hosting-deploy@4d0d0023f1d92b9b7d16dda64b3d7abd2c98974b # v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ env.FIREBASE_SERVICE_ACCOUNT }}"
expires: 7d
projectId: "${{ env.FIREBASE_PROJECT_ID }}"
channelId: "${{ env.FIREBASE_CHANNEL_ID }}"
env:
FIREBASE_CLI_PREVIEWS: hostingchannels
- name: Update robots and sitemap files for staging environments
env:
FIND_AND_REPLACE: s|https://dev.maxmind.com|${{ steps.deploy-preview-channel.outputs.details_url }}|g
run: |
sed -i "s/Allow:/Disallow:/g" public/robots.txt
sed -i "$FIND_AND_REPLACE" public/robots.txt
sed -i "$FIND_AND_REPLACE" public/sitemap.xml
sed -i "$FIND_AND_REPLACE" public/sitemap-pages.xml
- name: Deploy updated files staging environment files
uses: FirebaseExtended/action-hosting-deploy@4d0d0023f1d92b9b7d16dda64b3d7abd2c98974b # v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ env.FIREBASE_SERVICE_ACCOUNT }}"
expires: 30d
projectId: "${{ env.FIREBASE_PROJECT_ID }}"
channelId: "${{ env.FIREBASE_CHANNEL_ID }}"
env:
FIREBASE_CLI_PREVIEWS: hostingchannels
deploy-functions:
name: Deploy – Functions
needs: [cache-keys, build]
runs-on: ubuntu-latest
# Requires access to our secrets.
if: ${{ github.repository_owner == 'maxmind' && github.actor != 'dependabot[bot]' && github.event.pull_request.head.repo.fork == false }}
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
# Dependencies are needed here to run `npm exec -- firbase` command
- 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]
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: ${{ needs.deploy-hosting.outputs.hosting-url }}
run: npm run test:e2e