Skip to content

docfx: sync from repo-template (gh-pages bootstrap fix)#150

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

docfx: sync from repo-template (gh-pages bootstrap fix)#150
Chris-Wolfgang merged 2 commits into
mainfrom
fix/docfx-bootstrap-gh-pages

Conversation

@Chris-Wolfgang

Copy link
Copy Markdown
Owner

Summary

Sync .github/workflows/docfx.yaml from repo-template to pick up the gh-pages bootstrap fix from 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

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>
Copilot AI review requested due to automatic review settings May 9, 2026 17:17

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

Note

Copilot was unable to run its full agentic suite in this review.

Syncs the DocFX GitHub Pages deployment workflow with repo-template to fix first-time deployments when the gh-pages branch doesn’t exist yet.

Changes:

  • Detects whether gh-pages exists and chooses between a worktree-based deploy vs. bootstrapping a fresh repo.
  • Bootstraps a new gh-pages repo (init + authenticated remote) when the branch is missing to avoid “not a git repository” failures.
  • Adjusts cleanup to remove either the worktree or the freshly initialized directory, and resets $LASTEXITCODE after cleanup.

Comment thread .github/workflows/docfx.yaml Outdated
Comment thread .github/workflows/docfx.yaml Outdated
Reworks the gh-pages deploy block to match repo-template:

- Authenticate via `git config http.extraheader` with a base64-encoded
  `x-access-token:$GITHUB_TOKEN` header instead of embedding the token
  directly in the remote URL. The plain `https://github.com/owner/repo.git`
  remote stays out of `git remote -v` output, error messages, and
  per-repo `.git/config`.
- Wrap the entire deploy in `try { ... } finally { ... }`. The finally
  block always unsets the extraheader so the token cannot linger in the
  runner's global git config for subsequent steps, even if the try
  block hits an early `exit` (failed `ls-remote`, missing template).
- Distinguish "ls-remote succeeded with empty output (branch missing)"
  from "ls-remote failed (auth/network)" via `$LASTEXITCODE`, so a
  transient failure does not silently route into the bootstrap path
  and clobber an existing gh-pages branch.
- Capture `$deployExitCode` before cleanup so cleanup noise cannot mask
  a real push failure, then explicit `exit` at the end of the script.

Addresses the Copilot review comment about token-in-URL on PR #150.
The `git init --initial-branch=` form is kept as-is — GitHub-hosted
runners ship Git ≥ 2.40 on every supported image, so the Git 2.28
floor is not a concern.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

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