diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6ecc4f0..b8226a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,13 +6,6 @@ on: pull_request: branches: [main] -env: - # This is required to support GLIB versions present in amazon linux 2. Can be removed once amazon linux 2 is 💀 - # More info - # - https://github.com/actions/checkout/issues/1809#issuecomment-2208202462 - # - https://github.blog/changelog/2024-03-07-github-actions-all-actions-will-run-on-node20-instead-of-node16-by-default/ - ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true - jobs: test_python_installation: strategy: @@ -30,9 +23,11 @@ jobs: steps: - name: Setup runner run: | - yum install -y git tar gzip sudo which + yum install -y git sudo tar gzip which - - uses: actions/checkout@v3 + - name: Checkout + run: | + git clone --depth 1 -b "${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}" "https://github.com/${GITHUB_REPOSITORY}.git" . - name: Install python uses: ./ @@ -56,41 +51,6 @@ jobs: python --version 2>&1 | grep -F "${{ matrix.python-version }}" test "$(python3 -m pip --version)" = "$(pip --version)" - test_abstract_version_specification: - strategy: - fail-fast: false - matrix: - include: - - python-version: "3" - installed-python-version: "3.12.4" - - python-version: "3.12" - installed-python-version: "3.12.4" - - python-version: "3.11" - installed-python-version: "3.11.9" - - python-version: "3.10" - installed-python-version: "3.10.14" - - python-version: "3.9" - installed-python-version: "3.9.19" - - python-version: "3.8" - installed-python-version: "3.8.19" - runs-on: ubuntu-latest - container: amazonlinux:2023 - steps: - - name: Setup runner - run: yum install -y git tar gzip sudo - - - uses: actions/checkout@v3 - - - name: Install python - uses: ./ - with: - python-version: "${{ matrix.python-version }}" - - - name: Test installation - run: | - set -x - python3 --version 2>&1 | grep -F "${{ matrix.installed-python-version }}" - test_pip_installs: strategy: fail-fast: false @@ -103,9 +63,11 @@ jobs: steps: - name: Setup runner run: | - yum install -y git tar gzip sudo + yum install -y git sudo tar gzip which - - uses: actions/checkout@v3 + - name: Checkout + run: | + git clone --depth 1 -b "${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}" "https://github.com/${GITHUB_REPOSITORY}.git" . - name: Install python uses: ./ @@ -127,9 +89,11 @@ jobs: steps: - name: Setup runner run: | - yum install -y git tar gzip sudo + yum install -y git sudo tar gzip which - - uses: actions/checkout@v3 + - name: Checkout + run: | + git clone --depth 1 -b "${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}" "https://github.com/${GITHUB_REPOSITORY}.git" . - name: Create python version file run: | diff --git a/action.yml b/action.yml index e2507eb..a298d16 100644 --- a/action.yml +++ b/action.yml @@ -7,51 +7,48 @@ inputs: description: 'Version of python to be installed' default: '.python-version' cache: - description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching. - required: true + description: > + [Deprecated] Used to specify whether caching is needed. Set to true, if you'd like to enable caching. + Current implementation uses uv which pulls in pre-compiled binaries of python thereby eliminating the + need to cache compiled python artifacts. default: 'true' + runs: using: "composite" steps: - - name: Ensure dependencies of python are installed + - name: Ensure system dependencies are installed + shell: bash + run: | + sudo yum install -y tar gzip which + + - name: Install uv shell: bash run: | - ${GITHUB_ACTION_PATH}/install-system-dependencies.sh + curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.3.3/uv-installer.sh | sh + source $HOME/.cargo/env + uv self update - - name: Find exact python version - id: find-exact-python-version + - name: Find desired python version + id: find-desired-python-version shell: bash run: | - exact_python_version=$(${GITHUB_ACTION_PATH}/find-exact-python-version.sh "${{ inputs.python-version }}" "${{ inputs.python-version-file }}") - echo "exact_python_version=${exact_python_version}" >> $GITHUB_OUTPUT + desired_python_version=$(${GITHUB_ACTION_PATH}/find-desired-python-version.sh "${{ inputs.python-version }}" "${{ inputs.python-version-file }}") + echo "desired_python_version=${desired_python_version}" | tee -a "${GITHUB_OUTPUT}" - name: Set installation directory id: set-installation-directory shell: bash run: | - exact_python_version="${{ steps.find-exact-python-version.outputs.exact_python_version }}" - echo "installation_directory=${HOME}/.setup-python-amazon-linux/.python-versions/${exact_python_version}" >> $GITHUB_OUTPUT - - - name: Cache - id: cache-python - uses: actions/cache@v3 - if: inputs.cache == 'true' - with: - path: ${{ steps.set-installation-directory.outputs.installation_directory }} - key: python-${{ steps.find-exact-python-version.outputs.exact_python_version }}-${{ runner.arch }} + desired_python_version="${{ steps.find-desired-python-version.outputs.desired_python_version }}" + echo "installation_directory=${HOME}/.setup-python-amazon-linux/.python-versions/${desired_python_version}" | tee -a "${GITHUB_OUTPUT}" - id: setup-python shell: bash - if: inputs.cache == 'false' || (inputs.cache == 'true' && steps.cache-python.outputs.cache-hit != 'true') run: | installation_directory="${{ steps.set-installation-directory.outputs.installation_directory }}" - exact_python_version="${{ steps.find-exact-python-version.outputs.exact_python_version }}" - - # Using a separate tmp directory instead of /tmp because in some OS images set a noexec option for the mount - # this is a better way compared to changing the mount options of /tmp - tmp_directory="${HOME}/.setup-python-amazon-linux/tmp" + desired_python_version="${{ steps.find-desired-python-version.outputs.desired_python_version }}" - ${GITHUB_ACTION_PATH}/install-python.sh "${exact_python_version}" "${installation_directory}" "${tmp_directory}" + uv venv --python "${desired_python_version}" "${installation_directory}" - name: Add python to PATH shell: bash @@ -61,10 +58,15 @@ runs: echo "The following python binaries are now available in the PATH" ls "${installation_directory}/bin" - - echo "Linking python libraries..." - ls "${installation_directory}/lib" - sudo ldconfig "${installation_directory}/lib" + + - name: Install pip + shell: bash + run: | + installation_directory="${{ steps.set-installation-directory.outputs.installation_directory }}" + + python -m ensurepip --upgrade + ln -sf "${installation_directory}/bin/pip3" "${installation_directory}/bin/pip" + pip install --upgrade pip branding: icon: 'code' diff --git a/find-desired-python-version.sh b/find-desired-python-version.sh new file mode 100755 index 0000000..a479b68 --- /dev/null +++ b/find-desired-python-version.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -euo pipefail + +specified_version="$1" +specified_version_file="$2" + +desired_python_version="${specified_version}" +if [ -f "${specified_version_file}" ]; then + desired_python_version=$(cat "${specified_version_file}") +fi + +echo "${desired_python_version}" \ No newline at end of file diff --git a/find-exact-python-version.sh b/find-exact-python-version.sh deleted file mode 100755 index 82b554d..0000000 --- a/find-exact-python-version.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -specified_version="$1" -specified_version_file="$2" - -desired_python_version="${specified_version}" -if [ -f "${specified_version_file}" ]; then - desired_python_version=$(cat "${specified_version_file}") -fi - -# This versions map should be kept in sync with -# - https://www.python.org/downloads/ -# - https://devguide.python.org/versions/ -case "${desired_python_version}" in - "3") - echo "3.12.4" - ;; - "3.12") - echo "3.12.4" - ;; - "3.11") - echo "3.11.9" - ;; - "3.10") - echo "3.10.14" - ;; - "3.9") - echo "3.9.19" - ;; - "3.8") - echo "3.8.19" - ;; - *) - echo "${desired_python_version}" - ;; -esac diff --git a/install-python.sh b/install-python.sh deleted file mode 100755 index 1f3b066..0000000 --- a/install-python.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -function set_aliases() { - ln -sf "${python_installation_dir}/bin/python3" "${python_installation_dir}/bin/python" - ln -sf "${python_installation_dir}/bin/pip3" "${python_installation_dir}/bin/pip" -} - -# Reference - https://realpython.com/installing-python/#how-to-build-python-from-source-code -function setup_python() { - python_version="${1:?}" - python_installation_dir="${2:?}" - temp_dir="${3:?}" - - mkdir -p "${python_installation_dir}" - mkdir -p "${temp_dir}" - rm -rf "${python_installation_dir:?}/*" - rm -rf "${temp_dir:?}/*" - - echo "Installing python from temporary directory ${temp_dir}" - pushd "${temp_dir}" >/dev/null - wget "https://www.python.org/ftp/python/${python_version}/Python-${python_version}.tgz" - tar -zxf "Python-${python_version}.tgz" - pushd "Python-${python_version}" >/dev/null - # - Have not added --enable-optimizations flag because that shoots up the build time by ~5 minutes - # - Ref for openssl - # - https://gist.github.com/wizardbeard/d5b641d1fadbaba755823e16eab4dda1#file-python-3-9-slim-dockerfile-L17 - # - https://stackoverflow.com/a/29169795/3316017 - # - https://stackoverflow.com/a/75880038/3316017 - export OPENSSL_LIBS=/usr/lib64/libssl.so - ./configure --prefix="${python_installation_dir}" --enable-shared --with-openssl=/usr --with-openssl-rpath=/usr/lib64 - make -j "$(nproc)" - make install - popd >/dev/null - popd - rm -rf "${temp_dir}" - - set_aliases -} - -setup_python "$1" "$2" "$3" diff --git a/install-system-dependencies.sh b/install-system-dependencies.sh deleted file mode 100755 index e4d6de2..0000000 --- a/install-system-dependencies.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# Reference https://stackoverflow.com/a/73208851/3316017 - -sudo yum update -y - -desired_openssl_package="openssl-devel" -if yum info "openssl11-devel" &>/dev/null; then - desired_openssl_package="openssl11-devel" -fi - -desired_lib_crypt="libcrypt" -if yum info "libxcrypt-compat" &>/dev/null; then - desired_lib_crypt="libxcrypt-compat" -fi - -dynamic_package_list="${desired_openssl_package} ${desired_lib_crypt}" - -sudo yum install -y autoconf automake binutils bison byacc cscope ctags diffstat doxygen \ - elfutils flex gcc gcc-c++ gcc-gfortran gettext git indent intltool libtool make patch patchutils \ - pkgconfig rpm-build rpm-sign swig system-rpm-config systemtap \ - ${dynamic_package_list} zlib-devel bzip2 bzip2-devel readline-devel libffi-devel \ - ncurses-devel sqlite sqlite-devel gdbm-devel tk-devel xz-devel \ - tar gzip wget which