Skip to content

Commit 3569521

Browse files
Initial implementation (#1)
* Fix test harness * Update test harness * Update test harness to use amazon linux images * Use v3 of checkout action * Revert "Use v3 of checkout action" This reverts commit eb6ad15. * Install runner pre requisites * Install runner pre requisites - gzip * Install runner pre requisites - git * Assert pip version * build python * Install runner pre requisites - sudo * Fix script issue * Update test harness to use patch version * Reduce log size * Update python assertion order * Add debug to test case * ensure system does not get affected * fix silly issue * fix version path to enable caching workflow * fix silly issue * Add test for cache functionality * Fix path setup * Install runner pre requisites - which * Fix caching * Fix python symlink * Add aliases * Reduce amount of sudo * Update cache key to include architecture * Add support for partial version specification * Fix version logic * Add test debug flag * Add version input * Reduce installations
1 parent 90d530a commit 3569521

5 files changed

Lines changed: 203 additions & 8 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Lint GitHub Actions workflows
2+
3+
on: [ push ]
4+
5+
jobs:
6+
actionlint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
11+
- name: Download actionlint
12+
id: get-action-lint
13+
run: |
14+
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
15+
16+
- name: Check workflow files
17+
run: |
18+
${{ steps.get-action-lint.outputs.executable }} -color

.github/workflows/test.yml

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,86 @@
1-
on: [push]
1+
on: [ push ]
22

33
jobs:
44
test_setup_python:
5+
strategy:
6+
matrix:
7+
# This tests the amazon linux versions receiving standard support
8+
# Refer - https://endoflife.date/amazon-linux
9+
amazon-linux-version: [ 2, 2023 ]
10+
# This tests the lowest supported python version and the latest stable python version
11+
# Refer - https://devguide.python.org/versions/#status-of-python-versions
12+
python-version:
13+
- 3.8.18
14+
- 3.12.0
15+
cache:
16+
- true
17+
- false
518
runs-on: ubuntu-latest
19+
container: amazonlinux:${{ matrix.amazon-linux-version }}
620
steps:
7-
- uses: actions/checkout@v4
21+
- name: Setup runner
22+
run: |
23+
yum install -y git tar gzip sudo which
24+
25+
- uses: actions/checkout@v3
26+
27+
- name: Install python
28+
uses: ./
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
cache: ${{ matrix.cache }}
32+
33+
- name: Test installation
34+
run: |
35+
set -x
36+
37+
which python3
38+
which python
39+
40+
python3 --version 2>&1 | grep -F "${{ matrix.python-version }}"
41+
test "$(python3 -m pip --version)" = "$(pip3 --version)"
42+
43+
python --version 2>&1 | grep -F "${{ matrix.python-version }}"
44+
test "$(python3 -m pip --version)" = "$(pip --version)"
45+
46+
test_major_version_specification:
47+
runs-on: ubuntu-latest
48+
container: amazonlinux:2023
49+
steps:
50+
- name: Setup runner
51+
run: |
52+
yum install -y git tar gzip sudo
53+
54+
- uses: actions/checkout@v3
55+
856
- name: Install python
9-
uses: .
57+
uses: ./
1058
with:
11-
python-version: 3.8
59+
python-version: 3
60+
61+
- name: Test installation
62+
run: |
63+
set -x
64+
65+
python3 --version 2>&1 | grep -F "3.12.0"
66+
67+
test_minor_version_specification:
68+
runs-on: ubuntu-latest
69+
container: amazonlinux:2023
70+
steps:
71+
- name: Setup runner
72+
run: |
73+
yum install -y git tar gzip sudo
74+
75+
- uses: actions/checkout@v3
76+
77+
- name: Install python
78+
uses: ./
79+
with:
80+
python-version: 3.9
81+
1282
- name: Test installation
1383
run: |
14-
python --version
84+
set -x
85+
86+
python3 --version 2>&1 | grep -F "3.9.18"

action.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,51 @@ inputs:
44
python-version:
55
description: 'Version of python to be installed'
66
required: true
7+
cache:
8+
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
9+
required: true
10+
default: 'true'
711
runs:
812
using: "composite"
913
steps:
14+
- name: Find exact python version
15+
id: find-exact-python-version
16+
shell: bash
17+
run: |
18+
exact_python_version=$(./find-exact-python-version.sh "${{ inputs.python-version }}")
19+
echo "exact_python_version=${exact_python_version}" >> $GITHUB_OUTPUT
20+
21+
- name: Set installation directory
22+
id: set-installation-directory
23+
shell: bash
24+
run: |
25+
exact_python_version="${{ steps.find-exact-python-version.outputs.exact_python_version }}"
26+
echo "installation_directory=~/setup-python-amazon-linux/.python-versions/${exact_python_version}" >> $GITHUB_OUTPUT
27+
28+
- name: Cache
29+
id: cache-python
30+
uses: actions/cache@v3
31+
if: inputs.cache == 'true'
32+
with:
33+
path: |
34+
${{ steps.set-installation-directory.outputs.installation_directory }}
35+
key: python-${{ steps.find-exact-python-version.outputs.exact_python_version }}-${{ runner.arch }}
36+
1037
- id: setup-python
38+
shell: bash
39+
if: inputs.cache == 'false' || (inputs.cache == 'true' && steps.cache-python.outputs.cache-hit != 'true')
40+
run: |
41+
installation_directory=${{ steps.set-installation-directory.outputs.installation_directory }}
42+
mkdir -p "${installation_directory}"
43+
exact_python_version="${{ steps.find-exact-python-version.outputs.exact_python_version }}"
44+
./install-python.sh "${exact_python_version}" "${installation_directory}"
45+
46+
- name: Add python to PATH
1147
shell: bash
1248
run: |
13-
./install-python.sh ${{ inputs.python-version }}
49+
installation_directory=${{ steps.set-installation-directory.outputs.installation_directory }}
50+
echo "${installation_directory}/bin" >> ${GITHUB_PATH}
51+
1452
branding:
1553
icon: 'code'
1654
color: 'yellow'

find-exact-python-version.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
specified_version="$1"
6+
7+
# This versions map should be kept in sync with
8+
# - https://www.python.org/downloads/
9+
# - https://devguide.python.org/versions/
10+
case "${specified_version}" in
11+
"3")
12+
echo "3.12.0"
13+
;;
14+
"3.12")
15+
echo "3.12.0"
16+
;;
17+
"3.11")
18+
echo "3.11.6"
19+
;;
20+
"3.10")
21+
echo "3.10.13"
22+
;;
23+
"3.9")
24+
echo "3.9.18"
25+
;;
26+
"3.8")
27+
echo "3.8.18"
28+
;;
29+
*)
30+
echo "${specified_version}"
31+
;;
32+
esac

