Skip to content

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

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

docfx: sync from repo-template (gh-pages bootstrap fix)#95
Chris-Wolfgang merged 1 commit 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 Actions workflow with the repo template to fix first-time gh-pages deployments and improve the deployment flow.

Changes:

  • Bootstraps a new gh-pages branch by initializing a git repo in $WORK_DIR and adding an authenticated origin remote.
  • Adds a gh-pages root stale-file cleanup step (preserving versions/, CNAME, .nojekyll) before deploying latest docs.
  • Updates tag ordering logic to use a custom full SemVer precedence comparison (including prerelease identifiers).

Comment on lines +173 to +174
if ($i -ge $aIds.Length) { return -1 } # a has fewer identifiers -> lower precedence
if ($i -ge $bIds.Length) { return 1 } # b has fewer identifiers -> lower precedence

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@claude review

Comment on lines +179 to +184
$aIsNum = [int]::TryParse($aId, [ref]([int]$null))
$bIsNum = [int]::TryParse($bId, [ref]([int]$null))

if ($aIsNum -and $bIsNum) {
$aVal = [int]$aId
$bVal = [int]$bId
Comment on lines +139 to +140
# Sort descending by full SemVer precedence (Major, Minor, Patch, Stable, PreRelease)
# Convert to a mutable list so we can use a custom comparison for proper SemVer prerelease ordering.
Comment on lines +224 to +234
# Before deploying the latest docs to the site root, remove any pre-existing
# root-level files and folders from the gh-pages branch (except the versions/
# directory, CNAME, and .nojekyll) so that stale DocFX assets from a previous
# build do not linger on the live site.
# The versions/ folder is preserved so that all versioned docs remain accessible
# while the root is refreshed with the new build.
if: inputs.deploy_to_pages != false && inputs.deploy_as_latest != false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: pwsh
run: |
Comment on lines +223 to +282
- name: Clean up stale root files from gh-pages
# Before deploying the latest docs to the site root, remove any pre-existing
# root-level files and folders from the gh-pages branch (except the versions/
# directory, CNAME, and .nojekyll) so that stale DocFX assets from a previous
# build do not linger on the live site.
# The versions/ folder is preserved so that all versioned docs remain accessible
# while the root is refreshed with the new build.
if: inputs.deploy_to_pages != false && inputs.deploy_as_latest != false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: pwsh
run: |
$branchExists = git ls-remote --heads origin gh-pages
if (-not $branchExists) {
Write-Host "ℹ️ gh-pages branch does not exist yet – skipping stale-file cleanup."
exit 0
}

git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git remote set-url origin "https://x-access-token:$($env:GITHUB_TOKEN)@github.com/$($env:GITHUB_REPOSITORY).git"

git fetch origin gh-pages
# Create a local tracking branch only if it does not already exist
git show-ref --verify --quiet refs/heads/gh-pages
if ($LASTEXITCODE -ne 0) {
git branch gh-pages origin/gh-pages
}

$WORK_DIR = Join-Path $env:RUNNER_TEMP 'gh-pages-clean'
# Remove a leftover worktree from a previous failed run, if any
git worktree remove "$WORK_DIR" --force 2>&1 | Out-Null
if (Test-Path $WORK_DIR) { Remove-Item $WORK_DIR -Recurse -Force }
git worktree add "$WORK_DIR" gh-pages

# Remove all root-level items EXCEPT:
# .git – Git metadata (worktree pointer file)
# CNAME – Custom domain config (if present)
# .nojekyll – Tells GitHub Pages not to run Jekyll
# versions/ – All versioned docs (v1.0.0/, latest/, etc.)
Get-ChildItem -Path $WORK_DIR -Force | Where-Object {
$_.Name -ne '.git' -and
$_.Name -ne 'CNAME' -and
$_.Name -ne '.nojekyll' -and
$_.Name -ne 'versions'
} | Remove-Item -Recurse -Force

git -C "$WORK_DIR" add -A
git -C "$WORK_DIR" diff --cached --quiet
if ($LASTEXITCODE -ne 0) {
git -C "$WORK_DIR" commit `
-m "chore: clean up stale root DocFX assets before redeploy [skip ci]"
git -C "$WORK_DIR" push origin HEAD:gh-pages
Write-Host "✅ Stale root files removed from gh-pages."
} else {
Write-Host "ℹ️ No stale files found in gh-pages root – nothing to clean."
}

git worktree remove "$WORK_DIR" --force

Comment on lines +351 to +352
git -C $WORK_DIR init --initial-branch=gh-pages
git -C $WORK_DIR remote add origin "https://x-access-token:$($env:GITHUB_TOKEN)@github.com/$($env:GITHUB_REPOSITORY).git"
@Chris-Wolfgang Chris-Wolfgang merged commit 164372e into main May 9, 2026
11 of 12 checks passed
Chris-Wolfgang pushed a commit that referenced this pull request May 9, 2026
…ng order)

Mirrors repo-template#341 — same fix into IEnumerable-Extensions's
docfx.yaml. The SemVer prerelease comparator's 'fewer prerelease ids'
branches were returning the wrong sign for the descending sort.

Per SemVer §11.4.4, fewer prerelease ids = lower precedence
(1.0.0-alpha < 1.0.0-alpha.1). For descending order (newest first),
the lower-precedence value sorts AFTER the higher-precedence one, so
'a has fewer ids' must return positive (place 'a' second).

Caught by Copilot review on PR #95.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Chris-Wolfgang Chris-Wolfgang deleted the fix/docfx-bootstrap-gh-pages branch May 30, 2026 02:37
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