From 37fc7a82db4b54fc4d0f72afa4c0e091984b9023 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Sun, 22 Mar 2026 08:40:27 -0400 Subject: [PATCH 1/2] fix: restore original branch after deploying to gh-pages The deploy action switched to gh-pages and never switched back, breaking subsequent steps that reference local actions. Save and restore the original ref, preserving branch vs detached HEAD state. Also split the action into separate steps with comments. Co-Authored-By: Claude Opus 4.6 (1M context) --- .github/actions/deploy-to-gh-pages/action.yml | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/actions/deploy-to-gh-pages/action.yml b/.github/actions/deploy-to-gh-pages/action.yml index 7c4b59d..80bee96 100644 --- a/.github/actions/deploy-to-gh-pages/action.yml +++ b/.github/actions/deploy-to-gh-pages/action.yml @@ -15,15 +15,19 @@ inputs: outputs: url: description: Default GitHub Pages URL for the deployed subdirectory - value: ${{ steps.deploy.outputs.url }} + value: ${{ steps.url.outputs.url }} runs: using: composite steps: - - id: deploy + # Save the current ref so we can restore it after deploying. + - id: save-ref shell: bash + run: echo "ref=$(git symbolic-ref HEAD 2>/dev/null || git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + + # Switch to gh-pages, creating it as an orphan branch if needed. + - shell: bash run: | - TARGET="${{ inputs.target }}" git fetch origin gh-pages 2>/dev/null || true if git rev-parse --verify origin/gh-pages >/dev/null 2>&1; then git checkout -B gh-pages origin/gh-pages @@ -32,6 +36,11 @@ runs: git rm -rf . git clean -fd fi + + # Copy the built site into the target subdirectory, commit, and push. + - shell: bash + run: | + TARGET="${{ inputs.target }}" rm -rf "$TARGET" mkdir -p "$(dirname "$TARGET")" cp -r "${{ inputs.site-dir }}" "$TARGET" @@ -39,4 +48,12 @@ runs: git add .nojekyll "$TARGET" git diff --cached --quiet || git commit -m "${{ inputs.commit-message }}" git push origin gh-pages - echo "url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${TARGET}/" >> "$GITHUB_OUTPUT" + + # Restore the original branch so subsequent steps can find local actions. + - shell: bash + run: git checkout "${{ steps.save-ref.outputs.ref }}" + + # Output the default GitHub Pages URL for the deployed subdirectory. + - id: url + shell: bash + run: echo "url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ inputs.target }}/" >> "$GITHUB_OUTPUT" From 1b35a1513570a6eccc599094099c3bf0e41c9b7f Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Sun, 22 Mar 2026 08:54:21 -0400 Subject: [PATCH 2/2] refactor: use git worktree for gh-pages operations Replace branch switching with git worktree so the main checkout is never disturbed. This fixes the issue where subsequent steps could not find local actions after deploying to gh-pages. Co-Authored-By: Claude Opus 4.6 (1M context) --- .github/actions/deploy-to-gh-pages/action.yml | 18 ++++++------------ .github/actions/update-index/action.yml | 10 ++++++++++ .github/workflows/docs-release.yml | 5 +++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/.github/actions/deploy-to-gh-pages/action.yml b/.github/actions/deploy-to-gh-pages/action.yml index 80bee96..1451cf6 100644 --- a/.github/actions/deploy-to-gh-pages/action.yml +++ b/.github/actions/deploy-to-gh-pages/action.yml @@ -20,26 +20,20 @@ outputs: runs: using: composite steps: - # Save the current ref so we can restore it after deploying. - - id: save-ref - shell: bash - run: echo "ref=$(git symbolic-ref HEAD 2>/dev/null || git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - - # Switch to gh-pages, creating it as an orphan branch if needed. + # Create a worktree for gh-pages. - shell: bash run: | git fetch origin gh-pages 2>/dev/null || true if git rev-parse --verify origin/gh-pages >/dev/null 2>&1; then - git checkout -B gh-pages origin/gh-pages + git worktree add /tmp/gh-pages gh-pages else - git checkout --orphan gh-pages - git rm -rf . - git clean -fd + git worktree add --orphan -b gh-pages /tmp/gh-pages fi # Copy the built site into the target subdirectory, commit, and push. - shell: bash run: | + cd /tmp/gh-pages TARGET="${{ inputs.target }}" rm -rf "$TARGET" mkdir -p "$(dirname "$TARGET")" @@ -49,9 +43,9 @@ runs: git diff --cached --quiet || git commit -m "${{ inputs.commit-message }}" git push origin gh-pages - # Restore the original branch so subsequent steps can find local actions. + # Clean up the worktree. - shell: bash - run: git checkout "${{ steps.save-ref.outputs.ref }}" + run: git worktree remove /tmp/gh-pages # Output the default GitHub Pages URL for the deployed subdirectory. - id: url diff --git a/.github/actions/update-index/action.yml b/.github/actions/update-index/action.yml index 133ae26..3f42f7f 100644 --- a/.github/actions/update-index/action.yml +++ b/.github/actions/update-index/action.yml @@ -12,11 +12,21 @@ inputs: runs: using: composite steps: + # Create a worktree for gh-pages. + - shell: bash + run: git worktree add /tmp/gh-pages gh-pages + + # Generate index.html, commit, and push. - shell: bash run: | + cd /tmp/gh-pages python "${{ github.action_path }}/generate_index.py" \ "${{ inputs.repo-name }}" \ "${{ inputs.repo-url }}" git add index.html git diff --cached --quiet || git commit -m "Update index.html" git push origin gh-pages + + # Clean up the worktree. + - shell: bash + run: git worktree remove /tmp/gh-pages diff --git a/.github/workflows/docs-release.yml b/.github/workflows/docs-release.yml index f343c5e..eaee5a3 100644 --- a/.github/workflows/docs-release.yml +++ b/.github/workflows/docs-release.yml @@ -49,10 +49,15 @@ jobs: - name: Update latest run: | + git worktree add /tmp/gh-pages gh-pages + cd /tmp/gh-pages rm -rf latest cp -r "${{ steps.build.outputs.site-dir }}" latest git add latest git commit -m "Update latest" + git push origin gh-pages + + - run: git worktree remove /tmp/gh-pages - uses: ./.github/actions/update-index with: