Commit 2ad10db8d2
Unsigned
Layout: unified · split
.githooks/pre-push +32 −26
| @@ -1,20 +1,23 @@ | ||
| 1 | 1 | #!/usr/bin/env bash |
| 2 | 2 | # |
| 3 | # Run the complexity ratchet and the accessibility audit against the oldest | |
| 4 | # supported simulator runtime before pushing. | |
| 3 | # Run the complexity ratchet, and refuse a push whose tree has no recorded | |
| 4 | # accessibility audit pass. | |
| 5 | 5 | # |
| 6 | 6 | # Enable once per clone: |
| 7 | 7 | # git config core.hooksPath .githooks |
| 8 | 8 | # |
| 9 | # Why pre-push and not pre-commit: the suite takes around ten minutes per | |
| 10 | # runtime. At pre-commit that blocks every commit, and a hook you routinely | |
| 11 | # bypass with --no-verify is worse than no hook, because it trains you to ignore | |
| 12 | # it. Pushes are far less frequent and map to the unit of work. | |
| 9 | # The audit runs before the push, not here: `./Scripts/audit-a11y.sh` on a | |
| 10 | # clean tree records the tree it passed on, and this hook looks it up. git opens | |
| 11 | # the connection before running pre-push, and gitbay kills a push that moves no | |
| 12 | # data for a minute or has not reached pre-receive fifteen minutes after taking | |
| 13 | # its slot. The suite takes around twenty minutes, so run inside the hook it | |
| 14 | # failed every push it gated. | |
| 13 | 15 | # |
| 14 | 16 | # Why both tiers: audit coverage is not nested across OS versions — each runtime |
| 15 | 17 | # reports findings the others miss, in both directions, which |
| 16 | # Docs/ACCESSIBILITY.txt records per screen. There is no CI, so a tier this does | |
| 17 | # not run is not run at all, and an enforced failure on it reaches main. | |
| 18 | # Docs/ACCESSIBILITY.txt records per screen. There is no CI, so a tier that is | |
| 19 | # not run is not run at all, and an enforced failure on it reaches main. Only a | |
| 20 | # run of both tiers is recorded. | |
| 18 | 21 | # |
| 19 | 22 | # Why the hook runs qlty at all: nothing else does. This repository's origin is |
| 20 | 23 | # gitbay, which has no build configured, so the smell gates in .qlty/qlty.toml |
| @@ -28,8 +31,11 @@ set -euo pipefail | ||
| 28 | 31 | repo_root=$(git rev-parse --show-toplevel) |
| 29 | 32 | cd "$repo_root" |
| 30 | 33 | |
| 34 | # shellcheck source=../Scripts/lib/audit-pass.sh | |
| 35 | source Scripts/lib/audit-pass.sh | |
| 36 | ||
| 31 | 37 | zero='0000000000000000000000000000000000000000' |
| 32 | changed='' | |
| 38 | needs_audit='' | |
| 33 | 39 | |
| 34 | 40 | # stdin: <local ref> <local sha> <remote ref> <remote sha>, one line per ref. |
| 35 | 41 | while read -r _local_ref local_sha _remote_ref remote_sha; do |
| @@ -43,15 +49,12 @@ while read -r _local_ref local_sha _remote_ref remote_sha; do | ||
| 43 | 49 | range="$remote_sha..$local_sha" |
| 44 | 50 | fi |
| 45 | 51 | |
| 46 | changed="$changed$(git diff --name-only "$range" 2>/dev/null || true)"$'\n' | |
| 52 | if git diff --name-only "$range" 2>/dev/null | grep -qE "$AUDIT_INPUTS"; then | |
| 53 | needs_audit="$needs_audit $local_sha" | |
| 54 | fi | |
| 47 | 55 | done |
| 48 | 56 | |
| 49 | if [ -z "$(printf '%s' "$changed" | tr -d '[:space:]')" ]; then | |
| 50 | exit 0 | |
| 51 | fi | |
| 52 | ||
| 53 | # Only pay the ~85s when something could actually change the rendered UI. | |
| 54 | if ! printf '%s' "$changed" | grep -qE '\.(swift|xcassets|xcodeproj)|\.pbxproj|xcscheme'; then | |
| 57 | if [ -z "$needs_audit" ]; then | |
| 55 | 58 | echo "pre-push: no Swift/project changes, skipping accessibility audit" |
| 56 | 59 | exit 0 |
| 57 | 60 | fi |
| @@ -101,18 +104,21 @@ print(sum( | ||
| 101 | 104 | fi |
| 102 | 105 | fi |
| 103 | 106 | |
| 104 | echo "pre-push: running accessibility audit on both runtimes (~20 min)" | |
| 105 | echo " skip with 'git push --no-verify'" | |
| 107 | passes=$(audit_pass_file) | |
| 108 | missing='' | |
| 109 | for sha in $needs_audit; do | |
| 110 | grep -qxF "$(git rev-parse "$sha^{tree}")" "$passes" 2>/dev/null || missing="$missing $sha" | |
| 111 | done | |
| 106 | 112 | |
| 107 | if ! ./Scripts/audit-a11y.sh; then | |
| 108 | echo | |
| 109 | echo "pre-push: accessibility audit failed. Push aborted." >&2 | |
| 110 | echo " Re-run with './Scripts/audit-a11y.sh' to see which tier and" >&2 | |
| 111 | echo " which screen, or bypass with 'git push --no-verify'." >&2 | |
| 113 | if [ -n "$missing" ]; then | |
| 114 | echo "pre-push: no recorded accessibility audit pass for:" >&2 | |
| 115 | for sha in $missing; do | |
| 116 | echo " $(git log -1 --format='%h %s' "$sha")" >&2 | |
| 117 | done | |
| 118 | echo " Check it out with a clean tree, run './Scripts/audit-a11y.sh'," >&2 | |
| 119 | echo " then push again. Bypass with 'git push --no-verify'." >&2 | |
| 112 | 120 | exit 1 |
| 113 | 121 | fi |
| 114 | 122 | |
| 115 | # Note: findings are reported, not enforced, so a clean exit here does not mean | |
| 116 | # zero findings — read the list above. Enforcement is controlled by | |
| 117 | # AccessibilityAuditHarness.enforcedAuditTypes. | |
| 123 | echo "pre-push: accessibility audit passed on this tree" | |
| 118 | 124 | exit 0 |
Docs/ACCESSIBILITY.txt +19 −13
| @@ -538,7 +538,7 @@ target had left in the app's container was still there. | ||
| 538 | 538 | That made the result depend on what ran before it. `testTrackedDomainsScreen` |
| 539 | 539 | passed with one finding in isolation, and reported six — including an enforced |
| 540 | 540 | `[FAIL][dynamicType]` on `EditButton`, which only renders when the watchlist has |
| 541 | rows — during a full `xcodebuild test`, which is what the pre-push hook runs. | |
| 541 | rows — during a full `xcodebuild test`, which is what `Scripts/audit-a11y.sh` runs. | |
| 542 | 542 | |
| 543 | 543 | **A correction to what this file said first.** The initial note blamed the |
| 544 | 544 | seeded fixtures. That was wrong: `seedAuditFixturesIfRequested` writes only to |
| @@ -583,7 +583,8 @@ no single number is correct on both. | ||
| 583 | 583 | |
| 584 | 584 | The audit therefore runs locally, across both ends, via |
| 585 | 585 | `Scripts/audit-a11y.sh` — on a machine that actually has an 18.x runtime |
| 586 | installed. The pre-push hook in `.githooks/` runs both of them. | |
| 586 | installed. The pre-push hook in `.githooks/` refuses a push without a recorded | |
| 587 | pass of both. | |
| 587 | 588 | |
| 588 | 589 | There is no CI job. The GitHub Actions workflow that used to run this suite on |
| 589 | 590 | the newest runtime has been removed, and with it the one check that no local run |
| @@ -618,19 +619,24 @@ so rather than implying floor coverage it does not have. | ||
| 618 | 619 | git config core.hooksPath .githooks |
| 619 | 620 | ``` |
| 620 | 621 | |
| 621 | Runs the complexity ratchet, then the audit on **both** runtimes, before a push, | |
| 622 | and only when Swift, asset, or project files changed. Bypass with | |
| 623 | `git push --no-verify`. | |
| 622 | Runs the complexity ratchet, then refuses the push unless the tree being pushed | |
| 623 | has a recorded audit pass, when Swift, asset, or project files changed. Bypass | |
| 624 | with `git push --no-verify`. | |
| 625 | ||
| 626 | Run the audit before pushing. `./Scripts/audit-a11y.sh` with no argument, on a | |
| 627 | tree with no tracked changes and no untracked Swift, asset or project files, | |
| 628 | appends `HEAD^{tree}` to `a11y-audit-passed` in the common git dir when both | |
| 629 | tiers pass. A squash or rebase that keeps the tree keeps the pass. | |
| 630 | ||
| 631 | The hook does not run the suite itself because git opens the connection before | |
| 632 | pre-push runs, and gitbay kills a push that moves no data for a minute or has | |
| 633 | not reached pre-receive fifteen minutes after taking its slot. The suite takes | |
| 634 | about twenty minutes, so every push it gated failed. | |
| 624 | 635 | |
| 625 | 636 | Both tiers rather than the floor alone because coverage is not nested across OS |
| 626 | versions (below) and there is no CI, so a tier the hook does not run is not run | |
| 627 | at all. The cost is real: about twenty minutes, against roughly eight for the | |
| 628 | floor alone. | |
| 629 | ||
| 630 | Pre-push rather than pre-commit deliberately: at pre-commit that blocks every | |
| 631 | commit. A hook routinely bypassed with `--no-verify` is worse than no hook, | |
| 632 | because it trains you to ignore it — which is the standing argument against | |
| 633 | letting this get any slower. | |
| 637 | versions (below) and there is no CI, so a tier that is not run is not run at | |
| 638 | all. The cost is real: about twenty minutes, against roughly eight for the floor | |
| 639 | alone. | |
| 634 | 640 | |
| 635 | 641 | ## Layout gotchas found the hard way |
| 636 | 642 | |
README.org +3 −1
| @@ -70,7 +70,9 @@ accessibility audit. | ||
| 70 | 70 | ./Scripts/audit-a11y.sh floor # oldest only (~85s) |
| 71 | 71 | #+end_src |
| 72 | 72 | |
| 73 | findings are reported, not enforced. optional pre-push hook: | |
| 73 | findings are reported, not enforced. a passing run of both tiers on a | |
| 74 | clean tree is recorded, and the optional pre-push hook refuses a push of | |
| 75 | Swift or project changes without one: | |
| 74 | 76 | |
| 75 | 77 | #+begin_src sh |
| 76 | 78 | git config core.hooksPath .githooks |
Scripts/audit-a11y.sh +20 −2
| @@ -33,6 +33,8 @@ TIER="${1:-both}" | ||
| 33 | 33 | |
| 34 | 34 | # shellcheck source=lib/simulators.sh |
| 35 | 35 | source "$(dirname "$0")/lib/simulators.sh" |
| 36 | # shellcheck source=lib/audit-pass.sh | |
| 37 | source "$(dirname "$0")/lib/audit-pass.sh" | |
| 36 | 38 | |
| 37 | 39 | case "$TIER" in |
| 38 | 40 | floor | current | both) ;; |
| @@ -72,8 +74,8 @@ run_tier() { | ||
| 72 | 74 | # |
| 73 | 75 | # The grep is wrapped in a brace group so that matching nothing does not read |
| 74 | 76 | # as a failure. With pipefail the pipeline then carries xcodebuild's own |
| 75 | # status, so an enforced audit failure reaches the caller — and the pre-push | |
| 76 | # gate can act on it — rather than being reported and exited 0. | |
| 77 | # status, so an enforced audit failure reaches the caller — and is never | |
| 78 | # recorded as a pass — rather than being reported and exited 0. | |
| 77 | 79 | local code=0 |
| 78 | 80 | set -o pipefail |
| 79 | 81 | xcodebuild test \ |
| @@ -95,11 +97,27 @@ else | ||
| 95 | 97 | run_tier "$TIER" || status=1 |
| 96 | 98 | fi |
| 97 | 99 | |
| 100 | # A pass on both tiers is recorded against the tree it ran on, for the pre-push | |
| 101 | # hook to check. Only a tree the build saw exactly counts: no tracked changes, | |
| 102 | # and no untracked file the build would pick up. | |
| 103 | record_pass() { | |
| 104 | if [[ -n "$(git status --porcelain --untracked-files=no)" ]] \ | |
| 105 | || git status --porcelain --untracked-files=all | grep -qE "$AUDIT_INPUTS"; then | |
| 106 | echo " Not recorded for the pre-push hook: the working tree differs from HEAD." | |
| 107 | return | |
| 108 | fi | |
| 109 | git rev-parse 'HEAD^{tree}' >> "$(audit_pass_file)" | |
| 110 | echo " Recorded for the pre-push hook: $(git log -1 --format='%h %s')" | |
| 111 | } | |
| 112 | ||
| 98 | 113 | echo |
| 99 | 114 | if [[ "$status" -eq 0 ]]; then |
| 100 | 115 | echo "==> Done. Findings above are the burndown list for issue #21." |
| 101 | 116 | echo " They are reported, not enforced — widen" |
| 102 | 117 | echo " AccessibilityAuditHarness.enforcedAuditTypes as each phase lands." |
| 118 | if [[ "$TIER" = "both" ]]; then | |
| 119 | record_pass | |
| 120 | fi | |
| 103 | 121 | else |
| 104 | 122 | echo "==> A tier failed. An enforced category reported a named finding, or the" >&2 |
| 105 | 123 | echo " suite could not run. Read the verdict line for each tier above." >&2 |
Scripts/lib/audit-pass.sh added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | # shellcheck shell=bash | |
| 2 | # | |
| 3 | # Where accessibility audit passes are recorded, and which changes need one. | |
| 4 | # Sourced by Scripts/audit-a11y.sh, which records a pass, and | |
| 5 | # .githooks/pre-push, which checks for it. | |
| 6 | ||
| 7 | # Paths whose changes can alter the rendered UI. | |
| 8 | AUDIT_INPUTS='\.(swift|xcassets|xcodeproj)|\.pbxproj|xcscheme' | |
| 9 | ||
| 10 | # One tree hash per line. Under the common git dir, so worktrees share it. | |
| 11 | audit_pass_file() { | |
| 12 | echo "$(git rev-parse --git-common-dir)/a11y-audit-passed" | |
| 13 | } | |