|
| 1 | +name: Generate Docs |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - 'site/**' |
| 8 | + - '.github/workflows/generate-docs.yml' |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + pages: write |
| 14 | + id-token: write |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: pages |
| 18 | + cancel-in-progress: false |
| 19 | + |
| 20 | +jobs: |
| 21 | + build: |
| 22 | + name: Build landing page |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Checkout repository |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Configure GitHub Pages |
| 29 | + uses: actions/configure-pages@v5 |
| 30 | + |
| 31 | + - name: Stage static site |
| 32 | + run: | |
| 33 | + set -euo pipefail |
| 34 | + mkdir -p _site |
| 35 | + cp -r site/. _site/ |
| 36 | + # disable Jekyll processing so files are served verbatim |
| 37 | + touch _site/.nojekyll |
| 38 | + # record build metadata (no personal data) |
| 39 | + date -u +"%Y-%m-%dT%H:%M:%SZ" > _site/build.txt |
| 40 | +
|
| 41 | + - name: Validate (no external resources) |
| 42 | + run: | |
| 43 | + set -euo pipefail |
| 44 | + python - <<'PY' |
| 45 | + from html.parser import HTMLParser |
| 46 | + from pathlib import Path |
| 47 | +
|
| 48 | + RESOURCE_ATTRIBUTES = { |
| 49 | + ("script", "src"), |
| 50 | + ("img", "src"), |
| 51 | + ("img", "srcset"), |
| 52 | + ("iframe", "src"), |
| 53 | + ("audio", "src"), |
| 54 | + ("video", "src"), |
| 55 | + ("track", "src"), |
| 56 | + ("source", "src"), |
| 57 | + ("source", "srcset"), |
| 58 | + ("embed", "src"), |
| 59 | + ("object", "data"), |
| 60 | + } |
| 61 | +
|
| 62 | + LINK_RESOURCE_RELS = { |
| 63 | + "stylesheet", |
| 64 | + "icon", |
| 65 | + "apple-touch-icon", |
| 66 | + "manifest", |
| 67 | + "preload", |
| 68 | + "modulepreload", |
| 69 | + "prefetch", |
| 70 | + "dns-prefetch", |
| 71 | + "preconnect", |
| 72 | + "mask-icon", |
| 73 | + "shortcut icon", |
| 74 | + } |
| 75 | +
|
| 76 | + def external_values(raw_value: str): |
| 77 | + for candidate in raw_value.split(","): |
| 78 | + value = candidate.strip().split(" ", 1)[0] |
| 79 | + if value.startswith(("http://", "https://", "//")): |
| 80 | + yield value |
| 81 | +
|
| 82 | + class ResourceParser(HTMLParser): |
| 83 | + def __init__(self, path: Path): |
| 84 | + super().__init__() |
| 85 | + self.path = path |
| 86 | + self.violations = [] |
| 87 | +
|
| 88 | + def handle_starttag(self, tag, attrs): |
| 89 | + attr_map = dict(attrs) |
| 90 | + rel_tokens = set(attr_map.get("rel", "").lower().split()) |
| 91 | +
|
| 92 | + for name, value in attrs: |
| 93 | + if not value: |
| 94 | + continue |
| 95 | +
|
| 96 | + if (tag, name) in RESOURCE_ATTRIBUTES: |
| 97 | + for external in external_values(value): |
| 98 | + self.violations.append((tag, name, external)) |
| 99 | +
|
| 100 | + if tag == "link" and name == "href": |
| 101 | + rel_value = attr_map.get("rel", "").lower().strip() |
| 102 | + if rel_tokens & LINK_RESOURCE_RELS or rel_value in LINK_RESOURCE_RELS: |
| 103 | + for external in external_values(value): |
| 104 | + self.violations.append((tag, name, external)) |
| 105 | +
|
| 106 | + violations = [] |
| 107 | + for path in Path("_site").rglob("*.html"): |
| 108 | + parser = ResourceParser(path) |
| 109 | + parser.feed(path.read_text(encoding="utf-8")) |
| 110 | + violations.extend((path, *violation) for violation in parser.violations) |
| 111 | +
|
| 112 | + if violations: |
| 113 | + for path, tag, attr, value in violations: |
| 114 | + print(f"{path}: external resource via <{tag} {attr}=\"{value}\">", flush=True) |
| 115 | + raise SystemExit("ERROR: external resource reference found — landing page must be self-contained.") |
| 116 | + PY |
| 117 | +
|
| 118 | + - name: Upload Pages artifact |
| 119 | + uses: actions/upload-pages-artifact@v3 |
| 120 | + with: |
| 121 | + path: _site |
| 122 | + |
| 123 | + deploy: |
| 124 | + name: Deploy to GitHub Pages |
| 125 | + needs: build |
| 126 | + runs-on: ubuntu-latest |
| 127 | + environment: |
| 128 | + name: github-pages |
| 129 | + url: ${{ steps.deployment.outputs.page_url }} |
| 130 | + steps: |
| 131 | + - name: Deploy |
| 132 | + id: deployment |
| 133 | + uses: actions/deploy-pages@v4 |
0 commit comments