Files
mostovik-backend/scripts/ensure-ci-python.sh
Aleksandr Meshchriakov f0a6984e85
Some checks failed
CI/CD Pipeline / Run Tests (pull_request) Failing after 52s
CI/CD Pipeline / Run API Inventory E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Code Quality Checks (pull_request) Failing after 56s
CI/CD Pipeline / Telegram Notify Success (pull_request) Has been skipped
fix(ci): support sudo in python bootstrap
2026-03-24 14:27:30 +01:00

35 lines
870 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
TARGET_VERSION="${1:-3.11}"
IFS="." read -r PYTHON_MAJOR PYTHON_MINOR _ <<< "${TARGET_VERSION}"
if [[ -n "${PYTHON_MINOR:-}" ]]; then
PYTHON_BIN="python${PYTHON_MAJOR}.${PYTHON_MINOR}"
else
PYTHON_BIN="python${PYTHON_MAJOR}"
fi
if command -v "${PYTHON_BIN}" >/dev/null 2>&1; then
command -v "${PYTHON_BIN}"
exit 0
fi
APT_RUNNER=()
if [[ "$(id -u)" -ne 0 ]]; then
APT_RUNNER=(sudo)
fi
export DEBIAN_FRONTEND=noninteractive
"${APT_RUNNER[@]}" apt-get update
if ! "${APT_RUNNER[@]}" apt-get install -y "${PYTHON_BIN}" "${PYTHON_BIN}-venv"; then
"${APT_RUNNER[@]}" apt-get install -y software-properties-common
"${APT_RUNNER[@]}" add-apt-repository -y ppa:deadsnakes/ppa
"${APT_RUNNER[@]}" apt-get update
"${APT_RUNNER[@]}" apt-get install -y "${PYTHON_BIN}" "${PYTHON_BIN}-venv"
fi
command -v "${PYTHON_BIN}"