Skip to content

Commit 7281778

Browse files
committed
Skip docs deployment gracefully when GitHub Pages is disabled
- Add pages-enabled check in deploy-docs gate - Skip deploy-docs with notice when Pages is not enabled - Keep docs URL visible in summary and docs guidance Made-with: Cursor
1 parent e7c6d5b commit 7281778

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,34 +462,48 @@ jobs:
462462
- name: Check for DocFX configuration
463463
id: check-docs
464464
shell: bash
465+
env:
466+
GH_TOKEN: ${{ github.token }}
465467
run: |
468+
HAS_DOCS="false"
466469
if [ -f "docs/docfx.json" ]; then
467-
echo "has_docs=true" >> "$GITHUB_OUTPUT"
470+
HAS_DOCS="true"
468471
else
469472
echo "::notice::No docs/docfx.json found. Skipping documentation deployment."
470-
echo "has_docs=false" >> "$GITHUB_OUTPUT"
473+
fi
474+
475+
HAS_PAGES="$(gh api repos/${{ github.repository }} --jq '.has_pages' 2>/dev/null || echo "false")"
476+
if [ "$HAS_PAGES" != "true" ]; then
477+
echo "::notice::GitHub Pages is not enabled. Enable Settings > Pages > Source: GitHub Actions."
478+
HAS_PAGES="false"
479+
fi
480+
481+
if [ "$HAS_DOCS" = "true" ] && [ "$HAS_PAGES" = "true" ]; then
482+
echo "should_deploy=true" >> "$GITHUB_OUTPUT"
483+
else
484+
echo "should_deploy=false" >> "$GITHUB_OUTPUT"
471485
fi
472486
473487
- uses: actions/setup-dotnet@v5
474-
if: steps.check-docs.outputs.has_docs == 'true'
488+
if: steps.check-docs.outputs.should_deploy == 'true'
475489
with:
476490
global-json-file: global.json
477491

478492
- name: Restore .NET tools
479-
if: steps.check-docs.outputs.has_docs == 'true'
493+
if: steps.check-docs.outputs.should_deploy == 'true'
480494
run: dotnet tool restore
481495

482496
- name: Build documentation
483-
if: steps.check-docs.outputs.has_docs == 'true'
497+
if: steps.check-docs.outputs.should_deploy == 'true'
484498
run: dotnet docfx docs/docfx.json
485499

486500
- name: Upload pages artifact
487-
if: steps.check-docs.outputs.has_docs == 'true'
501+
if: steps.check-docs.outputs.should_deploy == 'true'
488502
uses: actions/upload-pages-artifact@v3
489503
with:
490504
path: docs/_site
491505

492506
- name: Deploy to GitHub Pages
493-
if: steps.check-docs.outputs.has_docs == 'true'
507+
if: steps.check-docs.outputs.should_deploy == 'true'
494508
id: deployment
495509
uses: actions/deploy-pages@v4

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ To enable automatic documentation deployment to GitHub Pages:
154154
4. Expected docs URL: `https://<owner>.github.io/<repo>/` (for this repo: `https://agibuild.github.io/dotnet.CI.template/`)
155155

156156
The `Resolve Version` job summary always shows this expected docs URL, even when docs deployment is skipped.
157+
If Pages is not enabled, `deploy-docs` is skipped with a notice instead of failing the whole workflow.
157158

158159
---
159160

docs/github-workflows-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ push / PR to main + weekly
6060
### `deploy-docs`
6161
- 依赖 `release` 成功后自动运行
6262
- 如果存在 `docs/docfx.json`,构建 DocFX 并部署到 GitHub Pages
63-
- 如果不存在则跳过
63+
- 如果未启用 GitHub Pages 或缺少 DocFX 配置,则自动跳过并给出 notice,不会导致整条流水线失败
6464

6565
---
6666

0 commit comments

Comments
 (0)