| 1 | #!/usr/bin/env bash |
| 2 | # Run one whole-repo ratchet. A failure blocks and prints the receipt command. |
| 3 | # |
| 4 | # Usage: |
| 5 | # scripts/ci/ratchet-gate.sh --name NAME --update "CMD" -- CHECK... |
| 6 | # |
| 7 | # --name label used in annotations (e.g. blocking-calls) |
| 8 | # --update the exact receipt command that lands the fix; printed |
| 9 | # on failure so the author can regenerate and commit the budget |
| 10 | # CHECK... the checker command, run from the repository root |
| 11 | set -euo pipefail |
| 12 | |
| 13 | name="" |
| 14 | update_cmd="" |
| 15 | while [[ "$#" -gt 0 ]]; do |
| 16 | case "$1" in |
| 17 | --name) name="${2:?--name needs a value}"; shift 2 ;; |
| 18 | --update) update_cmd="${2:?--update needs a value}"; shift 2 ;; |
| 19 | --) shift; break ;; |
| 20 | *) |
| 21 | echo "usage: $0 --name NAME --update CMD -- CHECK..." >&2 |
| 22 | exit 2 |
| 23 | ;; |
| 24 | esac |
| 25 | done |
| 26 | if [[ -z "${name}" || -z "${update_cmd}" || "$#" -eq 0 ]]; then |
| 27 | echo "usage: $0 --name NAME --update CMD -- CHECK..." >&2 |
| 28 | exit 2 |
| 29 | fi |
| 30 | |
| 31 | cd "$(dirname "${BASH_SOURCE[0]}")/../.." |
| 32 | |
| 33 | status=0 |
| 34 | "$@" || status=$? |
| 35 | if [[ "${status}" -eq 0 ]]; then |
| 36 | exit 0 |
| 37 | fi |
| 38 | |
| 39 | echo "::error title=${name} ratchet::${name} budget check failed (exit ${status}). Fix: ${update_cmd}" >&2 |
| 40 | echo "" >&2 |
| 41 | echo "To land the fix: remove the new sites, or if the growth is intended run" >&2 |
| 42 | echo " ${update_cmd}" >&2 |
| 43 | echo "and commit the regenerated budget with the reason in the commit message." >&2 |
| 44 | exit 1 |
| 45 |