diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 2cf6da91b7e..e51fdb49bc2 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -61,7 +61,10 @@ Features: - Uses the same data and announcement artifacts as `deploy.yaml`, with noindex and no analytics - Compares each build with its merge base with `main`: URL list, structured data, SEO tags and internal links. See `scripts/rebrand/README.md` - A failed check marks the run red but still updates the preview -- After the build, the comparison, the designed-screens check and the accessibility check run as three jobs side by side; the designed-screens check runs four browsers at once +- PRs build their base commit alongside the candidate with the same artifacts and regenerated Contributors page. The browser checks use the resulting HTML diff. The comparison with the merge base with `main` still covers the whole site. +- CSS or JS changes with no HTML changes run the core design sample and the usual axe sample. Core design covers the named screens, breakpoints, sample pages, home, floating controls at 390 and 1440 px, and every fourth article in the usual article set. +- Pushes, PRs labeled `full-checks`, PRs changing this workflow or the check scripts, and diffs over 60 pages run the full browser suite. With no relevant changes, both browser jobs report success without starting Chromium. +- Design and axe cache Chromium by Playwright version. - Delete this workflow when the redesign launches ## Data Workflows diff --git a/.github/workflows/rebrand-preview.yaml b/.github/workflows/rebrand-preview.yaml index ad6ba763559..444c3dbc5d8 100644 --- a/.github/workflows/rebrand-preview.yaml +++ b/.github/workflows/rebrand-preview.yaml @@ -9,9 +9,10 @@ name: Doors preview # Checks: Every run also builds the merge base with main from the same data, then compares # the two builds. # A failed check shows on the run but does not hold back the preview. -# Layout: "Build" builds the branch and shares it as an artifact. Three jobs then check it -# side by side: the comparison with main, the designed screens and the accessibility -# rules. "Check results" fails if any of them did. +# Layout: Shared inputs feed the branch build and, on scoped PRs, the PR base build. +# The browser checks use the changed pages or a core sample for CSS/JS-only changes. +# Pushes, the full-checks label, check infrastructure changes and large diffs use the full suite. +# "Compare with main" still checks the whole site. "Check results" aggregates failures. # Note: Uses the same data and announcement artifacts as deploy.yaml. Delete this # workflow when the redesign launches. @@ -20,6 +21,7 @@ on: branches: - rebrand-doors pull_request: + types: [opened, synchronize, reopened, labeled, unlabeled] branches: - rebrand-doors @@ -28,6 +30,7 @@ env: PYTHONUNBUFFERED: "1" # Output is flushed as it is printed, so the log's timestamps show which section is slow. HUGO_VERSION: "0.158.0" HUGO_EXTENDED: true + PLAYWRIGHT_VERSION: "1.63.0" PREVIEW_BASE: /rebrand-doors/ PREVIEW_URL: https://forrt.org/rebrand-doors/ @@ -36,14 +39,16 @@ concurrency: cancel-in-progress: true jobs: - build: - name: Build + inputs: + name: Prepare shared inputs runs-on: ubuntu-22.04 # Fork PRs get no artifacts token and have no preview to update. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository permissions: contents: read actions: read # Needed for artifact access + outputs: + scoped: ${{ steps.scope.outputs.scoped }} steps: # Full history for Hugo's Git dates, with file contents fetched only for the commit # checked out (as in staging-aggregate.yaml). @@ -58,6 +63,19 @@ jobs: - name: Let Git report non-ASCII paths unquoted run: git config core.quotepath false + - name: Select full or scoped checks + id: scope + env: + EVENT: ${{ github.event_name }} + BASE_SHA: ${{ github.event.pull_request.base.sha }} + FULL_LABEL: ${{ contains(github.event.pull_request.labels.*.name, 'full-checks') }} + run: | + if [ "$EVENT" != pull_request ] || [ "$FULL_LABEL" = true ]; then + echo "scoped=false" >> "$GITHUB_OUTPUT" + else + echo "scoped=true" >> "$GITHUB_OUTPUT" + fi + # ======================= # Artifacts, as in deploy.yaml # ======================= @@ -110,7 +128,8 @@ jobs: - name: Pack the artifacts for the reference build run: | mkdir -p "$RUNNER_TEMP/artifacts/data" "$RUNNER_TEMP/artifacts/announcements" - tar -cf inputs.tar -C "$RUNNER_TEMP" artifacts + cp content/contributors/tenzing.md "$RUNNER_TEMP/contributors.md" + tar -cf inputs.tar -C "$RUNNER_TEMP" artifacts contributors.md - name: Upload the artifacts for the reference build uses: actions/upload-artifact@v7 @@ -121,6 +140,33 @@ jobs: overwrite: true if-no-files-found: error + build: + name: Build + runs-on: ubuntu-22.04 + needs: inputs + steps: + - name: Checkout repository + uses: actions/checkout@v6 + with: + fetch-depth: 0 + filter: blob:none + + - name: Let Git report non-ASCII paths unquoted + run: git config core.quotepath false + + - name: Download shared inputs + uses: actions/download-artifact@v7 + with: + name: rebrand-inputs-${{ github.run_number }} + path: ${{ runner.temp }} + + - name: Apply shared inputs + run: | + tar -xf "$RUNNER_TEMP/inputs.tar" -C "$RUNNER_TEMP" + scripts/rebrand/apply_artifacts.sh . \ + "$RUNNER_TEMP/artifacts/data" "$RUNNER_TEMP/artifacts/announcements" + cp "$RUNNER_TEMP/contributors.md" content/contributors/tenzing.md + - name: Setup Hugo uses: peaceiris/actions-hugo@75d2e84710de30f6ff7268e08f310b60ef14033f with: @@ -150,6 +196,110 @@ jobs: overwrite: true # A rerun reuses the run number. if-no-files-found: error + reference: + name: Build PR base + runs-on: ubuntu-22.04 + needs: inputs + if: needs.inputs.outputs.scoped == 'true' + steps: + - name: Checkout repository + uses: actions/checkout@v6 + with: + fetch-depth: 0 + filter: blob:none + + - name: Let Git report non-ASCII paths unquoted + run: git config core.quotepath false + + - name: Check out the PR base + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + run: git worktree add --detach "$RUNNER_TEMP/pr-base" "$BASE_SHA" + + - name: Download shared inputs + uses: actions/download-artifact@v7 + with: + name: rebrand-inputs-${{ github.run_number }} + path: ${{ runner.temp }} + + - name: Apply shared inputs + run: | + tar -xf "$RUNNER_TEMP/inputs.tar" -C "$RUNNER_TEMP" + scripts/rebrand/apply_artifacts.sh "$RUNNER_TEMP/pr-base" \ + "$RUNNER_TEMP/artifacts/data" "$RUNNER_TEMP/artifacts/announcements" + cp "$RUNNER_TEMP/contributors.md" "$RUNNER_TEMP/pr-base"/content/contributors/tenzing.md + + - name: Setup Hugo + uses: peaceiris/actions-hugo@75d2e84710de30f6ff7268e08f310b60ef14033f + with: + hugo-version: ${{ env.HUGO_VERSION }} + extended: ${{ env.HUGO_EXTENDED }} + + # HUGO_ENV=staging adds noindex and leaves out Google Analytics. + - name: Build the PR base + working-directory: ${{ runner.temp }}/pr-base + run: hugo --gc --minify --destination "$GITHUB_WORKSPACE/public" --baseURL "$PREVIEW_URL" + env: + HUGO_ENV: staging + + - name: Point root-relative links at the subfolder + run: python3 scripts/rebrand/preview_paths.py public --base "$PREVIEW_BASE" + + - name: Pack pages and bundles + working-directory: public + run: find . -type f \( -name '*.html' -o -name '*.css' -o -name '*.js' \) -print0 | tar --null -T - -cf ../site.tar + + - name: Upload site artifact + uses: actions/upload-artifact@v7 + with: + name: rebrand-pr-base-${{ github.run_number }} + path: site.tar + retention-days: 1 + compression-level: 1 + overwrite: true # A rerun reuses the run number. + if-no-files-found: error + + pages: + name: Select browser checks + runs-on: ubuntu-22.04 + needs: [inputs, build, reference] + if: always() && needs.build.result == 'success' && (needs.reference.result == 'success' || needs.inputs.outputs.scoped == 'false') + outputs: + mode: ${{ steps.selection.outputs.mode }} + steps: + - uses: actions/checkout@v6 + - uses: actions/download-artifact@v7 + if: needs.inputs.outputs.scoped == 'true' + with: + name: rebrand-preview-${{ github.run_number }} + path: head + - uses: actions/download-artifact@v7 + if: needs.inputs.outputs.scoped == 'true' + with: + name: rebrand-pr-base-${{ github.run_number }} + path: base + - name: Compare pages and bundles + id: selection + env: + SCOPED: ${{ needs.inputs.outputs.scoped }} + run: | + if [ "$SCOPED" = true ]; then + tar -xf base/site.tar -C base + tar -xf head/site.tar -C head + python3 scripts/rebrand/changed_pages.py base head --out changed.json | tee selection.log + else + python3 scripts/rebrand/changed_pages.py --full --out changed.json | tee selection.log + fi + sed -n 's/^Check mode: /mode=/p' selection.log >> "$GITHUB_OUTPUT" + shell: bash + - uses: actions/upload-artifact@v7 + with: + name: rebrand-pages-${{ github.run_number }} + path: changed.json + retention-days: 1 + overwrite: true + if-no-files-found: error + compare: name: Compare with main runs-on: ubuntu-22.04 @@ -236,22 +386,40 @@ jobs: design: name: Designed screens runs-on: ubuntu-22.04 - needs: build + needs: [build, pages] steps: - name: Checkout repository uses: actions/checkout@v6 + - name: Download page selection + uses: actions/download-artifact@v7 + with: + name: rebrand-pages-${{ github.run_number }} + + - name: Report check mode and pages + run: PYTHONPATH=scripts/rebrand python3 -c 'from changed_pages import load_selection; load_selection("changed.json")' + - name: Download the branch's build + if: needs.pages.outputs.mode != 'none' uses: actions/download-artifact@v7 with: name: rebrand-preview-${{ github.run_number }} - name: Unpack the site + if: needs.pages.outputs.mode != 'none' run: mkdir public && tar -xf site.tar -C public + - name: Cache Chromium + if: needs.pages.outputs.mode != 'none' + uses: actions/cache@v5 + with: + path: ~/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ runner.arch }}-${{ env.PLAYWRIGHT_VERSION }}-chromium + - name: Install Playwright + if: needs.pages.outputs.mode != 'none' run: | - pip install --quiet playwright==1.63.0 pillow + pip install --quiet "playwright==$PLAYWRIGHT_VERSION" pillow # The runner image already has Chromium's libraries; --with-deps adds fonts from the # Ubuntu mirror. When the mirror is unreachable, install the browser without them. playwright install --with-deps chromium || { @@ -261,36 +429,56 @@ jobs: # Runs its sections in four browsers side by side; each section's time is in the log. - name: Designed screens in a browser (overflow, position, layout shift, pause, directory) - run: python3 scripts/rebrand/check_design.py public --base "$PREVIEW_BASE" --jobs 4 + if: needs.pages.outputs.mode != 'none' + run: python3 scripts/rebrand/check_design.py public --pages changed.json --base "$PREVIEW_BASE" --jobs 4 axe: name: Accessibility rules runs-on: ubuntu-22.04 - needs: build + needs: [build, pages] steps: - name: Checkout repository uses: actions/checkout@v6 + - name: Download page selection + uses: actions/download-artifact@v7 + with: + name: rebrand-pages-${{ github.run_number }} + + - name: Report check mode and pages + run: PYTHONPATH=scripts/rebrand python3 -c 'from changed_pages import load_selection; load_selection("changed.json")' + - name: Download the branch's build + if: needs.pages.outputs.mode != 'none' uses: actions/download-artifact@v7 with: name: rebrand-preview-${{ github.run_number }} - name: Unpack the site + if: needs.pages.outputs.mode != 'none' run: mkdir public && tar -xf site.tar -C public + - name: Cache Chromium + if: needs.pages.outputs.mode != 'none' + uses: actions/cache@v5 + with: + path: ~/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ runner.arch }}-${{ env.PLAYWRIGHT_VERSION }}-chromium + - name: Install Playwright + if: needs.pages.outputs.mode != 'none' run: | - pip install --quiet playwright==1.63.0 + pip install --quiet "playwright==$PLAYWRIGHT_VERSION" playwright install --with-deps chromium || { echo "::warning::Could not install Chromium's system packages; installing the browser without them" playwright install chromium } - name: Accessibility rules in a browser (axe-core, by WCAG level) + if: needs.pages.outputs.mode != 'none' run: | curl -fsSL https://cdn.jsdelivr.net/npm/axe-core@4.11.1/axe.min.js -o "$RUNNER_TEMP/axe.min.js" - python3 scripts/rebrand/check_axe.py public --base "$PREVIEW_BASE" --axe "$RUNNER_TEMP/axe.min.js" + python3 scripts/rebrand/check_axe.py public --pages changed.json --base "$PREVIEW_BASE" --axe "$RUNNER_TEMP/axe.min.js" deploy: name: Deploy preview @@ -322,9 +510,9 @@ jobs: checks: name: Check results runs-on: ubuntu-22.04 - needs: [build, compare, design, axe] + needs: [inputs, build, compare, design, axe] # Report even when a check job failed; skip only when the build was skipped (fork PRs). - if: always() && needs.build.result != 'skipped' + if: always() && needs.inputs.result != 'skipped' steps: - name: Fail if any check failed env: diff --git a/assets/css/doors/tokens.css b/assets/css/doors/tokens.css index 4801e0ca8ca..d5a361a6925 100644 --- a/assets/css/doors/tokens.css +++ b/assets/css/doors/tokens.css @@ -3,7 +3,7 @@ :root{ /* Guide: backgrounds, neutral elements, text */ --ink:#262d35; - --page:#fefdf6; + --page:#fefdf7; --foot:#dce4ea; --soft:#4c5e72; --line:#bdc5ca; diff --git a/scripts/rebrand/changed_pages.py b/scripts/rebrand/changed_pages.py new file mode 100644 index 00000000000..29c03262ac1 --- /dev/null +++ b/scripts/rebrand/changed_pages.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +"""Compare built pages and CSS/JS, and select the browser check mode.""" + +import argparse +import hashlib +import json +import re +from pathlib import Path + +FINGERPRINT = re.compile(r"\.(?:[0-9a-f]{128}|[0-9a-f]{96}|[0-9a-f]{64}|[0-9a-f]{32})(?=\.(?:css|js)\b)") +INTEGRITY = re.compile(r"""\s+integrity=(?:"[^"]*"|'[^']*'|[^\s>]+)""") + + +def normalize(html): + def clean_tag(match): + return INTEGRITY.sub("", FINGERPRINT.sub("", match[0])) + + return re.sub(r"<(?:link|script)\b[^>]*>", clean_tag, html) + + +def page_path(path): + path = "/" + path.lstrip("/") + return path[:-len("index.html")] if path.endswith("/index.html") else path + + +def inventory(root): + pages, bundles = {}, {} + for path in sorted(root.rglob("*")): + suffix = path.suffix + if suffix not in {".html", ".css", ".js"} or not path.is_file(): + continue + relative = path.relative_to(root).as_posix() + if suffix == ".html": + pages[page_path(relative)] = hashlib.sha256(normalize(path.read_text(encoding="utf-8")).encode()).digest() + else: + bundles.setdefault(FINGERPRINT.sub("", relative), set()).add(hashlib.sha256(path.read_bytes()).digest()) + return pages, bundles + + +def compare(base, head): + before, old_bundles = inventory(base) + after, new_bundles = inventory(head) + return { + "changed": sorted(path for path in before.keys() & after.keys() if before[path] != after[path]), + "added": sorted(after.keys() - before.keys()), + "removed": sorted(before.keys() - after.keys()), + "bundles_changed": old_bundles != new_bundles, + } + + +def load_selection(path): + if path is None: + print("Check mode: full (all pages)") + return "full", set() + diff = json.loads(Path(path).read_text(encoding="utf-8")) + live = set(diff["changed"]) | set(diff["added"]) + total = len(live) + len(diff["removed"]) + if diff.get("force_full") or total > 60: + mode = "full" + elif live: + mode = "changed" + elif diff["bundles_changed"]: + mode = "core" + else: + mode = "none" + print(f"Check mode: {mode}") + for field in ("changed", "added", "removed"): + print(f"{field.capitalize()} pages: {', '.join(diff[field]) or '(none)'}") + if mode == "none": + print("no changed pages") + return mode, live + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("base", type=Path, nargs="?") + parser.add_argument("head", type=Path, nargs="?") + parser.add_argument("--out", type=Path, required=True) + parser.add_argument("--full", action="store_true") + args = parser.parse_args() + if args.full: + diff = {"changed": [], "added": [], "removed": [], "bundles_changed": False, "force_full": True} + else: + if not all(path and (path / "index.html").is_file() for path in (args.base, args.head)): + parser.error("base and head must each contain a built index.html") + diff = compare(args.base, args.head) + args.out.write_text(json.dumps(diff, indent=2) + "\n", encoding="utf-8") + load_selection(args.out) + + +if __name__ == "__main__": + main() diff --git a/scripts/rebrand/check_axe.py b/scripts/rebrand/check_axe.py index 4aec0be65d0..fbbeb60015f 100644 --- a/scripts/rebrand/check_axe.py +++ b/scripts/rebrand/check_axe.py @@ -21,6 +21,8 @@ sys.path.insert(0, HERE) from check_design import serve # noqa: E402 +from changed_pages import load_selection # noqa: E402 + LEVEL_A = {"wcag2a", "wcag21a", "wcag22a"} LEVEL_AA = {"wcag2aa", "wcag21aa", "wcag22aa"} EXTRA = { @@ -57,14 +59,24 @@ def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("public", nargs="?") parser.add_argument("--url") + parser.add_argument("--pages", help="JSON from changed_pages.py") parser.add_argument("--base", default="/") parser.add_argument("--axe", required=True, help="path to axe.min.js") parser.add_argument("--out", help="write every finding to this JSON file") args = parser.parse_args() + mode, pages = load_selection(args.pages) + if mode == "none": + if args.out: + with open(args.out, "w", encoding="utf-8") as handle: + json.dump([], handle) + return base = args.url.rstrip("/") + "/" if args.url else serve(os.path.abspath(args.public), args.base) with open(os.path.join(HERE, "sample_pages.json"), encoding="utf-8") as handle: sample = {**json.load(handle), **EXTRA} sample.pop("404", None) + if mode == "changed": + names = {path: name for name, path in sample.items()} + sample = {names.get(path, path): path for path in sorted(pages)} with open(args.axe, encoding="utf-8") as handle: axe = handle.read() findings, failures, practice = [], [], collections.Counter() diff --git a/scripts/rebrand/check_design.py b/scripts/rebrand/check_design.py index 5a62a9324a9..fefcbb479f0 100644 --- a/scripts/rebrand/check_design.py +++ b/scripts/rebrand/check_design.py @@ -28,11 +28,14 @@ import tempfile import threading import time +from pathlib import Path from urllib.parse import urlsplit from playwright.sync_api import Error as PlaywrightError, sync_playwright from playwright.sync_api import TimeoutError as PlaywrightTimeoutError +from changed_pages import load_selection + WIDTHS = {390: 844, 1024: 768, 1440: 900} SCREENS = { "home": "", @@ -178,8 +181,10 @@ def new_page(browser, width, errors=None, **options): return page -def check_screens(browser, base, failures): +def check_screens(browser, base, failures, selected=None): for name, path in SCREENS.items(): + if selected is not None and "/" + path not in selected: + continue for width in WIDTHS: errors = [] page = new_page(browser, width, errors) @@ -201,7 +206,7 @@ def check_screens(browser, base, failures): page.context.close() -def article_paths(root): +def article_paths(root, selected=None): """Pages drawn on the reading layout, from the build.""" paths = [] for directory, _, files in os.walk(root): @@ -209,6 +214,8 @@ def article_paths(root): with open(os.path.join(directory, "index.html"), encoding="utf-8", errors="replace") as handle: if re.search(r'class="?article-layout', handle.read()): paths.append(os.path.relpath(directory, root).replace(os.sep, "/") + "/") + if selected is not None: + return sorted(path for path in paths if "/" + path in selected) # The two generated collections have over a thousand pages from one template, so take a sample. chosen = [] seen = {} @@ -243,7 +250,7 @@ def check_articles(browser, base, paths, failures, widths=WIDTHS): page.context.close() -def check_callouts(browser, base, root, failures): +def check_callouts(browser, base, root, failures, selected=None): """Call-outs sit in the right-hand column from 1240px, clear of each other, and in the text below that.""" paths = [] for directory, _, files in os.walk(root): @@ -251,6 +258,10 @@ def check_callouts(browser, base, root, failures): with open(os.path.join(directory, "index.html"), encoding="utf-8", errors="replace") as handle: if re.search(r'