Skip to content

Fix multiversion docs overwrite on main push#266

Merged
yuecideng merged 4 commits into
mainfrom
fix/docs-multiversion-overwrite
May 12, 2026
Merged

Fix multiversion docs overwrite on main push#266
yuecideng merged 4 commits into
mainfrom
fix/docs-multiversion-overwrite

Conversation

@yuecideng
Copy link
Copy Markdown
Contributor

Description

This PR fixes a bug where pushing to main wiped all versioned documentation from GitHub Pages, leaving only the main/ subdirectory.

Root cause: actions/deploy-pages@v4 always performs a full site replacement. The original per-ref cache (docs-output-${{ github.ref_name }}) only stored the current branch's output, so each main push deployed an artifact with only main/ — erasing all previously deployed versioned dirs like v0.2.0/.

Fix: Maintain a single shared cross-ref cache (docs-full-site-<repo>-<run_id>) with a common restore-key prefix. Every build job:

  1. Restores the last saved full multi-version site from cache
  2. Rebuilds only the current version subdir (main/ or v*/)
  3. Prunes excess tag versions when a new tag push exceeds DOCS_MAX_VERSIONS=4
  4. Regenerates versions.json and root index.html from all present dirs
  5. Saves the updated full site back to cache
  6. Uploads the complete multi-version site as the pages artifact

actions/deploy-pages then deploys the full site — all versions intact. No GitHub Pages source setting change required (stays on "GitHub Actions").

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which improves an existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (existing functionality will not work without user modification)
  • Documentation update

Checklist

  • I have run the black . command to format the code base.
  • I have added tests that prove my fix is effective or that my feature works

Tests.github/workflows/tests/test_docs_publish.yml with 3 act scenarios, all pass ✅:

  • test-main-push: v0.1.0 and v0.2.0 survive after main push, main/ is updated
  • test-tag-push: New tag version added, all existing dirs preserved
  • test-prune-old-versions: 5th tag causes oldest to be removed, max 4 tags kept

🤖 Generated with GitHub Copilot

yuecideng and others added 2 commits May 12, 2026 16:26
Root cause: actions/deploy-pages@v4 does a full site replacement.
A main branch push only built main/, so every deploy wiped out all
versioned docs (v0.2.0, etc.) deployed via tag pushes.

Fix:
- Remove the per-ref docs cache from the build job (it only stored
  the current ref's subdir, making the full-replace worse).
- Switch from actions/upload-pages-artifact + actions/deploy-pages
  to JamesIves/github-pages-deploy-action@v4 with target-folder +
  clean: true, which updates only the specific subdirectory in the
  gh-pages branch leaving all other version dirs untouched.
- Move version pruning and metadata regeneration (versions.json,
  root index.html) into the publish job where the full gh-pages
  state is always visible.

Required repo-settings change: GitHub Pages source must be changed
from 'GitHub Actions' to 'Deploy from branch: gh-pages'.

Add .github/workflows/tests/test_docs_publish.yml with three act-
testable scenarios (main push, tag push, prune) all verified passing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Root cause: actions/deploy-pages always replaces the entire site with
whatever artifact is uploaded. A per-ref cache only restored the current
branch's output, so a main push deployed a site with only main/ and
wiped all versioned docs.

Fix: use a shared cross-ref cache (docs-full-site-<repo>-<run_id>) with
a common restore-key prefix. Every build job:
  1. Restores the last saved full site (all versions)
  2. Rebuilds only the current version subdir (main/ or v*)
  3. Prunes excess tag versions when on a tag push
  4. Regenerates versions.json and root index.html
  5. Saves the updated full site back to cache
  6. Uploads the complete multi-version site as the pages artifact

actions/deploy-pages then deploys the full site — all versions intact.
Reverts the JamesIves gh-pages branch approach (user prefers GitHub
Actions source for Pages deployment).

Test: 3 act scenarios all pass:
  - main push: v0.1.0 and v0.2.0 survive, main/ updated
  - tag push: new version added, existing dirs untouched
  - prune: 5th tag causes oldest to be removed, max 4 tags kept

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@yuecideng yuecideng added bug Something isn't working ci docs Improvements or additions to documentation labels May 12, 2026
@yuecideng yuecideng merged commit c322584 into main May 12, 2026
1 check passed
@yuecideng yuecideng deleted the fix/docs-multiversion-overwrite branch May 12, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci docs Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant