testsAndMisc/scripts/deploy.sh
Krzysztof kuhy Rudnicki f75fb60687
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Add deploy command: ff the live checkout
testsAndMisc had no '- deploy:' line, so Ship reported 'pushed, not
deployed'. scripts/deploy.sh fast-forwards ~/src/testsAndMisc to
origin/main, keeps unrelated local edits, and health-checks HEAD =
origin/main plus the tracked hooks. bats: 7/7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 08:57:05 +01:00

57 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# ============================================================================
# Deploy testsAndMisc: fast-forward the live checkout (~/src/testsAndMisc) to
# origin/main. Everything this repo runs on the machine (i3 config, systemd
# units, symlinked scripts, git hooks) executes straight from that checkout,
# so updating it is the deploy.
#
# scripts/deploy.sh
#
# Idempotent. Uncommitted work in the live checkout is kept: git refuses the
# fast-forward (and this exits non-zero) only when an incoming commit touches
# a file with local edits. Copies installed under /usr/local or /etc by the
# sudo installers are not refreshed here; rerun that installer by hand.
#
# Exits non-zero unless the health check passes: the checkout is on main, its
# HEAD equals origin/main, and core.hooksPath points at the tracked hooks.
# Env: TESTSANDMISC_DIR (default ~/src/testsAndMisc).
# ============================================================================
set -euo pipefail
readonly REPO="${TESTSANDMISC_DIR:-${HOME}/src/testsAndMisc}"
readonly HOOKS_PATH=linux_configuration/.githooks
die() {
echo "deploy: $1" >&2
exit 1
}
update_checkout() {
[[ -d "${REPO}/.git" ]] || die "${REPO} is not a git checkout"
local branch
branch="$(git -C "$REPO" rev-parse --abbrev-ref HEAD)"
[[ "$branch" == main ]] || die "${REPO} is on '${branch}', not main"
git -C "$REPO" pull --ff-only --quiet origin main ||
die "git pull --ff-only failed in ${REPO} (diverged, or local edits collide)"
}
health_check() {
local head remote hooks
head="$(git -C "$REPO" rev-parse HEAD)"
remote="$(git -C "$REPO" rev-parse origin/main)"
[[ "$head" == "$remote" ]] || die "HEAD ${head:0:8} != origin/main ${remote:0:8}"
hooks="$(git -C "$REPO" config --get core.hooksPath || true)"
[[ "$hooks" == "$HOOKS_PATH" && -d "${REPO}/${HOOKS_PATH}" ]] ||
die "core.hooksPath is '${hooks}', want ${HOOKS_PATH} (run meta/scripts/install_hooks.sh)"
echo "deploy: ${REPO} at ${head:0:8} = origin/main, hooks wired"
}
main() {
update_checkout
health_check
}
main "$@"