diff --git a/.github/actions/deploy-to-gh-pages/action.yml b/.github/actions/deploy-to-gh-pages/action.yml index 7c4b59d..1451cf6 100644 --- a/.github/actions/deploy-to-gh-pages/action.yml +++ b/.github/actions/deploy-to-gh-pages/action.yml @@ -15,23 +15,26 @@ 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 - shell: bash + # Create a worktree for gh-pages. + - 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 + 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")" cp -r "${{ inputs.site-dir }}" "$TARGET" @@ -39,4 +42,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" + + # Clean up the worktree. + - shell: bash + run: git worktree remove /tmp/gh-pages + + # 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" 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: