Skip to content

Commit 157e48e

Browse files
TaiSakumaclaude
andauthored
fix: use git worktree for gh-pages operations (#23)
## Summary - Replace branch switching with `git worktree` in `deploy-to-gh-pages` and `update-index` actions - The main checkout is never disturbed, fixing the error where `update-index` action could not be found after deploying - Update "Update latest" step in `docs-release.yml` to use worktree as well ## Test plan - [ ] Push to main → `/dev/` deployed, `index.html` updated (no action lookup error) - [ ] Push a tag → `/<version>/`, `/latest/`, and `index.html` all updated 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 959aef8 commit 157e48e

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

.github/actions/deploy-to-gh-pages/action.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,39 @@ inputs:
1515
outputs:
1616
url:
1717
description: Default GitHub Pages URL for the deployed subdirectory
18-
value: ${{ steps.deploy.outputs.url }}
18+
value: ${{ steps.url.outputs.url }}
1919

2020
runs:
2121
using: composite
2222
steps:
23-
- id: deploy
24-
shell: bash
23+
# Create a worktree for gh-pages.
24+
- shell: bash
2525
run: |
26-
TARGET="${{ inputs.target }}"
2726
git fetch origin gh-pages 2>/dev/null || true
2827
if git rev-parse --verify origin/gh-pages >/dev/null 2>&1; then
29-
git checkout -B gh-pages origin/gh-pages
28+
git worktree add /tmp/gh-pages gh-pages
3029
else
31-
git checkout --orphan gh-pages
32-
git rm -rf .
33-
git clean -fd
30+
git worktree add --orphan -b gh-pages /tmp/gh-pages
3431
fi
32+
33+
# Copy the built site into the target subdirectory, commit, and push.
34+
- shell: bash
35+
run: |
36+
cd /tmp/gh-pages
37+
TARGET="${{ inputs.target }}"
3538
rm -rf "$TARGET"
3639
mkdir -p "$(dirname "$TARGET")"
3740
cp -r "${{ inputs.site-dir }}" "$TARGET"
3841
touch .nojekyll
3942
git add .nojekyll "$TARGET"
4043
git diff --cached --quiet || git commit -m "${{ inputs.commit-message }}"
4144
git push origin gh-pages
42-
echo "url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${TARGET}/" >> "$GITHUB_OUTPUT"
45+
46+
# Clean up the worktree.
47+
- shell: bash
48+
run: git worktree remove /tmp/gh-pages
49+
50+
# Output the default GitHub Pages URL for the deployed subdirectory.
51+
- id: url
52+
shell: bash
53+
run: echo "url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ inputs.target }}/" >> "$GITHUB_OUTPUT"

.github/actions/update-index/action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@ inputs:
1212
runs:
1313
using: composite
1414
steps:
15+
# Create a worktree for gh-pages.
16+
- shell: bash
17+
run: git worktree add /tmp/gh-pages gh-pages
18+
19+
# Generate index.html, commit, and push.
1520
- shell: bash
1621
run: |
22+
cd /tmp/gh-pages
1723
python "${{ github.action_path }}/generate_index.py" \
1824
"${{ inputs.repo-name }}" \
1925
"${{ inputs.repo-url }}"
2026
git add index.html
2127
git diff --cached --quiet || git commit -m "Update index.html"
2228
git push origin gh-pages
29+
30+
# Clean up the worktree.
31+
- shell: bash
32+
run: git worktree remove /tmp/gh-pages

.github/workflows/docs-release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,15 @@ jobs:
4949

5050
- name: Update latest
5151
run: |
52+
git worktree add /tmp/gh-pages gh-pages
53+
cd /tmp/gh-pages
5254
rm -rf latest
5355
cp -r "${{ steps.build.outputs.site-dir }}" latest
5456
git add latest
5557
git commit -m "Update latest"
58+
git push origin gh-pages
59+
60+
- run: git worktree remove /tmp/gh-pages
5661

5762
- uses: ./.github/actions/update-index
5863
with:

0 commit comments

Comments
 (0)