@@ -9,8 +9,23 @@ branding:
99
1010inputs :
1111 python-version :
12- description : " The version of Python to set up."
13- required : true
12+ description : >
13+ The version(s) of Python to set up.
14+ Can be a single version or multiple versions separated by newlines or spaces.
15+ required : false
16+ python-version-file :
17+ description : >
18+ File containing the Python version to set up.
19+ Supports .python-version, pyproject.toml, .tool-versions, and Pipfile.
20+ required : false
21+
22+ outputs :
23+ python-version :
24+ description : " The version of Python that was set up."
25+ value : ${{ steps.outputs.outputs.python-version }}
26+ python-path :
27+ description : " The path to the Python executable."
28+ value : ${{ steps.outputs.outputs.python-path }}
1429
1530runs :
1631 using : " composite"
@@ -49,21 +64,51 @@ runs:
4964 shell : bash
5065 run : pyenv update
5166
67+ - name : Determine Python Version(s)
68+ id : determine-version
69+ shell : bash
70+ env :
71+ INPUT_PYTHON_VERSION : ${{ inputs.python-version }}
72+ INPUT_PYTHON_VERSION_FILE : ${{ inputs.python-version-file }}
73+ run : |
74+ # Source the version determination script
75+ source "${{ github.action_path }}/determine_version.sh"
76+
77+ # Determine versions using the shared function
78+ determine_python_version "${INPUT_PYTHON_VERSION}" "${INPUT_PYTHON_VERSION_FILE}"
79+
80+ echo "Python versions to install: ${PYTHON_VERSIONS}"
81+ echo "Default Python version: ${DEFAULT_PYTHON_VERSION}"
82+ echo "versions=${PYTHON_VERSIONS}" >> $GITHUB_OUTPUT
83+ echo "default-version=${DEFAULT_PYTHON_VERSION}" >> $GITHUB_OUTPUT
84+
5285 - name : Available Python versions
5386 shell : bash
5487 run : pyenv install --list
5588
5689 - name : Install Python
5790 env :
58- INPUT_PYTHON_VERSION : ${{ inputs.python-version }}
91+ PYTHON_VERSIONS : ${{ steps.determine-version.outputs.versions }}
92+ DEFAULT_VERSION : ${{ steps.determine-version.outputs.default-version }}
5993 shell : bash
6094 run : |
61- pyenv install ${INPUT_PYTHON_VERSION}
62- pyenv global ${INPUT_PYTHON_VERSION}
95+ # Convert space-separated versions to array
96+ IFS=' ' read -ra version_array <<< "${PYTHON_VERSIONS}"
97+
98+ # Install each version
99+ for version in "${version_array[@]}"; do
100+ echo "Installing Python ${version}..."
101+ pyenv install ${version}
102+ done
103+
104+ # Set only the default version as global
105+ pyenv global ${DEFAULT_VERSION}
106+
107+ echo "Default Python version set to: ${DEFAULT_VERSION}"
63108
64109 - name : Setup Python Environment
65110 env :
66- INPUT_PYTHON_VERSION : ${{ inputs.python -version }}
111+ DEFAULT_VERSION : ${{ steps.determine-version.outputs.default -version }}
67112 shell : bash
68113 run : |
69114 echo "Current system Python Version:"
97142 fi
98143
99144 # Extract major.minor version (e.g., "2.7.18" -> "2.7", "2.7-win32" -> "2.7", "3.10.5" -> "3.10")
100- python_version_two_digit=$(echo "${INPUT_PYTHON_VERSION }" | sed -E 's/^([0-9]+\.[0-9]+).*$/\1/')
145+ python_version_two_digit=$(echo "${DEFAULT_VERSION }" | sed -E 's/^([0-9]+\.[0-9]+).*$/\1/')
101146
102147 # Convert version to comparable format (e.g., "2.7" -> 27, "3.10" -> 310)
103148 version_major=$(echo "${python_version_two_digit}" | cut -d. -f1)
@@ -139,3 +184,19 @@ runs:
139184 # show python version
140185 echo "Python venv version:"
141186 python --version
187+
188+ - name : Set outputs
189+ id : outputs
190+ shell : bash
191+ run : |
192+ python_path=$(which python)
193+
194+ # Convert to Windows path format on Windows runners
195+ if [[ "${{ runner.os }}" == "Windows" ]]; then
196+ python_path=$(cygpath -w "${python_path}")
197+ fi
198+
199+ {
200+ echo "python-version=$(pyenv version-name)"
201+ echo "python-path=${python_path}"
202+ } >> "${GITHUB_OUTPUT}"
0 commit comments