diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index e9a6af0..cf19327 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -11,11 +11,39 @@ parameters: default: v4 executors: + python: + docker: + - image: cimg/python:3.8 macos: macos: xcode: 16.1 - + machine: + machine: + image: ubuntu-2004:current + machine-arm: + resource_class: arm.medium + machine: + image: ubuntu-2004:current + docker-latest: + docker: + - image: cimg/base:stable + ruby: + docker: + - image: circleci/ruby:2.7.2 jobs: + install-python: + parameters: + executor: + type: executor + default: machine + version: + type: string + default: 3.11.10 + executor: <> + steps: + - python/install: + version: <> + pip-install-test: parameters: executor: @@ -46,15 +74,6 @@ jobs: working_directory: ~/project/sample_pip command: | pytest - pip-install-test-no-packages: - executor: python/default - steps: - - checkout - - run: - name: "Test" - working_directory: ~/project/sample_pip - command: | - pytest pip-install-test-args: executor: python/default steps: @@ -143,6 +162,18 @@ workflows: test-deploy: jobs: # Make sure to include "filters: *filters" in every test job you want to run as part of your deployment. + - install-python: + filters: *filters + name: install-python-<>-<> + matrix: + alias: install-python + parameters: + executor: ["machine", "machine-arm","macos", "ruby", "python"] + version: ["3.11", "3.8", "3.12", "3.11.5", "3.9.4"] + post-steps: + - run: + name: Verify python version is right + command: python --version | grep "Python <>" - pip-install-test: name: "pip-install-macos" filters: *filters @@ -298,6 +329,7 @@ workflows: - dist-test-wheel - dist-test-build - dist-test-build-opts + - install-python context: orb-publisher filters: branches: diff --git a/src/commands/install.yml b/src/commands/install.yml new file mode 100644 index 0000000..8f2f228 --- /dev/null +++ b/src/commands/install.yml @@ -0,0 +1,14 @@ +description: "Install the specified version of python" + +parameters: + version: + type: string + default: 3.11.10 + description: Python version to install + +steps: + - run: + name: Install Python + command: <> + environment: + PARAM_VERSION: << parameters.version >> diff --git a/src/scripts/cache-save.sh b/src/scripts/cache-save.sh index 951b9db..99cb22a 100755 --- a/src/scripts/cache-save.sh +++ b/src/scripts/cache-save.sh @@ -62,10 +62,6 @@ fi LOCKFILE_PATH="${CACHE_DIR}/lockfile" -if [ -e "${LOCKFILE_PATH}" ]; then - rm -f "${LOCKFILE_PATH}" -fi - if [ -e "${LOCK_FILE}" ]; then FULL_LOCK_FILE=$(readlink -f "${LOCK_FILE}") diff --git a/src/scripts/install-python.sh b/src/scripts/install-python.sh new file mode 100644 index 0000000..8e9befe --- /dev/null +++ b/src/scripts/install-python.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# shellcheck disable=SC2034 # Unused variables left for readability +# shellcheck disable=SC1090 +PARAM_VERSION="$(echo "${PARAM_VERSION}" | circleci env subst)" +IFS='.' +read -r MAJOR MINOR PATCH <<< "$PARAM_VERSION" + +Install_Pyenv() { + { + echo "export PYENV_ROOT=$HOME/.pyenv" + echo "export PATH=$HOME/.pyenv/shims:$HOME/.pyenv/bin:$PATH" + echo "export PYTHON_VERSION=$PARAM_VERSION" + echo "export PIPENV_DEFAULT_PYTHON_VERSION=$PARAM_VERSION" + } >> "$BASH_ENV" + . "$BASH_ENV" + curl https://pyenv.run | bash +} + +Install_Python() { + if ! command -v "pyenv" >/dev/null 2>&1; then + Install_Pyenv + else + echo "Pyenv is already installed" + fi + pyenv install "$PARAM_VERSION" + pyenv global "$PARAM_VERSION" + echo "BASH_ENV_PYTHON_ALIASED=true" >> "$BASH_ENV" +} + +if [ "$SYS_ENV_PLATFORM" = "linux_alpine" ]; then + if [ "$ID" = 0 ]; then export SUDO=""; else export SUDO="sudo"; fi +else + if [ "$EUID" = 0 ]; then export SUDO=""; else export SUDO="sudo"; fi +fi + +if [ -z "$MAJOR" ] || [ -z "$MINOR" ]; then + echo "The version provided: $PARAM_VERSION is not valid" + exit 1 +fi + +if ! python --version | grep "Python $PARAM_VERSION" >/dev/null 2>&1; then + Install_Python +else + echo "Python$PARAM_VERSION is already installed" + exit 0 +fi