diff --git a/.github/workflows/clp-artifact-build.yaml b/.github/workflows/clp-artifact-build.yaml index 59b216b43c..82e35a9b23 100644 --- a/.github/workflows/clp-artifact-build.yaml +++ b/.github/workflows/clp-artifact-build.yaml @@ -62,24 +62,28 @@ jobs: - ".github/actions/**" - ".github/workflows/clp-artifact-build.yaml" - "components/core/tools/scripts/lib_install/*.sh" + - "components/core/tools/scripts/lib_install/pipx-packages/**" - "components/core/tools/docker-images/clp-env-base-centos-stream-9/**" - "components/core/tools/scripts/lib_install/centos-stream-9/**" manylinux_2_28_x86_64_image: - ".github/actions/**" - ".github/workflows/clp-artifact-build.yaml" - "components/core/tools/scripts/lib_install/*.sh" + - "components/core/tools/scripts/lib_install/pipx-packages/**" - "components/core/tools/docker-images/clp-env-base-manylinux_2_28-x86_64/**" - "components/core/tools/scripts/lib_install/manylinux_2_28/**" musllinux_1_2_x86_64_image: - ".github/actions/**" - ".github/workflows/clp-artifact-build.yaml" - "components/core/tools/scripts/lib_install/*.sh" + - "components/core/tools/scripts/lib_install/pipx-packages/**" - "components/core/tools/docker-images/clp-env-base-musllinux_1_2-x86_64/**" - "components/core/tools/scripts/lib_install/musllinux_1_2/**" ubuntu_jammy_image: - ".github/actions/**" - ".github/workflows/clp-artifact-build.yaml" - "components/core/tools/scripts/lib_install/*.sh" + - "components/core/tools/scripts/lib_install/pipx-packages/**" - "components/core/tools/docker-images/clp-env-base-ubuntu-jammy/**" - "components/core/tools/scripts/lib_install/ubuntu-jammy/**" clp: diff --git a/.github/workflows/clp-core-build-macos.yaml b/.github/workflows/clp-core-build-macos.yaml index a0c3522963..40ed1aca97 100644 --- a/.github/workflows/clp-core-build-macos.yaml +++ b/.github/workflows/clp-core-build-macos.yaml @@ -9,6 +9,7 @@ on: - "components/core/CMakeLists.txt" - "components/core/src/**" - "components/core/tests/**" + - "components/core/tools/scripts/lib_install/pipx-packages/**" - "components/core/tools/scripts/lib_install/macos/**" - "components/core/tools/scripts/deps-download/**" - "components/core/tools/scripts/utils/build-and-run-unit-tests.py" @@ -23,6 +24,7 @@ on: - "components/core/CMakeLists.txt" - "components/core/src/**" - "components/core/tests/**" + - "components/core/tools/scripts/lib_install/pipx-packages/**" - "components/core/tools/scripts/lib_install/macos/**" - "components/core/tools/scripts/deps-download/**" - "components/core/tools/scripts/utils/build-and-run-unit-tests.py" diff --git a/components/core/tools/scripts/lib_install/pipx-packages/find-pipx-bin.sh b/components/core/tools/scripts/lib_install/pipx-packages/find-pipx-bin.sh new file mode 100755 index 0000000000..cb37f09240 --- /dev/null +++ b/components/core/tools/scripts/lib_install/pipx-packages/find-pipx-bin.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +if ! command -v pipx >/dev/null 2>&1; then + echo "Error: pipx not found." + exit 1 +fi + +if ! command -v jq >/dev/null 2>&1; then + echo "Error: jq not found." + exit 1 +fi + +if [ "$#" -ne 2 ] || [ -z "${1:-}" ] || [ -z "${2:-}" ]; then + echo "Usage: $0 " >&2 + exit 2 +fi + +pkg="$1" +app="$2" + +pipx list --json | jq --raw-output --arg pkg "$pkg" --arg app "$app" ' + .venvs[$pkg].metadata.main_package.app_paths[]?.__Path__ + | select((split("/") | last) == $app) +' | head -n1 diff --git a/components/core/tools/scripts/lib_install/pipx-packages/install-all.sh b/components/core/tools/scripts/lib_install/pipx-packages/install-all.sh index 226425faff..a133f6a44f 100755 --- a/components/core/tools/scripts/lib_install/pipx-packages/install-all.sh +++ b/components/core/tools/scripts/lib_install/pipx-packages/install-all.sh @@ -4,6 +4,13 @@ set -o errexit set -o nounset set -o pipefail +is_sudo_from_non_root=$(( EUID == 0 && ${SUDO_UID:-0} != 0 )) +if (( is_sudo_from_non_root )); then + echo "Installing pipx packages to the user environment (sudo lifted)." + exec sudo --preserve-env --set-home --user="$SUDO_USER" \ + /usr/bin/env bash "${BASH_SOURCE[0]}" "$@" +fi + script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" "${script_dir}/install-cmake.sh" diff --git a/components/core/tools/scripts/lib_install/pipx-packages/install-cmake.sh b/components/core/tools/scripts/lib_install/pipx-packages/install-cmake.sh index 855a79b731..add0047491 100755 --- a/components/core/tools/scripts/lib_install/pipx-packages/install-cmake.sh +++ b/components/core/tools/scripts/lib_install/pipx-packages/install-cmake.sh @@ -15,18 +15,24 @@ readonly required_version_min="${required_version_major_min}.${required_version_ readonly required_version_major_max=3 readonly required_version_major_max_plus_1=$((required_version_major_max + 1)) -package_preinstalled=0 -if ! command -v cmake >/dev/null 2>&1; then +cmake_bin="$(command -v cmake 2>/dev/null || true)" +if [ -n "${cmake_bin}" ]; then + package_preinstalled=0 + echo "Preinstalled CMake found at: ${cmake_bin}" +else package_preinstalled=1 # ystdlib requires CMake v3.23; ANTLR and yaml-cpp do not yet support CMake v4+ # (see https://github.com/y-scope/clp/issues/795). pipx install --force "cmake>=${required_version_min},<${required_version_major_max_plus_1}" pipx ensurepath + script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" + cmake_bin=$("${script_dir}/find-pipx-bin.sh" cmake cmake) + echo "Pipx CMake installed at: ${cmake_bin}" fi -installed_version=$(cmake -E capabilities | jq --raw-output ".version.string") -installed_version_major=$(cmake -E capabilities | jq --raw-output ".version.major") -installed_version_minor=$(cmake -E capabilities | jq --raw-output ".version.minor") +installed_version=$("${cmake_bin}" -E capabilities | jq --raw-output ".version.string") +installed_version_major=$("${cmake_bin}" -E capabilities | jq --raw-output ".version.major") +installed_version_minor=$("${cmake_bin}" -E capabilities | jq --raw-output ".version.minor") # ystdlib requires CMake v3.23; ANTLR and yaml-cpp do not yet support CMake v4+ # (see https://github.com/y-scope/clp/issues/795). @@ -47,3 +53,5 @@ if (("${installed_version_major}" < "${required_version_major_min}")) \ exit 1 fi + +echo "CMake version ${installed_version} installed at ${cmake_bin} satisfies version requirements." diff --git a/components/core/tools/scripts/lib_install/pipx-packages/install-go-task.sh b/components/core/tools/scripts/lib_install/pipx-packages/install-go-task.sh index 1a6eb61640..9f05722069 100755 --- a/components/core/tools/scripts/lib_install/pipx-packages/install-go-task.sh +++ b/components/core/tools/scripts/lib_install/pipx-packages/install-go-task.sh @@ -12,17 +12,23 @@ fi # We lock to version 3.44.0 to avoid https://github.com/y-scope/clp/issues/1352 readonly required_version="3.44.0" -package_preinstalled=0 -if ! command -v task >/dev/null 2>&1; then +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" + +go_task_bin="$(command -v task 2>/dev/null || true)" +if [ -n "${go_task_bin}" ]; then + package_preinstalled=0 + echo "Preinstalled Task found at: ${go_task_bin}" +else package_preinstalled=1 pipx install --force "go-task-bin==${required_version}" pipx ensurepath + go_task_bin=$("${script_dir}/find-pipx-bin.sh" go-task-bin task) + echo "Pipx Task installed at: ${go_task_bin}" fi -script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" -task_version=$(task --silent --taskfile "${script_dir}/print-go-task-version.yaml") -if [[ "${task_version}" != "${required_version}" ]]; then - echo "Error: Task version ${task_version} is currently unsupported (must be" \ +installed_version=$(${go_task_bin} --silent --taskfile "${script_dir}/print-go-task-version.yaml") +if [[ "${installed_version}" != "${required_version}" ]]; then + echo "Error: Task version ${installed_version} is currently unsupported (must be" \ "${required_version})." if ((0 == "${package_preinstalled}")); then @@ -35,3 +41,5 @@ if [[ "${task_version}" != "${required_version}" ]]; then exit 1 fi + +echo "Task version ${installed_version} installed at ${go_task_bin} satisfies version requirements." diff --git a/components/core/tools/scripts/lib_install/pipx-packages/install-uv.sh b/components/core/tools/scripts/lib_install/pipx-packages/install-uv.sh index a368dd7192..b45dcc2041 100755 --- a/components/core/tools/scripts/lib_install/pipx-packages/install-uv.sh +++ b/components/core/tools/scripts/lib_install/pipx-packages/install-uv.sh @@ -13,14 +13,20 @@ readonly required_version_major_min=0 readonly required_version_minor_min=8 readonly required_version_min="${required_version_major_min}.${required_version_minor_min}" -package_preinstalled=0 -if ! command -v uv >/dev/null 2>&1; then +uv_bin="$(command -v uv 2>/dev/null || true)" +if [ -n "${uv_bin}" ]; then + package_preinstalled=0 + echo "Preinstalled uv found at: ${uv_bin}" +else package_preinstalled=1 pipx install --force "uv>=${required_version_min}" pipx ensurepath + script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" + uv_bin=$("${script_dir}/find-pipx-bin.sh" uv uv) + echo "Pipx uv installed at: ${uv_bin}" fi -installed_version=$(uv self version --output-format json | jq --raw-output ".version") +installed_version=$(${uv_bin} self version --output-format json | jq --raw-output ".version") IFS=. read -r installd_version_major installed_version_minor _ <<<"${installed_version}" if (("${installd_version_major}" == "${required_version_major_min}" && \ @@ -38,3 +44,5 @@ if (("${installd_version_major}" == "${required_version_major_min}" && \ exit 1 fi + +echo "uv version ${installed_version} installed at ${uv_bin} satisfies version requirements."