Skip to content

docfx: bootstrap gh-pages branch on first deploy#337

Merged
Chris-Wolfgang merged 2 commits into
mainfrom
fix/docfx-bootstrap-gh-pages
May 9, 2026
Merged

docfx: bootstrap gh-pages branch on first deploy#337
Chris-Wolfgang merged 2 commits into
mainfrom
fix/docfx-bootstrap-gh-pages

Conversation

@Chris-Wolfgang

Copy link
Copy Markdown
Owner

Summary

  • The "Deploy docs to GitHub Pages" step had a latent bug: when gh-pages did not yet exist on the remote, $WORK_DIR was created as a plain directory and the subsequent git add / diff --cached / commit / push calls all failed with fatal: not a git repository (and error: unknown option 'cached').
  • Fix: after creating the empty $WORK_DIR, initialize it as a git repo on the gh-pages branch and add the authenticated origin remote, so the existing add/commit/push flow works on the first-ever deploy.

Reproduction

Hit in IComparable-Extensions, run 25606117292. Workaround was to manually create an orphan gh-pages branch with .nojekyll and re-run.

Downstream impact

This is repo-template — once merged, the change should propagate to all downstream repos via the standard pr.yaml / docfx.yaml template sync. Reviewers and downstream maintainers should expect to see this as part of the next sync PR in each consuming repo.

Test plan

  • Merge and let the next downstream sync pick it up
  • Verify on a repo with no gh-pages branch that the first docs deploy succeeds end-to-end (init → add → commit → push)
  • Confirm existing repos (with gh-pages already present) are unaffected — the change only runs in the else branch

When gh-pages did not yet exist on the remote, the deploy step created
$WORK_DIR as a plain directory and then ran git add/diff/commit/push
against it, which failed with "fatal: not a git repository". Initialize
the directory as a git repo on the gh-pages branch and wire up the
authenticated origin remote so the existing add/commit/push works.

Reproduced in IComparable-Extensions (run 25606117292); workaround was
to manually create an orphan gh-pages branch with .nojekyll.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 9, 2026 16:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the DocFX GitHub Actions workflow to support the first-ever docs deployment in repositories that do not yet have a gh-pages branch, by creating a valid git repository in the temporary deploy directory so the existing add/commit/push sequence can run successfully.

Changes:

  • When gh-pages is missing, create $WORK_DIR and initialize it as a git repo on gh-pages.
  • Add an authenticated origin remote in $WORK_DIR so the later push works in the bootstrap case.

Comment thread .github/workflows/docfx.yaml
When gh-pages did not yet exist, $WORK_DIR is initialized as a
standalone repo, not a worktree of the main checkout. The trailing
`git worktree remove $WORK_DIR --force` then fails with a non-zero
exit (the directory is not a registered worktree), which fails the
step on the first deploy.

Track whether a worktree was created with $useWorktree, and at cleanup
time either remove the worktree or just delete the directory. Also
reset $LASTEXITCODE so any residual cleanup noise does not fail the
step.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Chris-Wolfgang Chris-Wolfgang merged commit 4f85d51 into main May 9, 2026
7 checks passed
@Chris-Wolfgang Chris-Wolfgang deleted the fix/docfx-bootstrap-gh-pages branch May 9, 2026 17:09
This was referenced May 9, 2026
Chris-Wolfgang added a commit to Chris-Wolfgang/IComparable-Extensions that referenced this pull request May 9, 2026
Sync .github/workflows/docfx.yaml from canonical repo-template to pick up the bootstrap fix from Chris-Wolfgang/repo-template#337.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Chris-Wolfgang added a commit to Chris-Wolfgang/DbContextBuilder that referenced this pull request May 9, 2026
## Summary
Sync `.github/workflows/docfx.yaml` from `repo-template` to pick up the
gh-pages bootstrap fix from
[Chris-Wolfgang/repo-template#337](Chris-Wolfgang/repo-template#337).

## What changed
The "Deploy docs to GitHub Pages" step had a latent bug: when the
`gh-pages` branch did not yet exist on the remote, `$WORK_DIR` was
created as a plain directory and the subsequent `git add` / `diff
--cached` / `commit` / `push` failed with `fatal: not a git repository`.
The fix initializes the directory as a git repo on `gh-pages` and adds
the authenticated `origin` remote, so the existing add/commit/push works
on a first-ever deploy. Cleanup also branches between `git worktree
remove` (worktree path) and `Remove-Item` (fresh-repo path).

If `gh-pages` already exists in this repo (the common case), this change
is a no-op at runtime — the bootstrap branch is only taken on a fresh
repo.

## Test plan
- [ ] Workflow YAML lints / next docs deploy succeeds
- [ ] (Optional) verify `gh-pages` is unaffected
Chris-Wolfgang added a commit to Chris-Wolfgang/IEnumerable-Extensions that referenced this pull request May 9, 2026
Sync .github/workflows/docfx.yaml from canonical repo-template to pick up the bootstrap fix from Chris-Wolfgang/repo-template#337.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Chris-Wolfgang added a commit to Chris-Wolfgang/ETL-FixedWidth that referenced this pull request May 14, 2026
Sync .github/workflows/docfx.yaml from canonical repo-template to pick up the bootstrap fix from Chris-Wolfgang/repo-template#337.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Chris-Wolfgang added a commit to Chris-Wolfgang/ETL-Transformers that referenced this pull request May 14, 2026
Sync .github/workflows/docfx.yaml from canonical repo-template to pick up the bootstrap fix from Chris-Wolfgang/repo-template#337.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Chris-Wolfgang added a commit to Chris-Wolfgang/ETL-Xml that referenced this pull request May 14, 2026
Sync .github/workflows/docfx.yaml from canonical repo-template to pick up the bootstrap fix from Chris-Wolfgang/repo-template#337.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Chris-Wolfgang added a commit to Chris-Wolfgang/ETL-Test-Kit that referenced this pull request May 14, 2026
Sync .github/workflows/docfx.yaml from canonical repo-template to pick up the bootstrap fix from Chris-Wolfgang/repo-template#337.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Chris-Wolfgang added a commit to Chris-Wolfgang/ETL-Transformers that referenced this pull request Jun 19, 2026
Sync .github/workflows/docfx.yaml from canonical repo-template to pick up the bootstrap fix from Chris-Wolfgang/repo-template#337.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants