# shellcheck shell=bash # WHO IS ASKING FOR THE MACHINE: A RELEASE, A CHECK JOB, A WALK OR A LOCAL RUN. # # source scripts/lib/caller-class.sh; class="$(caller_class)" # release | ci | walk | local # # A check job outranks a builder's local run on every machine that runs both # (`scripts/with-build-lock.sh`, `scripts/ci/with-machine-lock.sh`), so the two # wrappers have to agree on which one a caller is — and they read it here, once. # # `ci` when the runner says so: forgejo-runner sets `CI=true` and # `GITHUB_ACTIONS=true` in every step, and those are the two variables the rest # of the repo already asks (the pre-push hook). Anything else — a coding session, a hand-typed shell, a # `dev_run_on_mac` command — is `local`. A LABEL is not asked: `ci-*` and # `local-*` are a naming habit, and a caller that passes a borrowed label must # not borrow a rank with it. # # `release` is never guessed: a release or install lane SAYS it is one with # `BUILD_LOCK_CLASS=release` (the TestFlight and Mac release steps, the Mac # release lane), because it outranks every check job on the machine # (`scripts/with-build-lock.sh`, "RELEASES GO FIRST"). # # `walk` is never guessed either: a simulator build somebody is standing at to # walk the app says it is one (`rank_as_walk` below), and it goes ahead of # every other local run waiting on the machine (`scripts/with-build-lock.sh`, # "A WALK GOES BEFORE OTHER LOCAL RUNS"). # # `BUILD_LOCK_CLASS=release|ci|walk|local` overrides the runner's variables. # Any other value is said on stderr and ignored — a typo must not quietly # promote a local run. caller_class() { case "${BUILD_LOCK_CLASS:-}" in release | ci | walk | local) printf '%s\n' "$BUILD_LOCK_CLASS" return 0 ;; "") ;; *) echo "[caller-class] ignoring BUILD_LOCK_CLASS='$BUILD_LOCK_CLASS' — it is release, ci, walk or local" >&2 ;; esac if [ "${CI:-}" = "true" ] || [ "${GITHUB_ACTIONS:-}" = "true" ]; then printf 'ci\n' else printf 'local\n' fi } # A WALK SCRIPT'S RANK: `walk` for its whole run, every build lock below it # included (build-xcframework.sh re-execs under the lock with the environment # it was given). Only when nothing ranked it already — a release or a check job # that runs a walk script keeps its own rank, and a caller may still say # `BUILD_LOCK_CLASS=local` to queue as an ordinary run. rank_as_walk() { if [ -z "${BUILD_LOCK_CLASS:-}" ] && [ "$(caller_class)" = local ]; then export BUILD_LOCK_CLASS=walk fi return 0 }