ci(docs): fix preview cleanup failing on unsupported per_page param#129
Merged
Conversation
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`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The docs preview cleanup job has failed on every PR close since it was added (not just recent ones). The logs show:
The first API call passes
per_page=100:The Cloudflare Pages deployments API does not support
per_pageand returns HTTP 400 for it (envandpageare fine). Because the request usescurl -fsSunderset -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
per_pageand paginate with the supportedpageparameter, 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..deployment_trigger?.metadata?.branch?) and(.result // [])so a null or malformed deployment entry can't abort the run underset -e.Verification
Can't hit the live API from CI (needs the
pull_request: closedevent and the CF token), so I verified the logic locally:docs-preview-cleanup.ymlparses as valid YAML; the extracted script passesbash -n.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.deployment_triggernull /metadatanull / a string trigger / a missing trigger: no error, only the real match returned.Full end-to-end runs on the next PR-close event.