Skip to content

Add python version file support #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,38 @@ jobs:

pip install requests
pip3 install s4cmd

test_python_version_file:
runs-on: ubuntu-latest
container: amazonlinux:2023
steps:
- name: Setup runner
run: |
yum install -y git tar gzip sudo

- uses: actions/checkout@v3

- name: Create python version file
run: |
echo '3.11.5' > .python-version

- name: Install python
uses: ./
with:
python-version-file: ".python-version"

- name: Test installation
run: |
set -x

which python3
which python

python3 --version
python --version

python3 --version 2>&1 | grep -F "3.11.5"
test "$(python3 -m pip --version)" = "$(pip3 --version)"

python --version 2>&1 | grep -F "3.11.5"
test "$(python3 -m pip --version)" = "$(pip --version)"
6 changes: 4 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ name: 'Setup python amazon linux'
description: 'setup-python action for amazon linux self hosted runners'
inputs:
python-version:
description: 'Version of python to be installed. Reads from .python-version if unset.'
python-version-file:
description: 'Version of python to be installed'
required: true
default: '.python-version'
cache:
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
required: true
Expand All @@ -20,7 +22,7 @@ runs:
id: find-exact-python-version
shell: bash
run: |
exact_python_version=$(${GITHUB_ACTION_PATH}/find-exact-python-version.sh "${{ inputs.python-version }}")
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

- name: Set installation directory
Expand Down
10 changes: 8 additions & 2 deletions find-exact-python-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
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 "${specified_version}" in
case "${desired_python_version}" in
"3")
echo "3.12.0"
;;
Expand All @@ -27,6 +33,6 @@ case "${specified_version}" in
echo "3.8.18"
;;
*)
echo "${specified_version}"
echo "${desired_python_version}"
;;
esac
17 changes: 9 additions & 8 deletions install-system-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ set -euo pipefail
# Reference https://stackoverflow.com/a/73208851/3316017

sudo yum update -y
sudo yum groupinstall -y "Development Tools"
if yum info "openssl11-devel" &> /dev/null; then
sudo yum install -y openssl11-devel
else
sudo yum install -y openssl-devel

desired_openssl_package="openssl-devel"
if yum info "openssl11-devel" &>/dev/null; then
desired_openssl_package="openssl11-devel"
fi
sudo yum install -y zlib-devel bzip2 bzip2-devel readline-devel libffi-devel \
ncurses-devel sqlite sqlite-devel gdbm-devel tk-devel xz-devel \
tar gzip wget

sudo yum groupinstall -y "Development Tools"
sudo yum install -y "${desired_openssl_package}" zlib-devel bzip2 bzip2-devel readline-devel libffi-devel \
ncurses-devel sqlite sqlite-devel gdbm-devel tk-devel xz-devel \
tar gzip wget