-
Notifications
You must be signed in to change notification settings - Fork 310
287 lines (287 loc) · 10.3 KB
/
e2e.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
name: End-to-end Tests
concurrency:
group: e2e-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
paths:
- "*.go"
- "go.mod"
- "go.sum"
- "pkg/**"
- "tools/**"
- "config/**"
- "!config/stack/ttn-lw-stack.yml"
- "package.json"
- "pkg/webui/**"
- "sdk/js/**"
- "yarn.lock"
- "cypress/**"
- "docker-compose.yml"
- ".github/workflows/e2e.yml"
env:
TTN_LW_LOG_LEVEL: debug
TTN_LW_IS_EMAIL_PROVIDER: dir
TTN_LW_IS_EMAIL_DIR: .dev/email
TTN_LW_EXPERIMENTAL_FEATURES: is.bunstore
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
CYPRESS_FAIL_FAST: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
determine-if-required:
name: Determine if run is required
runs-on: ubuntu-22.04
outputs:
needs-to-run: ${{ steps.check-result.outputs.passed != 'true' }}
hash: ${{ steps.get-hash.outputs.hash }}
timeout-minutes: 5
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: false
- name: Get hash of code files
id: get-hash
run: echo "hash=${{ hashFiles('.github/workflows/e2e.yml', '*.go', 'go.mod', 'go.sum', 'pkg/**', 'tools/**', 'config/**', 'package.json', 'pkg/webui/**', 'sdk/js/**', 'yarn.lock', 'cypress/**', 'docker-compose.yml') }}" >> $GITHUB_OUTPUT
- name: Get the cached result
id: run-cache
uses: actions/cache@v3
with:
path: .cache/passed
key: run-cache-${{ steps.get-hash.outputs.hash }}-${{ github.run_id }}
restore-keys: |
run-cache-${{ steps.get-hash.outputs.hash }}
- name: Check cached result connected to the hashed files (if any)
id: check-result
continue-on-error: true
run: test -f .cache/passed && echo "passed=$(cat .cache/passed)" >> $GITHUB_OUTPUT
preparation:
name: Run preparations
runs-on: ubuntu-22.04
needs: determine-if-required
if: needs.determine-if-required.outputs.needs-to-run == 'true'
timeout-minutes: 30
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Install Go and Dependencies
uses: ./.github/actions/install-go-and-deps
- name: Build Mage
uses: ./.github/actions/build-mage
- name: Install Node and Dependencies
uses: ./.github/actions/install-node-and-deps
- name: Initialize SQL dump cache
id: db-cache
uses: actions/cache@v3
with:
path: |
.env/cache/database.pgdump
.env/admin_api_key.txt
key: db-cache-${{ hashFiles('pkg/identityserver/store/**/*.go', 'cmd/ttn-lw-stack/commands/is-db.go', '.github/workflows/e2e.yml', 'docker-compose.yml') }}
- name: Initialize device repository index cache
id: dr-index-cache
uses: actions/cache@v3
with:
path: data/lorawan-devices-index
key: dr-index-cache-${{ hashFiles('data/lorawan-devices') }}
- name: Create device repository index
run: tools/bin/mage dev:initDeviceRepo
if: steps.dr-index-cache.outputs.cache-hit != 'true'
- name: Run test preparations
if: steps.db-cache.outputs.cache-hit != 'true'
run: tools/bin/mage -v dev:dbStop dev:dbErase dev:dbStart dev:initStack dev:sqlDump
- name: Build Frontend
uses: ./.github/actions/build-frontend
- name: Initialize build cache
id: build-cache
uses: actions/cache@v3
with:
path: ttn-lw-stack
key: build-cache-${{ hashFiles('go.mod', 'go.sum', 'pkg/**', 'config/**', 'cmd/**') }}
- name: Build TTS
if: steps.build-cache.outputs.cache-hit != 'true'
run: go build ./cmd/ttn-lw-stack
- name: Zip build artifacts
run: zip -r build.zip .env/cache/database.pgdump .env/admin_api_key.txt data/lorawan-devices-index public ttn-lw-stack tools/bin/mage
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: build-files
path: build.zip
end-to-end:
name: Main frontend end-to-end tests (Chrome)
runs-on: ubuntu-22.04
env:
NODE_ENV: development
CYPRESS_MACHINE_NUMBER: ${{ matrix.machines }}
strategy:
matrix:
machines: [1, 2, 3, 4]
needs: [determine-if-required, preparation]
if: needs.determine-if-required.outputs.needs-to-run == 'true'
timeout-minutes: 15
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Install Go and Dependencies
uses: ./.github/actions/install-go-and-deps
- name: Build Mage
uses: ./.github/actions/build-mage
- name: Install Node and Dependencies
uses: ./.github/actions/install-node-and-deps
- name: Upgrade Google Chrome
run: |
sudo apt-get update
sudo apt-get --only-upgrade install google-chrome-stable
google-chrome --version
- uses: actions/download-artifact@v3
name: Download build artifacts
with:
name: "build-files"
- name: Download last failed spec
uses: dawidd6/action-download-artifact@v2
continue-on-error: true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow: e2e.yml
branch: ${{ github.head_ref }}
workflow_conclusion: completed
name: cypress-failed-test-spec
search_artifacts: true
- name: Read failed spec file
id: get-failed-spec
continue-on-error: true
run: |
sed -i 's/\.\.\///g' .failed-specs-*.txt
sed -i 's|/integration/|/e2e/|' .failed-specs-*.txt
echo "failed-test=$(paste -d , .failed-specs-*.txt)" >> $GITHUB_OUTPUT
echo "neg-failed-test=!$(paste -d ',!' .failed-specs-*.txt)" >> $GITHUB_OUTPUT
- name: Unzip build artifacts
run: unzip -o build.zip
- name: Generate certs
run: tools/bin/mage dev:certificates
- name: Restore initialized sql db
run: tools/bin/mage -v dev:dbStart dev:sqlRestore
- name: Run stack
run: tools/bin/mage dev:startDevStack &
- name: Run previously failed test first
uses: cypress-io/github-action@v6
if: steps.get-failed-spec.outputs.failed-test != ''
with:
config-file: config/cypress.config.js
config: baseUrl=https://localhost:8885
record: true
parallel: true
browser: chrome
group: previously-failed-${{ needs.determine-if-required.outputs.hash }}
spec: ${{ steps.get-failed-spec.outputs.failed-test }}
- name: Run frontend end-to-end tests
uses: cypress-io/github-action@v6
with:
config-file: config/cypress.config.js
config: baseUrl=https://localhost:8885
record: true
parallel: true
browser: chrome
group: main-${{ needs.determine-if-required.outputs.hash }}
spec: |
**/*
!cypress/e2e/smoke/smoke.spec.js
${{ steps.get-failed-spec.outputs.neg-failed-test }}
- name: Upload logs
uses: actions/upload-artifact@v3
if: failure()
with:
name: logs
path: .cache/devStack.log
- name: Upload screenshots for failed tests
uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
- name: Upload name of failing test
uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-failed-test-spec
path: .cache/.failed-specs-*.txt
cross-browser-smoke:
name: Cross-browser smoke tests (Firefox 102.3.0 ESR)
runs-on: ubuntu-22.04
env:
NODE_ENV: development
needs: [determine-if-required, preparation]
if: needs.determine-if-required.outputs.needs-to-run == 'true'
timeout-minutes: 15
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Install Go and Dependencies
uses: ./.github/actions/install-go-and-deps
- name: Build Mage
uses: ./.github/actions/build-mage
- name: Install Node and Dependencies
uses: ./.github/actions/install-node-and-deps
- uses: actions/download-artifact@v3
name: Download build artifacts
with:
name: "build-files"
- name: Unzip build artifacts
run: unzip -o build.zip
- name: Install FF 102.3.0 ESR
run: |
wget --no-verbose -O /tmp/firefox.tar.bz2 https://download-installer.cdn.mozilla.net/pub/firefox/releases/102.3.0esr/linux-x86_64/en-US/firefox-102.3.0esr.tar.bz2
tar -C /opt -xjf /tmp/firefox.tar.bz2
rm /tmp/firefox.tar.bz2
sudo ln -fs /opt/firefox/firefox /usr/bin/firefox
- name: Generate certs
run: tools/bin/mage dev:certificates
- name: Restore initialized sql db
run: tools/bin/mage dev:dbStart dev:sqlRestore
- name: Run stack
run: tools/bin/mage dev:startDevStack &
- name: Run end-to-end smoke tests (Firefox)
uses: cypress-io/github-action@v6
with:
config-file: config/cypress.config.js
config: baseUrl=https://localhost:8885
browser: firefox
record: true
spec: cypress/e2e/smoke/smoke.spec.js
- name: Upload logs
uses: actions/upload-artifact@v3
if: failure()
with:
name: logs
path: .cache/devStack.log
- name: Upload screenshots for failed tests
uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
cache-result:
name: Write result cache
runs-on: ubuntu-22.04
needs: [preparation, end-to-end, cross-browser-smoke, determine-if-required]
timeout-minutes: 5
steps:
- name: Setup result cache to skip redundant runs
id: run-cache
uses: actions/cache@v3
with:
path: .cache/passed
key: run-cache-${{ needs.determine-if-required.outputs.hash }}
- name: Create result file for caching
run: mkdir -p .cache && echo true > .cache/passed