-
Notifications
You must be signed in to change notification settings - Fork 76
318 lines (269 loc) · 10.7 KB
/
cypress.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
name: Cypress
on:
# allow running manually
workflow_dispatch:
pull_request:
branches: [ 'master', 'stable-*' ]
push:
branches: [ 'master', 'stable-*' ]
# daily on master
schedule:
- cron: '30 5 * * *'
concurrency:
group: cypress-${{ github.ref }}
cancel-in-progress: true
jobs:
cypress:
runs-on: ubuntu-latest
env:
# base of a PR, or pushed-to branch outside PRs, or master
BRANCH: ${{ github.base_ref || github.ref || 'refs/heads/master' }}
strategy:
fail-fast: false
matrix:
test:
- 'approval'
- 'approval-modal'
- 'collections'
- 'community'
- 'namespaces'
- 'repo'
- 'screenshots'
steps:
# galaxykit needs pip 23+, Ubuntu 22.04's default Python uses pip 22
- name: "Install python 3.11"
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: "Install galaxykit dependency"
run: |
# pip install git+https://github.com/ansible/galaxykit.git@branch_name
pip install git+https://github.com/ansible/galaxykit.git
- name: "Set env.SHORT_BRANCH, BACKEND_FLAVOR"
run: |
SHORT_BRANCH=`sed 's/^refs\/heads\///' <<< $BRANCH`
case "${{ matrix.test }}" in
community*)
BACKEND_FLAVOR=community
API=api
;;
*)
BACKEND_FLAVOR=standalone
API=api/galaxy
;;
esac
echo "BACKEND_FLAVOR=${BACKEND_FLAVOR}" >> $GITHUB_ENV
echo "COMPOSE_INTERACTIVE_NO_CLI=1" >> $GITHUB_ENV
echo "SHORT_BRANCH=${SHORT_BRANCH}" >> $GITHUB_ENV
echo "API=${API}" >> $GITHUB_ENV
- name: "Set variables for screenshots"
if: matrix.test == 'screenshots'
run: |
UI_COMMIT_BASE=`curl -s https://api.github.com/repos/ansible/ansible-hub-ui/branches/${SHORT_BRANCH} | jq -r .commit.sha`
echo "UI_COMMIT_BASE=${UI_COMMIT_BASE}" >> $GITHUB_ENV
- name: "Checkout ansible-hub-ui (${{ github.ref }})"
uses: actions/checkout@v4
with:
path: 'ansible-hub-ui'
- name: "Checkout galaxy_ng (${{ env.SHORT_BRANCH }})"
uses: actions/checkout@v4
with:
repository: 'ansible/galaxy_ng'
ref: '${{ env.SHORT_BRANCH }}'
path: 'galaxy_ng'
- name: "Checkout oci_env (main)"
uses: actions/checkout@v4
with:
repository: 'pulp/oci_env'
path: 'oci_env'
- name: "Configure oci_env"
working-directory: 'oci_env'
run: |
pip install --editable ./client/
# merge common, profile-specific and test matrix specific config
cat ../ansible-hub-ui/.github/workflows/cypress/compose.env.common \
../ansible-hub-ui/.github/workflows/cypress/compose.env."$BACKEND_FLAVOR" \
../ansible-hub-ui/test/cypress/e2e/"${{ matrix.test }}"/compose.env \
| sed 's/^\s\+//' | tee compose.env || [ -s compose.env ]
# oci-env compose build: FileNotFoundError: [Errno 2] No such file or directory: 'docker-compose'
- name: "Provide docker-compose"
run: |
mkdir -p /home/runner/.local/bin/
cd /home/runner/.local/bin/
( echo '#!/bin/sh' ; echo 'docker compose "$@"' ) > docker-compose
chmod +x docker-compose
- name: "oci-env compose build"
working-directory: 'oci_env'
run: 'oci-env compose build'
- name: "oci-env compose up"
working-directory: 'oci_env'
run: 'oci-env compose up &'
- name: "Install node 18"
uses: actions/setup-node@v4
with:
node-version: '18'
- name: "Cache ~/.npm & ~/.cache/Cypress"
uses: actions/cache@v4
with:
path: |
~/.npm
~/.cache/Cypress
key: npm-${{ env.SHORT_BRANCH }}-${{ hashFiles('ansible-hub-ui/**/package-lock.json') }}
restore-keys: |
npm-${{ env.SHORT_BRANCH }}-
npm-
- name: 'npm install'
working-directory: 'ansible-hub-ui'
run: 'npm install'
- name: 'gettext extract & compile'
working-directory: 'ansible-hub-ui'
run: |
# production displays unknown translations literally, make sure it's up to date
npm run gettext:extract
npm run gettext:compile
- name: "Build standalone UI"
if: ${{ env.BACKEND_FLAVOR == 'standalone' }}
working-directory: 'ansible-hub-ui'
run: |
npm run build-standalone
# save the App.*.js hash for later verification
BUILD_HASH=`ls dist/js/App*js | cut -d. -f2`
echo "BUILD_HASH=${BUILD_HASH}" >> $GITHUB_ENV
- name: "Build community UI"
if: ${{ env.BACKEND_FLAVOR == 'community' }}
working-directory: 'ansible-hub-ui'
run: |
npm run build-community
# save the App.*.js hash for later verification
BUILD_HASH=`ls dist/js/App*js | cut -d. -f2`
echo "BUILD_HASH=${BUILD_HASH}" >> $GITHUB_ENV
- name: "Serve standalone UI"
if: ${{ env.BACKEND_FLAVOR == 'standalone' }}
run: |
mkdir -p www/static/
mv ansible-hub-ui/dist www/static/galaxy_ng
cd www
echo '{}' > package.json
npm install local-web-server
node_modules/.bin/ws --port 8002 --directory . --spa static/galaxy_ng/index.html \
--rewrite '/api/(.*) -> http://localhost:5001/api/$1' \
--rewrite '/pulp/api/(.*) -> http://localhost:5001/pulp/api/$1' \
--rewrite '/v2/(.*) -> http://localhost:5001/v2/$1' \
--rewrite '/extensions/v2/(.*) -> http://localhost:5001/extensions/v2/$1' &
- name: "Serve community UI"
if: ${{ env.BACKEND_FLAVOR == 'community' }}
run: |
mkdir -p www/
mv ansible-hub-ui/dist/* www/
cd www
echo '{}' > package.json
npm install local-web-server
node_modules/.bin/ws --port 8002 --directory . --spa index.html \
--rewrite '/api/(.*) -> http://localhost:5001/api/$1' \
--rewrite '/pulp/api/(.*) -> http://localhost:5001/pulp/api/$1' \
--rewrite '/v2/(.*) -> http://localhost:5001/v2/$1' \
--rewrite '/extensions/v2/(.*) -> http://localhost:5001/extensions/v2/$1' &
- name: "Install Cypress & test dependencies"
working-directory: 'ansible-hub-ui/test'
run: |
npm install
- name: "Install Imagemagick"
if: matrix.test == 'screenshots'
run: |
sudo apt install imagemagick
- name: "Configure Cypress"
working-directory: 'ansible-hub-ui/test'
run: |
cp -aiv ../.github/workflows/cypress/cypress.env.json."$BACKEND_FLAVOR" cypress.env.json
- name: "Ensure standalone index.html uses the new js"
if: ${{ env.BACKEND_FLAVOR == 'standalone' }}
run: |
echo 'expecting /static/galaxy_ng/js/App.'"$BUILD_HASH"'.js'
curl http://localhost:8002/static/galaxy_ng/index.html | tee /dev/stderr | grep '/static/galaxy_ng/js/App.'"$BUILD_HASH"'.js'
- name: "Ensure community index.html uses the new js"
if: ${{ env.BACKEND_FLAVOR == 'community' }}
run: |
echo 'expecting /js/App.'"$BUILD_HASH"'.js'
curl http://localhost:8002/index.html | tee /dev/stderr | grep '/js/App.'"$BUILD_HASH"'.js'
- name: "Ensure galaxykit can connect to API"
run: |
galaxykit -s http://localhost:8002/"$API"/ -u admin -p admin collection list
- name: "Check initial feature flags"
run: |
curl -s http://localhost:5001/"$API"/_ui/v1/feature-flags/ | jq
- name: "Check component versions & settings"
run: |
HUB_TOKEN=`curl -s -u admin:admin -d '' http://localhost:5001/"$API"/v3/auth/token/ | jq -r .token`
curl -s -H "Authorization: Token $HUB_TOKEN" http://localhost:5001/"$API"/ | jq
curl -s -H "Authorization: Token $HUB_TOKEN" http://localhost:5001/"$API"/_ui/v1/settings/ | jq
- name: "Check if e2e contains only dirs in matrix test array"
working-directory: 'ansible-hub-ui'
run: |
diff -Naur <(ls test/cypress/e2e | sort) <(yq '.jobs.cypress.strategy.matrix.test[]' .github/workflows/cypress.yml | sort)
- name: "Cache base screenshots"
if: matrix.test == 'screenshots'
uses: actions/cache@v4
with:
path: ansible-hub-ui/test/screenshots-base/
key: screenshots-${{env.SHORT_BRANCH}}-${{ env.UI_COMMIT_BASE }}
restore-keys: |
screenshots-${{env.SHORT_BRANCH}}-
- name: "List cached screenshots"
if: ${{ matrix.test == 'screenshots' && github.event_name == 'pull_request' }}
run: |
ls ansible-hub-ui/test/screenshots-base/
- name: "Run cypress"
working-directory: 'ansible-hub-ui/test'
env:
CONSOLE_LOG_TO_TERMINAL: true
run: |
sed -i '/specPattern:/s/\*\*/${{matrix.test}}/' cypress.config.js
sed -i "/screenshotsFolder:/s/',$/\/${{matrix.test}}',/" cypress.config.js
git diff cypress.config.js
npm run cypress:chrome
- name: "List new screenshots"
if: matrix.test == 'screenshots'
continue-on-error: true
run: |
ls ansible-hub-ui/test/cypress/screenshots/screenshots/screenshots.js/
- name: "Compare screenshots"
if: ${{ matrix.test == 'screenshots' && github.event_name == 'pull_request' }}
working-directory: 'ansible-hub-ui/test'
run: |
changed=false
for orig in screenshots-base/*; do
name=`basename "$orig"`
new="cypress/screenshots/screenshots/screenshots.js/$name"
diff="cypress/screenshots/screenshots/diff--$name"
num=$(compare -metric RMSE -fuzz 5% "$orig" "$new" "$diff" 2>&1 | awk '{ print $1 }')
num=${num%.*}
if [ "$num" -gt 64 ]; then
echo "screenshot $name changed: $num" 1>&2
changed=true
fi
done
if [ "$changed" = true ]; then
cp -a screenshots-base cypress/screenshots/screenshots/0-before
mv cypress/screenshots/screenshots/{screenshots.js,1-after}
exit 1
fi
- name: "Move screenshots to cache"
if: ${{ matrix.test == 'screenshots' && github.event_name != 'pull_request' }}
working-directory: 'ansible-hub-ui/test'
run: |
rm -rf screenshots-base/
mv cypress/screenshots/screenshots/screenshots.js ./screenshots-base
- uses: actions/upload-artifact@v4
if: failure()
with:
name: screenshots_and_videos-${{matrix.test}}
path: |
ansible-hub-ui/test/cypress/screenshots
ansible-hub-ui/test/cypress/videos
- name: "Kill container, show debug info"
if: always()
working-directory: 'oci_env'
run: |
oci-env exec bash -c "pip3 list && pip3 install pipdeptree && pipdeptree"
oci-env compose logs
oci-env compose kill