@@ -23,6 +23,8 @@ cancel-in-progress: true
jobs:
build:
+ outputs:
+ pages_enabled: ${{ steps.pages.outputs.enabled }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
@@ -32,11 +34,72 @@ with: python-version: "3.14"
- id: pages
+ name: Read the Pages configuration
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: |
+ python - <<'PY'
+ import json
+ import os
+ from urllib.error import HTTPError
+ from urllib.request import Request, urlopen
+
+ owner = os.environ["GITHUB_REPOSITORY_OWNER"]
+ repository = os.environ["GITHUB_REPOSITORY"].split("/", 1)[1]
+ account_site = repository.casefold() == f"{owner}.github.io".casefold()
+ project = "" if account_site else f"/{repository}"
+ default_url = f"https://{owner}.github.io{project}"
+
+ headers = {
+ "Accept": "application/vnd.github+json",
+ "X-GitHub-Api-Version": "2026-03-10",
+ }
+ if os.environ.get("GH_TOKEN"):
+ headers["Authorization"] = f"Bearer {os.environ['GH_TOKEN']}"
+
+ request = Request(
+ f"https://api.github.com/repos/{os.environ['GITHUB_REPOSITORY']}/pages",
+ headers=headers,
+ )
+
+ try:
+ with urlopen(request) as response:
+ data = json.load(response)
+ except HTTPError as error:
+ if error.code != 404:
+ raise
+ data = None
+
+ enabled = bool(
+ data and data.get("build_type") in (None, "workflow")
+ )
+ site_url = data.get("html_url", default_url) if data else default_url
+
+ with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
+ output.write(f"enabled={str(enabled).lower()}\n")
+ output.write(f"site_url={site_url.rstrip('/')}\n")
+
+ if not enabled:
+ message = (
+ "GitHub Pages is not enabled with GitHub Actions. "
+ "The site will be built and checked, but deployment is skipped. "
+ "Select Settings > Pages > Source > GitHub Actions and rerun this workflow."
+ )
+ print(f"::warning title=GitHub Pages is not enabled::{message}")
+ with open(
+ os.environ["GITHUB_STEP_SUMMARY"],
+ "a",
+ encoding="utf-8",
+ ) as summary:
+ summary.write(f"## Deployment skipped\n\n{message}\n")
+ PY
+
+ - if: steps.pages.outputs.enabled == 'true'
uses: actions/configure-pages@v6
- name: Point the site at its published address
env:
- SITE_URL: ${{ steps.pages.outputs.base_url }}
+ SITE_URL: ${{ steps.pages.outputs.site_url }}
run: |
python - <<'PY'
import os
@@ -69,6 +132,7 @@ path: example/public
deploy:
needs: build
+ if: needs.build.outputs.pages_enabled == 'true'
runs-on: ubuntu-latest
environment:
name: github-pages
@@ -29,6 +29,8 @@ The workflow reads the public URL from GitHub itself. Project sites live below
the repository name, such as `/mdssg/`, and mdssg keeps that path in links,
assets, feeds, canonical URLs and the sitemap. No `pip install` step is needed.
+Before Pages is enabled, the workflow still builds, checks and uploads the
+artifact, then skips deployment with a clear warning instead of failing.
### Netlify, Vercel, Cloudflare Pages