install-python.sh

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Follows the guidelines from https://realpython.com/installing-python/#how-to-build-python-from-source-code
6+
7+
function setup_build_prerequisites() {
8+
sudo yum groupinstall -y "Development Tools"
9+
sudo yum install -y tar gzip wget
10+
sudo yum install -y gcc openssl-devel bzip2-devel libffi-devel
11+
}
12+
13+
function set_aliases() {
14+
ln -sf "${python_installation_dir}/bin/python3" "${python_installation_dir}/bin/python"
15+
ln -sf "${python_installation_dir}/bin/pip3" "${python_installation_dir}/bin/pip"
16+
}
17+
118
function setup_python() {
2-
echo "installing python..."
19+
python_version="$1"
20+
python_installation_dir="$2"
21+
22+
setup_build_prerequisites
23+
24+
mkdir -p "${python_installation_dir}"
25+
temp_dir=$(mktemp -d)
26+
pushd "${temp_dir}" >/dev/null
27+
wget "https://www.python.org/ftp/python/${python_version}/Python-${python_version}.tgz"
28+
tar -zxf "Python-${python_version}.tgz"
29+
pushd "Python-${python_version}" >/dev/null
30+
./configure --enable-optimizations --prefix="${python_installation_dir}"
31+
make -j 8
32+
make install
33+
popd >/dev/null
34+
popd
35+
rm -rf "${temp_dir}"
36+
37+
set_aliases
338
}
439

5-
setup_python
40+
setup_python "$1" "$2"

0 commit comments

Comments
 (0)