Files
computer-playbook/scripts/lint/wrapper.sh
T
kevinveenbirkenbachandClaude Opus 4.7 92f11a6701 feat(install/lint): Python-ize lint install + host/docker dispatcher
Refactor scripts/install/lint.sh (~870 LOC bash) into a Python package
under utils/install/. scripts/install/lint.sh becomes a 7-line wrapper
that delegates to `python3 -m utils.install.lint`.

Layout:
- utils/install/{primitives,pip,npm,github_release,system_pkg}.py:
  channel-agnostic installers
- utils/install/lint/<tool>.py: one ensure() per tool (actionlint,
  shfmt, mbake, ruff, ansible_lint, galaxy_importer, markdownlint_cli2,
  eslint, shellcheck, ansible_commands, ansible_collections)
- utils/install/lint/__main__.py: CLI + group dispatch + stamp logic

INFINITO_LINT_RUNNER dispatch:
- New env var (host | docker, default docker), tracked in env/static.env
  + passthrough handler + drift test.
- scripts/install/wrapper.sh routes `make install-lint` to host or
  container based on the runner.
- scripts/lint/wrapper.sh already dispatched; container branch now uses
  bash (not --login) so /etc/profile does not reset PATH, and forwards
  BASH_ENV so the .env keys land in the lint script's env.

Stamp logic:
- Per-interpreter stamp at build/install-lint-<sha256(sys.executable)>.stamp
  so host venv and container venv track installs independently despite
  bind-mounted build/.
- `--force` drops the stamp; group args bypass the stamp.

Tests + docs:
- 43 unit tests under tests/unit/utils/install/{,lint/} cover primitives,
  pip/npm/github_release/system_pkg fallback chains, and the main CLI
  (stamp logic, group dispatch, error path).
- utils/install/README.md + utils/install/lint/README.md document the
  structure and the per-tool ensure() contract.
- docs/contributing/tools/make.md install-lint row updated to mention
  the runner dispatch + per-env stamp + install-lint-force.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 20:40:34 +02:00

72 lines
2.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Dispatcher for scripts/lint/<TYPE>.sh based on INFINITO_LINT_RUNNER:
# host -- directly on the host shell (tools resolved via PATH).
# docker -- inside the running infinito compose container
# (requires `make up`; auto-brings the stack up).
#
# Argv: <TYPE> [extra args forwarded to the lint script]
# TYPE is the basename (without `.sh`) of a sibling script next to this
# one, e.g. `ansible` resolves to scripts/lint/ansible.sh.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
cd "${REPO_ROOT}"
# shellcheck source=scripts/meta/env/load.sh
source scripts/meta/env/load.sh
: "${1:?lint type required (e.g. ansible, python, shellcheck, markdown, action, galaxy, makefile, javascript, autoformat)}"
: "${INFINITO_LINT_RUNNER:?INFINITO_LINT_RUNNER must be set}"
lint_type="$1"
shift
target_script="scripts/lint/${lint_type}.sh"
if [[ ! -f "${target_script}" ]]; then
echo "scripts/lint/wrapper.sh: unknown lint type '${lint_type}' (no ${target_script})" >&2 # nocheck: self-path-reference
exit 2
fi
case "${INFINITO_LINT_RUNNER}" in
host)
exec bash --login "${target_script}" "$@"
;;
docker)
# Use bash (not --login) inside the container: --login sources
# /etc/profile which resets PATH to the Debian system default and
# drops the image's /opt/venvs/infinito/bin entry, leaving tools
# like ruff / mbake / ansible-lint undiscoverable. BASH_ENV via -e
# still sources load.sh on non-interactive bash startup.
echo "============================================================"
echo ">>> Running lint '${lint_type}' in ${INFINITO_DISTRO} container (compose stack)"
echo "============================================================"
if ! docker compose --env-file env/ci.env --env-file .env --profile ci \
ps -q infinito 2>/dev/null | grep -q .; then
echo ">>> 'infinito' container not running; starting the stack via 'make up'..."
"${MAKE:-make}" up
fi
# Pass BASH_ENV so `bash --login` auto-sources load.sh inside the
# container, putting every INFINITO_* key from the bind-mounted .env
# into the lint script's environment. Without this the script body
# would see `set -u` unbound-variable errors on first ${INFINITO_X}.
INFINITO_DISTRO="${INFINITO_DISTRO}" \
docker compose --env-file env/ci.env --env-file .env --profile ci exec -T \
-e ACT="${ACT:-}" \
-e BASH_ENV="${INFINITO_SRC_DIR}/scripts/meta/env/load.sh" \
-e GITHUB_ACTIONS="${GITHUB_ACTIONS:-}" \
-e GITHUB_REPOSITORY="${GITHUB_REPOSITORY:-}" \
-e GITHUB_REPOSITORY_OWNER="${GITHUB_REPOSITORY_OWNER:-}" \
-e GITHUB_SHA="${GITHUB_SHA:-}" \
--workdir "${INFINITO_SRC_DIR}" \
infinito \
bash "${INFINITO_SRC_DIR}/${target_script}" "$@"
;;
*)
echo "scripts/lint/wrapper.sh: unknown INFINITO_LINT_RUNNER='${INFINITO_LINT_RUNNER}' (expected: host|docker)" >&2 # nocheck: self-path-reference
exit 2
;;
esac