fix: make docs workflow deploy step conditional on GitHub Pages being enabled#81
fix: make docs workflow deploy step conditional on GitHub Pages being enabled#81
Conversation
… enabled Co-authored-by: pmalarme <686568+pmalarme@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes the python-docs.yml workflow which was failing because GitHub Pages is not enabled in the template repository. The fix adds a pre-deployment check to detect if GitHub Pages is configured and gracefully skips deployment when it's not available, while still building the documentation successfully.
Changes:
- Added GitHub Pages status check using the GitHub API to detect if Pages is enabled
- Made the deploy job conditional based on the Pages availability check
- Added informational notice when Pages is not configured instead of failing
| STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ | ||
| -H "Authorization: Bearer ${GH_TOKEN}" \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| "https://api.github.com/repos/${{ github.repository }}/pages") | ||
| if [ "${STATUS}" = "200" ]; then | ||
| echo "enabled=true" >> "${GITHUB_OUTPUT}" | ||
| else | ||
| echo "enabled=false" >> "${GITHUB_OUTPUT}" | ||
| echo "::notice::GitHub Pages is not configured for this repository. Skipping deployment." | ||
| fi |
There was a problem hiding this comment.
The STATUS variable extracted from curl output is written to GITHUB_OUTPUT without validation. According to the repository's security practices (see .github/workflows/python-release.yml:66 and .github/workflows/monorepo-release.yml:44), extracted values should be validated with regex patterns before writing to GITHUB_OUTPUT to prevent newline injection attacks.
The HTTP status code should be validated to ensure it contains only digits before being used in the conditional. While the current code writes "enabled=true" or "enabled=false" (which are safe), the STATUS variable itself should still be validated as a defense-in-depth measure.
Suggested validation:
- Add a check like: if [[ ! "$STATUS" =~ ^[0-9]+$ ]]; then echo "::error::Invalid HTTP status received"; exit 1; fi
Summary
The
python-docs.ymlworkflow was failing on thedeploy to GitHub Pagesjob with a 404 because GitHub Pages is not enabled in this template repository. Thebuild docsjob succeeded; only deployment was broken.Changes to
.github/workflows/python-docs.yml:outputsblock tobuildjob exposingpages-enabledCheck GitHub Pages statusstep (post-artifact-upload) that hits the GitHub API and setsenabled=true/false— emits a workflow notice when Pages is not configuredif: needs.build.outputs.pages-enabled == 'true'guard to thedeployjob so it skips gracefully instead of failing when Pages is not set upWhen Pages is enabled in repo settings, the deploy job runs as before. When it isn't (e.g. in a fresh clone of this template), the workflow passes with a skipped deploy and an informational notice.
Testing
uv run poe checkChecklist
Additional context
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.