@@ -66,36 +66,52 @@ jobs:
6666 if : steps.cache-npm.outputs.cache-hit != 'true'
6767 run : npm ci --legacy-peer-deps --include=dev
6868
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.
69+ # Serve the formidableforms.com APIs from fixtures instead of calling
70+ # them on every run. The cache key is the UTC date, so the fixtures are
71+ # refreshed at most once a day and all four shards share the one copy -
72+ # without this, each shard fetches them separately. If a fetch fails the
73+ # committed fixture is used, so the suite still runs when the API is
74+ # unreachable.
7575 - name : Get current date
7676 id : date
7777 run : echo "date=$( date -u +%Y-%m-%d )" >> "$GITHUB_OUTPUT"
7878
79- - name : Cache form templates API response
80- id : cache-templates
79+ - name : Cache API responses
80+ id : cache-api
8181 uses : actions/cache@v4
8282 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'
83+ path : |
84+ tests/mu-plugins/form-templates-api.json
85+ tests/mu-plugins/style-templates-api.json
86+ tests/mu-plugins/view-templates-api.json
87+ tests/mu-plugins/addons-api.json
88+ key : frm-api-fixtures-${{ steps.date.outputs.date }}
89+
90+ - name : Refresh API fixtures
91+ if : steps.cache-api.outputs.cache-hit != 'true'
8892 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
93+ # Each line is "<fixture> <url>". The URLs match what the plugin
94+ # requests on an unlicensed install, which is what wp-env is - so
95+ # the add-ons list comes from the Cloudflare worker, and only the
96+ # form templates endpoint takes the free-templates license.
97+ while read -r fixture url; do
98+ [ -n "$fixture" ] || continue
99+
100+ # Write to a temp file first so a partial or failed response never
101+ # clobbers the committed fallback.
102+ if curl -fsS --max-time 40 -A 'formidable-e2e' "$url" -o "/tmp/$fixture" \
103+ && [ -s "/tmp/$fixture" ]; then
104+ mv "/tmp/$fixture" "tests/mu-plugins/$fixture"
105+ echo "Refreshed $fixture from the API."
106+ else
107+ echo "Could not reach $url; using the committed $fixture."
108+ fi
109+ done <<'FIXTURES'
110+ form-templates-api.json https://formidableforms.com/wp-json/form-templates/v1/list?l=RlJFRVRFTVBMQVRFUyEhIQ%3D%3D
111+ style-templates-api.json https://formidableforms.com/wp-json/style-templates/v1/list
112+ view-templates-api.json https://formidableforms.com/wp-json/view-templates/v1/list
113+ addons-api.json https://plapi.formidableforms.com/list/
114+ FIXTURES
99115
100116 - name : Set up WP environment
101117 run : npm run env start
0 commit comments