diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..4f85cd6 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,40 @@ +name: Check + +# The site has no build step, so its pages link brand.css with a version written by hand: /brand.css?v= and the first +# 10 hex of the file's sha256. GitHub Pages lets a browser reuse a file for 10 minutes, and the version gives a changed +# stylesheet a new URL, so a returning visitor never gets new HTML with an old cached brand.css. This fails when a +# page's version doesn't match the file, and prints the line to use. + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + check: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Stylesheet versions + run: | + python3 - <<'PY' + import hashlib, pathlib, re, sys + bad = 0 + for page in sorted(pathlib.Path(".").glob("*.html")): + text = page.read_text(encoding="utf-8") + for m in re.finditer(r'', text): + want = hashlib.sha256(pathlib.Path(m[1]).read_bytes()).hexdigest()[:10] + if m[2] != want: + print(f'::error file={page}::{m[0]} should be ') + bad += 1 + if re.search(r']*\bsrc=", text): + print(f"::error file={page}::links a stylesheet or script this check doesn't know; version it and extend the check") + bad += 1 + sys.exit(1 if bad else 0) + PY diff --git a/index.html b/index.html index 0b80b5f..da4105e 100644 --- a/index.html +++ b/index.html @@ -14,7 +14,7 @@ - +