|
| 1 | +name: UI Baseline Guard |
| 2 | + |
| 3 | +# tool/ui_lint/baseline.json הוא החוב הקיים מול תקן הממשק |
| 4 | +# (docs/design-system/CI_ENFORCEMENT.md §3.4, DD-23). הוא יכול רק לקטון: |
| 5 | +# `dart tool/ui_lint_cli.dart --update-baseline` מוחק רשומות שתוקנו. PR שמוסיף |
| 6 | +# מופע לכלל באותו קובץ ובאותו scope צריך את התווית ui-baseline, שמתחזק מוסיף. |
| 7 | +# גם החרגת נתיב חדשה או מורחבת ב־tool/ui_lint/config.yaml משתיקה חריגות בלי |
| 8 | +# baseline, ולכן גם היא צריכה את אותה תווית. |
| 9 | + |
| 10 | +on: |
| 11 | + pull_request: |
| 12 | + branches: |
| 13 | + - main |
| 14 | + - dev |
| 15 | + types: [opened, synchronize, reopened, labeled, unlabeled] |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +concurrency: |
| 21 | + group: ui-baseline-guard-${{ github.event.pull_request.number }} |
| 22 | + cancel-in-progress: true |
| 23 | + |
| 24 | +jobs: |
| 25 | + guard: |
| 26 | + name: ui_lint baseline growth |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - name: Checkout code |
| 30 | + uses: actions/checkout@v7.0.1 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | + - name: Check baseline growth |
| 35 | + env: |
| 36 | + BASE_SHA: ${{ github.event.pull_request.base.sha }} |
| 37 | + BASELINE_LABEL: ${{ contains(github.event.pull_request.labels.*.name, 'ui-baseline') }} |
| 38 | + run: | |
| 39 | + set -euo pipefail |
| 40 | + path=tool/ui_lint/baseline.json |
| 41 | + # ה־PR שמכניס את ui_lint: ב־base אין baseline ואין config, ולכן אין |
| 42 | + # מול מה למדוד גידול. ה־baseline הראשון הוא רישום החוב (§3.4). |
| 43 | + if ! git cat-file -e "$BASE_SHA:$path" 2>/dev/null; then |
| 44 | + echo "The base has no $path: this pull request introduces the ui_lint baseline, so there is no growth to check." |
| 45 | + exit 0 |
| 46 | + fi |
| 47 | + git show "$BASE_SHA:$path" > /tmp/base.json |
| 48 | + python3 - /tmp/base.json "$path" > /tmp/growth.txt <<'PY' |
| 49 | + import json, sys |
| 50 | +
|
| 51 | + # Per rule, file and scope: a fingerprint change (an edited |
| 52 | + # expression, or a new engine version) is not growth. |
| 53 | + def counts(path): |
| 54 | + data = json.load(open(path, encoding="utf-8")) |
| 55 | + totals = {} |
| 56 | + for rule, files in data["rules"].items(): |
| 57 | + for file, entries in files.items(): |
| 58 | + for entry in entries: |
| 59 | + key = (rule, file, entry["scope"]) |
| 60 | + totals[key] = totals.get(key, 0) + entry["n"] |
| 61 | + return totals |
| 62 | +
|
| 63 | + base, head = counts(sys.argv[1]), counts(sys.argv[2]) |
| 64 | + for key, n in sorted(head.items()): |
| 65 | + added = n - base.get(key, 0) |
| 66 | + if added > 0: |
| 67 | + print(f"+{added} {key[0]} {key[1]} ({key[2]})") |
| 68 | + PY |
| 69 | + # A new or edited path exclusion silences findings without a baseline |
| 70 | + # entry. A changed glob shows up as an added line too. |
| 71 | + config=tool/ui_lint/config.yaml |
| 72 | + git diff --unified=0 "$BASE_SHA" HEAD -- "$config" \ |
| 73 | + | { grep -E '^\+[[:space:]]*(-[[:space:]]*)?path:' || true; } \ |
| 74 | + | sed -E 's/^\+[[:space:]]*(-[[:space:]]*)?/exclude /' > /tmp/excludes.txt |
| 75 | + if [ ! -s /tmp/growth.txt ] && [ ! -s /tmp/excludes.txt ]; then |
| 76 | + echo "The ui_lint baseline did not grow, and no path exclusion was added." |
| 77 | + exit 0 |
| 78 | + fi |
| 79 | + if [ -s /tmp/growth.txt ]; then |
| 80 | + echo "Baseline additions:" |
| 81 | + cat /tmp/growth.txt |
| 82 | + fi |
| 83 | + if [ -s /tmp/excludes.txt ]; then |
| 84 | + echo "Path exclusions added or changed in $config:" |
| 85 | + cat /tmp/excludes.txt |
| 86 | + fi |
| 87 | + if [ "$BASELINE_LABEL" = "true" ]; then |
| 88 | + echo "Baseline growth and exclusions approved with the 'ui-baseline' label." |
| 89 | + exit 0 |
| 90 | + fi |
| 91 | + if [ -s /tmp/growth.txt ]; then |
| 92 | + echo "::error file=$path::This pull request adds entries to the ui_lint baseline. Fix the new violations, or mark a justified one with '// ui-lint: allow UIL-xxx — reason'. If the debt is intended, ask a maintainer to add the 'ui-baseline' label." |
| 93 | + fi |
| 94 | + if [ -s /tmp/excludes.txt ]; then |
| 95 | + echo "::error file=$config::This pull request adds or widens a path exclusion in the ui_lint config, which silences findings without a baseline entry. Prefer '// ui-lint: allow UIL-xxx — reason' on the single node, or ask a maintainer to add the 'ui-baseline' label." |
| 96 | + fi |
| 97 | + exit 1 |
0 commit comments