-
Notifications
You must be signed in to change notification settings - Fork 41
134 lines (116 loc) · 5.08 KB
/
Copy pathcypress.yml
File metadata and controls
134 lines (116 loc) · 5.08 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
on:
# Trigger the workflow on push or pull request,
# but only for the main branch
push:
branches:
- master
pull_request:
types: [ opened, labeled, synchronize ]
name: E2E Test
# Cancel superseded runs for the same branch. The group is named explicitly
# rather than derived from github.workflow: several files share the workflow
# name `Inspections` and would otherwise cancel each other.
concurrency:
group: formidable-cypress-${{ github.ref }}
cancel-in-progress: true
jobs:
cypress:
if: contains(github.event.pull_request.labels.*.name, 'run e2e tests')
runs-on: ubuntu-latest
strategy:
# Report every shard's result. The default would cancel the sibling
# shards as soon as one spec fails, hiding failures we want to see in
# the same run.
fail-fast: false
matrix:
# Each shard is a separate runner with its own wp-env stack. The
# specs assert on global state (searchFunctionality.cy.js creates a
# form named "Test Form" and asserts the list count is exactly 1), so
# two Cypress processes must never share one WordPress instance -
# parallelism has to be at the runner level, not within a job.
#
# Each shard re-pays the fixed setup cost (npm ci + wp-env booting
# WordPress and MySQL), so raising this past ~6 buys little.
shard: [ 0, 1, 2, 3 ]
name: Cypress (shard ${{ matrix.shard }})
env:
SHARD_TOTAL: 4
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Node
uses: actions/setup-node@v5
with:
node-version: 22
- name: Cache dependencies
id: cache-npm
uses: actions/cache@v4
with:
path: |
~/.npm
~/.cache/Cypress
node_modules
key: ${{ runner.os }}-cypress-node-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-cypress-node-modules-
- name: Install dependencies
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci --legacy-peer-deps --include=dev
# Serve the formidableforms.com APIs from fixtures instead of calling
# them on every run. The cache key is the UTC date, so the fixtures are
# refreshed at most once a day and all four shards share the one copy -
# without this, each shard fetches them separately. If a fetch fails the
# committed fixture is used, so the suite still runs when the API is
# unreachable.
- name: Get current date
id: date
run: echo "date=$( date -u +%Y-%m-%d )" >> "$GITHUB_OUTPUT"
- name: Cache API responses
id: cache-api
uses: actions/cache@v4
with:
path: |
tests/mu-plugins/form-templates-api.json
tests/mu-plugins/style-templates-api.json
tests/mu-plugins/view-templates-api.json
tests/mu-plugins/addons-api.json
key: frm-api-fixtures-${{ steps.date.outputs.date }}
- name: Refresh API fixtures
if: steps.cache-api.outputs.cache-hit != 'true'
run: |
# Each line is "<fixture> <url>". The URLs match what the plugin
# requests on an unlicensed install, which is what wp-env is - so
# the add-ons list comes from the Cloudflare worker, and only the
# form templates endpoint takes the free-templates license.
while read -r fixture url; do
[ -n "$fixture" ] || continue
# Write to a temp file first so a partial or failed response never
# clobbers the committed fallback.
if curl -fsS --max-time 40 -A 'formidable-e2e' "$url" -o "/tmp/$fixture" \
&& [ -s "/tmp/$fixture" ]; then
mv "/tmp/$fixture" "tests/mu-plugins/$fixture"
echo "Refreshed $fixture from the API."
else
echo "Could not reach $url; using the committed $fixture."
fi
done <<'FIXTURES'
form-templates-api.json https://formidableforms.com/wp-json/form-templates/v1/list?l=RlJFRVRFTVBMQVRFUyEhIQ%3D%3D
style-templates-api.json https://formidableforms.com/wp-json/style-templates/v1/list
view-templates-api.json https://formidableforms.com/wp-json/view-templates/v1/list
addons-api.json https://plapi.formidableforms.com/list/
FIXTURES
- name: Set up WP environment
run: npm run env start
- name: Test
run: |
specs="$( ./tests/bin/split-specs.sh "$SHARD_TOTAL" "${{ matrix.shard }}" )"
# An empty shard only happens if there are fewer specs than shards.
# Bail out rather than calling Cypress with an empty --spec, which
# would silently fall back to running the whole suite.
if [ -z "$specs" ]; then
echo "No specs assigned to shard ${{ matrix.shard }}; nothing to run."
exit 0
fi
echo "Shard ${{ matrix.shard }} of $SHARD_TOTAL running:"
echo "$specs" | tr ',' '\n' | sed 's/^/ /'
npm run e2e:githubrun -- --spec "$specs"