refactor: guardrails for branches#3241
Merged
Merged
Conversation
Contributor
|
🔭🐙🐈 Test this branch here: https://db-ui.github.io/elements/review/refactor-guardrails-for-branches |
mfranzke
enabled auto-merge (squash)
June 22, 2026 05:51
nmerget
approved these changes
Jun 22, 2026
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.
Analysis
Root Cause: The cleanup workflow unconditionally deploys
Looking at
cleanup.yml:./publiccleanup-gh-pages.jswhich removes stale dirs from./public/review/and./public/version/./publicback to gh-pages — regardless of whether the cleanup script actually deleted anythingThe
peaceiris/actions-gh-pagesaction withpublish_dir: ./publicreplaces the entire gh-pages branch content with what's in./public.Problem 1:
./index.html(root-level files) are lostThe
build-gh-page.shscript shows that on a release (RELEASE == "true"), the root of./publicis populated with the build output (mv ./out ./public), and existingreview/andversion/folders are preserved by copying them back in. This is what creates the rootindex.html.However, in
cleanup.yml, step 1 checks out the repo's default branch (not gh-pages). So the./publicdirectory is built only from the gh-pages tarball. That tarball should containindex.html. But here's the critical issue:The cleanup script's
deployresult is never checked. The deploy step runs unconditionally. If the tarball download or extraction has any issue (partial download, rate limiting, network error), the deploy will overwrite gh-pages with incomplete content — wipingindex.htmland anything else that didn't survive.Problem 2:
./review/main/is deleted by the cleanup scriptThis is the primary bug. Look at
cleanup-gh-pages.js:It lists all directories under
public/review/and keeps only those whose name matches a branch returned bygithub.rest.repos.listBranches().The GitHub API
listBranchesendpoint is paginated and defaults to 30 results per page. If the repo has more than 30 branches, themainbranch might not appear in the first page of results. Since the script doesn't handle pagination, it may not seemainin the response, and will deletereview/main/.Even if
maindoes appear, the more fundamental issue is: the script is designed to clean up preview branches for closed PRs. Butreview/main/is presumably a permanent deployment of the main branch's build output — it should never be cleaned up.Solution
Two fixes needed:
paginate) in the API callsreview/main/and root-level files) from deletionHere's the fix:
Now let's fix the workflow to only deploy when the cleanup actually removed something:
Summary of Changes
Two bugs identified, three fixes applied:
review/main/deletedlistBranchesis paginated (default 30). Ifmainisn't in the first page, the script treats it as stale and deletes it.github.paginate()to fetch all branches/tags. 2. AddPROTECTED_DIRS = ['main']so it's never removed regardless.index.htmldisappearsif: fromJSON(steps.cleanup.outputs.result).deployso the deploy only happens when files were actually removed.The pagination fix ensures accurate branch lookup, the protected list ensures
review/main/survives even edge cases, and the conditional deploy prevents unnecessary (and potentially destructive) overwrites of the gh-pages branch.