|
20 | 20 | if: contains(github.event.pull_request.labels.*.name, 'run e2e tests') |
21 | 21 | runs-on: ubuntu-latest |
22 | 22 |
|
23 | | - name: Cypress |
| 23 | + strategy: |
| 24 | + # Report every shard's result. The default would cancel the sibling |
| 25 | + # shards as soon as one spec fails, hiding failures we want to see in |
| 26 | + # the same run. |
| 27 | + fail-fast: false |
| 28 | + matrix: |
| 29 | + # Each shard is a separate runner with its own wp-env stack. The |
| 30 | + # specs assert on global state (searchFunctionality.cy.js creates a |
| 31 | + # form named "Test Form" and asserts the list count is exactly 1), so |
| 32 | + # two Cypress processes must never share one WordPress instance - |
| 33 | + # parallelism has to be at the runner level, not within a job. |
| 34 | + # |
| 35 | + # Each shard re-pays the fixed setup cost (npm ci + wp-env booting |
| 36 | + # WordPress and MySQL), so raising this past ~6 buys little. |
| 37 | + shard: [ 0, 1, 2, 3 ] |
| 38 | + |
| 39 | + name: Cypress (shard ${{ matrix.shard }}) |
| 40 | + |
| 41 | + env: |
| 42 | + SHARD_TOTAL: 4 |
| 43 | + |
24 | 44 | steps: |
25 | 45 | - name: Checkout |
26 | 46 | uses: actions/checkout@v6 |
|
46 | 66 | if: steps.cache-npm.outputs.cache-hit != 'true' |
47 | 67 | run: npm ci --legacy-peer-deps --include=dev |
48 | 68 |
|
| 69 | + # Serve the form-templates API from a fixture instead of calling |
| 70 | + # formidableforms.com on every run. The cache key is the UTC date, so |
| 71 | + # the fixture is refreshed at most once a day and all four shards share |
| 72 | + # the one copy - without this, each shard fetches it separately. If the |
| 73 | + # fetch fails the committed fixture is used, so the suite still runs |
| 74 | + # when the API is unreachable. |
| 75 | + - name: Get current date |
| 76 | + id: date |
| 77 | + run: echo "date=$( date -u +%Y-%m-%d )" >> "$GITHUB_OUTPUT" |
| 78 | + |
| 79 | + - name: Cache form templates API response |
| 80 | + id: cache-templates |
| 81 | + uses: actions/cache@v4 |
| 82 | + with: |
| 83 | + path: tests/mu-plugins/form-templates-api.json |
| 84 | + key: form-templates-${{ steps.date.outputs.date }} |
| 85 | + |
| 86 | + - name: Refresh form templates fixture |
| 87 | + if: steps.cache-templates.outputs.cache-hit != 'true' |
| 88 | + run: | |
| 89 | + # Write to a temp file first so a partial or failed response never |
| 90 | + # clobbers the committed fallback. |
| 91 | + if curl -fsS --max-time 40 -A 'formidable-e2e' \ |
| 92 | + 'https://formidableforms.com/wp-json/form-templates/v1/list?l=RlJFRVRFTVBMQVRFUyEhIQ%3D%3D' \ |
| 93 | + -o /tmp/form-templates-api.json && [ -s /tmp/form-templates-api.json ]; then |
| 94 | + mv /tmp/form-templates-api.json tests/mu-plugins/form-templates-api.json |
| 95 | + echo "Refreshed the form templates fixture from the API." |
| 96 | + else |
| 97 | + echo "Could not reach the templates API; using the committed fixture." |
| 98 | + fi |
| 99 | +
|
49 | 100 | - name: Set up WP environment |
50 | 101 | run: npm run env start |
51 | 102 |
|
52 | 103 | - name: Test |
53 | | - run: npm run e2e:githubrun |
| 104 | + run: | |
| 105 | + specs="$( ./tests/bin/split-specs.sh "$SHARD_TOTAL" "${{ matrix.shard }}" )" |
| 106 | +
|
| 107 | + # An empty shard only happens if there are fewer specs than shards. |
| 108 | + # Bail out rather than calling Cypress with an empty --spec, which |
| 109 | + # would silently fall back to running the whole suite. |
| 110 | + if [ -z "$specs" ]; then |
| 111 | + echo "No specs assigned to shard ${{ matrix.shard }}; nothing to run." |
| 112 | + exit 0 |
| 113 | + fi |
| 114 | +
|
| 115 | + echo "Shard ${{ matrix.shard }} of $SHARD_TOTAL running:" |
| 116 | + echo "$specs" | tr ',' '\n' | sed 's/^/ /' |
| 117 | +
|
| 118 | + npm run e2e:githubrun -- --spec "$specs" |
0 commit comments