Skip to content

ci(docs): fix preview cleanup failing on unsupported per_page param#129

Merged
dcmcand merged 1 commit into
mainfrom
ci/fix-docs-preview-cleanup
Jul 7, 2026
Merged

ci(docs): fix preview cleanup failing on unsupported per_page param#129
dcmcand merged 1 commit into
mainfrom
ci/fix-docs-preview-cleanup

Conversation

@dcmcand

@dcmcand dcmcand commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Problem

The docs preview cleanup job has failed on every PR close since it was added (not just recent ones). The logs show:

curl: (22) The requested URL returned error: 400

The first API call passes per_page=100:

GET .../pages/projects/llm-serving-pack/deployments?env=preview&per_page=100

The Cloudflare Pages deployments API does not support per_page and returns HTTP 400 for it (env and page are fine). Because the request uses curl -fsS under set -euo pipefail, the 400 becomes a hard failure before any deployment is deleted, so preview deployments linger, which is exactly what this workflow is meant to prevent. Refs: Cloudflare community thread.

Fix

  • Drop per_page and paginate with the supported page parameter, walking pages until one comes back empty (with a 50-page safety cap so a degenerate response can't loop forever). This also means a closed branch's deployments are still found if they've been pushed past the default first page.
  • Guard the branch lookup with optional jq access (.deployment_trigger?.metadata?.branch?) and (.result // []) so a null or malformed deployment entry can't abort the run under set -e.

Verification

Can't hit the live API from CI (needs the pull_request: closed event and the CF token), so I verified the logic locally:

  • docs-preview-cleanup.yml parses as valid YAML; the extracted script passes bash -n.
  • Simulated the full step with a mocked curl: it walks page 1-2, stops at the empty page 3, deletes only the two matching-branch IDs, correctly dedupes an ID that appears on two pages, and skips a deployment on a different branch.
  • Ran the guarded jq against deployments with deployment_trigger null / metadata null / a string trigger / a missing trigger: no error, only the real match returned.

Full end-to-end runs on the next PR-close event.

The Cloudflare Pages deployments API rejects the per_page query
parameter with HTTP 400, so this job has failed on every PR close since
it was added: curl -f turns the 400 into a hard error before anything is
deleted, leaving preview deployments to linger.

Drop per_page and page through results with the supported `page`
parameter instead, stopping at the first empty page (with a 50-page
safety cap). Also guard the jq branch lookup with optional access so a
deployment with a missing or null trigger can't abort the run under
`set -e`.
@dcmcand
dcmcand merged commit f197db1 into main Jul 7, 2026
6 checks passed
@dcmcand
dcmcand deleted the ci/fix-docs-preview-cleanup branch July 7, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant