-
-
Notifications
You must be signed in to change notification settings - Fork 128
299 lines (287 loc) · 10.5 KB
/
Copy pathvalidate.yaml
File metadata and controls
299 lines (287 loc) · 10.5 KB
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
288
289
290
291
292
293
294
295
296
297
298
299
name: Validate
on:
pull_request:
branches: [main]
push:
branches: [main]
permissions:
contents: read
statuses: write
env:
DOCKER_APP_IMAGE_NAME: 'ghcr.io/hasadna/open-bus-map-search/open-bus-map-search'
DOCKER_APP_IMAGE_TAG: 'latest'
APPLITOOLS_API_KEY: ${{ secrets.APPLITOOLS_API_KEY }}
APPLITOOLS_BATCH_ID: ${{ github.event.pull_request.head.sha }}
APPLITOOLS_LOG_DIR: ./logs
APPLITOOLS_SHOW_LOGS: true
jobs:
local-tests:
name: Local Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24
cache: 'npm'
- name: Check for yarn.json
run: |
if [ -f yarn.json ]; then
echo "::error file=yarn.json::yarn.json is being added"
exit 1
fi
- name: Ensure package-lock.json exists
run: |
if [ ! -f package-lock.json ]; then
echo "::error file=package-lock.json::package-lock.json is being removed"
exit 1
fi
- name: Validate package-lock.json is updated
run: |
if ! npm ci; then
echo "::error file=package-lock.json::package-lock.json is not updated"
exit 1
fi
- name: Run linter
run: npm run lint
- name: Check for circular dependencies
run: npx madge --extensions js,ts --circular .
build:
name: Docker Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Generate hash.txt with commit hash
run: echo "$(git rev-parse --short HEAD)" >> public/hash.txt
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and export Docker image
uses: docker/build-push-action@v6
with:
context: .
tags: ${{ env.DOCKER_APP_IMAGE_NAME }}:${{ env.DOCKER_APP_IMAGE_TAG }}
outputs: type=docker, dest=/tmp/docker-image.tar
- name: Upload Docker image artifact
uses: actions/upload-artifact@v7
with:
name: docker-image
path: /tmp/docker-image.tar
build-outside-docker:
name: Node.js Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build application
run: npm run build
- name: Build Storybook
run: npm run build-storybook
test:
name: Application & Playwright Tests
runs-on: ubuntu-latest
needs: [build, build-outside-docker]
steps:
- name: Set timezone
run: echo "TZ=Asia/Jerusalem" >> $GITHUB_ENV
- name: Download Docker image artifact
uses: actions/download-artifact@v4
with:
name: docker-image
path: /tmp
- name: Load Docker image
run: docker load -i /tmp/docker-image.tar
- name: Start application container
run: docker run -d -p 3000:80 ${{ env.DOCKER_APP_IMAGE_NAME }}:${{ env.DOCKER_APP_IMAGE_TAG }}
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v6
with:
node-version: 24
cache: 'npm'
- name: Configure blocked external hosts
uses: ./.github/actions/block-network
- name: Validate hash.txt endpoint
run: |
response=$(curl -s -w "%{http_code}" -o /tmp/hash.txt http://localhost:3000/hash.txt)
http_code=${response: -3}
if [ "$http_code" -ne 200 ]; then
echo "Error: HTTP request failed with status code $http_code"
exit 1
fi
mime_type=$(file --mime-type -b /tmp/hash.txt)
if [ "$mime_type" != "text/plain" ]; then
echo "Error: hash.txt does not have MIME type text/plain. Found: $mime_type"
exit 1
fi
content_length=$(wc -c < /tmp/hash.txt | xargs)
if [ "$content_length" -ge 100 ]; then
echo "Error: hash.txt content exceeds 100 characters. Length: $content_length"
exit 1
fi
echo "hash.txt is valid with MIME type $mime_type and length $content_length characters."
- name: Install Dependencies and Playwright
run: npm ci
- name: Install Playwright browser dependencies
timeout-minutes: 15
run: npx playwright install chromium
- name: Run Playwright tests
run: npm test
- name: Prepare Playwright artifact directory
if: always()
run: |
mkdir -p playwright-artifact
if [ -d test-results ]; then cp -r test-results/* playwright-artifact/; fi
if [ -d playwright-report ]; then cp -r playwright-report/* playwright-artifact/; fi
touch playwright-artifact/.keep
- name: Upload Playwright test artifact
if: always()
uses: actions/upload-artifact@v7
with:
name: playwright-test
path: playwright-artifact
- name: Upload logs if exists
if: always()
uses: actions/upload-artifact@v7
with:
name: logs-test
path: logs
if-no-files-found: warn
storybook-test:
name: Storybook Visual Tests
runs-on: ubuntu-22.04 # not working whit ubuntu 23+
needs: [build, build-outside-docker]
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Configure blocked external hosts
uses: ./.github/actions/block-network
- name: Prepare for Testing
run: |
echo "SHORT_SHA=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-7)" >> $GITHUB_ENV
- name: Download Docker image artifact
uses: actions/download-artifact@v4
with:
name: docker-image
path: /tmp
- name: Load Docker image
run: docker load -i /tmp/docker-image.tar
- name: Start application container
run: docker run -d -p 3000:80 ${{ env.DOCKER_APP_IMAGE_NAME }}:${{ env.DOCKER_APP_IMAGE_TAG }}
- run: export APPLITOOLS_SHOW_LOGS=true && export APPLITOOLS_LOG_DIR=./logs
- run: npm i -g @applitools/eyes-storybook
- name: Run Storybook visual tests
if: env.APPLITOOLS_API_KEY
env:
APPLITOOLS_BATCH_NAME: open-bus-map-search/${{ github.ref }}/${{ env.SHORT_SHA }}/storybook
run: npm run test:storybook -- --storybook-url http://localhost:3000/storybook/index.html
- name: Upload logs if exists
if: always()
uses: actions/upload-artifact@v7
with:
name: logs-storybook-test
path: logs
if-no-files-found: warn
visual-test:
name: Playwright Visual Tests
runs-on: ubuntu-latest
needs: [build, build-outside-docker]
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Configure blocked external hosts
uses: ./.github/actions/block-network
- name: Prepare for Testing
run: |
echo "SHORT_SHA=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-7)" >> $GITHUB_ENV
- uses: actions/setup-node@v6
with:
node-version: 24
cache: 'npm'
- name: Install Dependencies and Playwright
run: npm ci
- name: Install Playwright browser dependencies
timeout-minutes: 15
run: npx playwright install chromium
- name: Run Playwright Visual Tests
env:
APPLITOOLS_BATCH_NAME: open-bus-map-search/${{ github.ref }}/${{ env.SHORT_SHA }}/
run: npm run test:e2e:visual
- name: Prepare Playwright artifact directory
if: always()
run: |
mkdir -p playwright-artifact
if [ -d test-results ]; then cp -r test-results/* playwright-artifact/; fi
if [ -d playwright-report ]; then cp -r playwright-report/* playwright-artifact/; fi
touch playwright-artifact/.keep
- name: Upload Playwright test artifact
if: always()
uses: actions/upload-artifact@v7
with:
name: playwright-visual-test
path: playwright-artifact
- name: Upload logs if exists
if: always()
uses: actions/upload-artifact@v7
with:
name: logs-visual-test
path: logs
if-no-files-found: warn
publish-test-results:
name: Publish Test Results
runs-on: ubuntu-latest
needs: [test]
if: always() && github.event.repository.fork == false && github.actor != 'dependabot[bot]'
env:
AWS_KEY_ID: ${{ secrets.AWS_KEY_ID }}
steps:
- name: Download Playwright test artifact
uses: actions/download-artifact@v4
with:
name: playwright-test
path: test-results
- name: Publish test results to S3
uses: shallwefootball/s3-upload-action@master
if: always() && env.AWS_KEY_ID != ''
id: s3-trace
continue-on-error: true
with:
aws_key_id: ${{env.AWS_KEY_ID}}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
aws_bucket: noam-gaash.co.il
source_dir: test-results
destination_dir: ${{ github.run_id }}/open-bus/${{ github.event.pull_request.head.sha }}/test-results
- name: Set commit status for test results
uses: myrotvorets/set-commit-status-action@master
if: always() && env.AWS_KEY_ID != ''
with:
sha: ${{ github.event.pull_request.head.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
description: 'Playwright html report with traces'
status: ${{needs.test.result}}
context: 'Test results (click to see!)'
targetUrl: 'https://s3.amazonaws.com/noam-gaash.co.il/${{ github.run_id }}/open-bus/${{ github.event.pull_request.head.sha }}/test-results/index.html'
close-visual-batches:
name: Close Applitools Visual Test Batches
runs-on: ubuntu-latest
needs: [visual-test, storybook-test]
if: always() && github.event.repository.fork == false && github.actor != 'dependabot[bot]'
steps:
- name: Close Applitools batches
run: |
export APPLITOOLS_SERVER_URL=https://eyesapi.applitools.com
curl -v -X DELETE "$APPLITOOLS_SERVER_URL/api/sessions/batches/$APPLITOOLS_BATCH_ID/close/bypointerid?apiKey=$APPLITOOLS_API_KEY"
all-passed:
name: All Jobs Passed
runs-on: ubuntu-latest
needs: [test, visual-test, storybook-test]
steps:
- name: All jobs passed
run: echo "All passed"