-
Notifications
You must be signed in to change notification settings - Fork 3
162 lines (139 loc) · 7.67 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
# Run cypress tests
name: cypress
on:
pull_request:
branches: [main, dev, staging, release/*]
types:
- opened # when a PR is opened
- synchronize # when a PR is pushed to
- reopened # when a PR is reopened
- ready_for_review # when a PR is marked as ready for review (e.g. taken off draft mode)
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
GITHUB_TOKEN: ${{ secrets.PROSOPONATOR_PAT }}
GH_TOKEN: ${{ secrets.PROSOPONATOR_PAT }}
CARGO_TERM_COLOR: always
NODE_OPTIONS: "--max-old-space-size=4096"
NODE_ENV: "test"
defaults:
run:
shell: bash
jobs:
check:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Print contexts
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
ENV_CONTEXT: ${{ toJson(env) }}
VARS_CONTEXT: ${{ toJson(vars) }}
JOB_CONTEXT: ${{ toJson(job) }}
STEPS_CONTEXT: ${{ toJson(steps) }}
RUNNER_CONTEXT: ${{ toJson(runner) }}
SECRETS_CONTEXT: ${{ toJson(secrets) }}
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
MATRIX_CONTEXT: ${{ toJson(matrix) }}
NEEDS_CONTEXT: ${{ toJson(needs) }}
INPUTS_CONTEXT: ${{ toJson(inputs) }}
run: |
echo "******************************"
echo "github:" "$GITHUB_CONTEXT"
echo "******************************"
echo "env:" "$ENV_CONTEXT"
echo "******************************"
echo "vars:" "$VARS_CONTEXT"
echo "******************************"
echo "job:" "$JOB_CONTEXT"
echo "******************************"
echo "steps:" "$STEPS_CONTEXT"
echo "******************************"
echo "runner:" "$RUNNER_CONTEXT"
echo "******************************"
echo "secrets:" "$SECRETS_CONTEXT"
echo "******************************"
echo "strategy:" "$STRATEGY_CONTEXT"
echo "******************************"
echo "matrix:" "$MATRIX_CONTEXT"
echo "******************************"
echo "needs:" "$NEEDS_CONTEXT"
echo "******************************"
echo "inputs:" "$INPUTS_CONTEXT"
echo "******************************"
- uses: actions/checkout@v4
with:
submodules: "recursive"
- run: mkdir -p ~/.npm
- run: mkdir -p ~/.cache/Cypress
- name: Restore npm cache
if: ${{ runner.environment != 'self-hosted' }} # don't restore cache on self-hosted runners, network speed not good enough
uses: actions/cache/restore@v4
with:
# must restore all cache dirs, and they must exist ahead of this!
path: |
~/.npm
~/.cache/Cypress
# note that restoring a cache in github is a pain. The trailing '-' matches any string after the '-', therefore 'abc-' would match a cache named 'abc-1234' or 'abc-5678', etc.
# the problem is 'abc-' will not match a cache named 'abc'! So if you're using wildcard cache name selectors like this, you need a field that changes as the suffix to become the wildcard
# here we're setting the key to an unused cache key so it falls back to the wildcard selector in `restore-keys`
key: some-unused-cache-key
restore-keys: |
npm-${{ runner.os }}-${{ runner.arch }}-
- uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
- run: npm i -g "npm@$(jq -r .engines.npm < package.json)"
- run: npm ci
# build all packages in workspace
- run: npm run build:all
- name: Setup env
run: |
set -euxo pipefail # stop on errors, print commands, fail on pipe fails
cp demos/client-example-server/env.development demos/client-example-server/.env.test
cp demos/client-example/env.development demos/client-example/.env.test
cp demos/client-bundle-example/env.development demos/client-example/.env.test
cp dev/scripts/env.test .env.test
cp dev/scripts/env.test dev/scripts/.env.test
cp dev/scripts/env.test packages/cli/.env.test
cp dev/scripts/env.test packages/procaptcha-bundle/.env.test
echo NODE_ENV: "$NODE_ENV"
- name: Start the docker images
run: |
docker compose --file ./docker/docker-compose.test.yml up -d --remove-orphans --force-recreate --always-recreate-deps
docker container ls
sleep 10s
# deploy dapp + protocol and run setup to register, stake and load a dataset for a provider
- run: NODE_ENV="test" npm run setup
# Build a test version of the procaptcha bundle and run the cypress tests on it and on the React client-example
# Running using NODE_ENV=development instead of NODE_ENV=production means the bundle will be built with selectors that can be used
# by the cypress tests to find the elements they need to interact with
- run: NODE_ENV="development" npm -w @prosopo/procaptcha-bundle run bundle
- name: Run the cypress tests on client-example
run: |
npx concurrently "npm run start:server" "npm run start:provider:admin" "npm run start:demo" "sleep 10s && npm -w @prosopo/cypress-shared run cypress:run:client-example" --success "first" --kill-others
- name: Run the cypress tests on client-bundle-example
run: |
npx concurrently "npm run start:server" "npm run start:provider:admin" "npm run start:bundle" "sleep 10s && npm -w @prosopo/cypress-shared run cypress:run:client-bundle-example" --success "first" --kill-others
- name: Run the cypress tests on client-bundle-example explicit rendering
run: |
npx concurrently "npm run start:server" "npm run start:provider:admin" "npm run start:bundle" "sleep 10s && npm -w @prosopo/cypress-shared run cypress:run:client-bundle-example:explicit" --success "first" --kill-others
# after the test run completes store videos and any screenshots
- uses: actions/upload-artifact@v4
# store screenshots only on failures
if: failure()
with:
name: cypress-screenshots
path: ./demos/cypress-shared/cypress/screenshots
if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn`
# after the test run completes store videos and any screenshots
- uses: actions/upload-artifact@v4
# store videos only on failures
if: failure()
with:
name: cypress-videos
path: ./demos/cypress-shared/cypress/videos
if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn`
- run: docker compose --file ./docker/docker-compose.test.yml down