-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
727001c
commit b0105b2
Showing
3 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# ignore JetBrains IDE files | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# action-setup-python | ||
|
||
This action provides the following functionality for GitHub Actions users: | ||
|
||
- Installing a version of Python or PyPy and (by default) adding it to the PATH, including Python 2.7. | ||
|
||
The action was developed after GitHub decided to remove support for Python 2.7 from their `actions/setup-python` action. | ||
|
||
## Basic usage | ||
|
||
See [action.yml](action.yml) | ||
|
||
**Python** | ||
```yaml | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: LizardByte/action-setup-python | ||
with: | ||
python-version: '3.10' | ||
- run: python my_script.py | ||
``` | ||
**Python 2.7** | ||
```yaml | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: LizardByte/action-setup-python | ||
with: | ||
python-version: '2.7' | ||
- run: python my_script.py | ||
``` | ||
**PyPy** | ||
```yaml | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: LizardByte/action-setup-python | ||
with: | ||
python-version: 'pypy3.9' | ||
- run: python my_script.py | ||
``` | ||
The `python-version` input is required. | ||
|
||
If the version of Python is not `2.7` the action will use `actions/setup-python` and pass the version to that | ||
action. Otherwise, it will install Python 2.7 on your platform. | ||
|
||
## License | ||
|
||
The scripts and documentation in this project are released under the [MIT License](LICENSE). | ||
|
||
## Contributions | ||
|
||
Contributions are welcome! See our | ||
[Contributor's Guide](https://docs.lizardbyte.dev/en/latest/developers/code_of_conduct.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
--- | ||
name: "Setup Python" | ||
description: "Set up a specific version of Python, including Python 2.7, and add the command-line tools to the PATH." | ||
author: "LizardByte" | ||
inputs: | ||
python-version: | ||
description: | | ||
Version range or exact version of Python or PyPy to use, using SemVer's version range syntax. | ||
Reads from .python-version if unset. | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Setup Python 3+ | ||
if: ${{ inputs.python-version != '2.7' }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ inputs.python-version }} | ||
|
||
- name: Windows Install | ||
shell: bash | ||
if: ${{ inputs.python-version == '2.7' && runner.os == 'Windows' }} | ||
run: | | ||
choco install python2 --version=2.7.18 -y --no-progress | ||
- name: Linux Install | ||
shell: bash | ||
if: ${{ inputs.python-version == '2.7' && runner.os == 'Linux' }} | ||
run: | | ||
# get the version from /etc/os-release | ||
version=$(grep -oP '(?<=VERSION_ID=")\d+' /etc/os-release) | ||
echo "Ubuntu version: $version" | ||
sudo apt-get update | ||
if [[ $version == 20 ]]; then | ||
sudo apt-get install python2.7 -y | ||
elif [[ $version == 22 ]]; then | ||
sudo apt-get install python2 python-pip -y | ||
fi | ||
- name: macOS Install | ||
shell: bash | ||
if: ${{ inputs.python-version == '2.7' && runner.os == 'macOS' }} | ||
run: | | ||
python_version=$(python --version 2>&1) | ||
echo "Python version: ${python_version}" | ||
if [[ "${python_version}" == *"Python 2.7"* ]]; then | ||
echo "${python_version} already installed, nothing to do" | ||
else | ||
echo "Python 2.7 not installed" | ||
exit 1 | ||
fi | ||
- name: Setup Python Environment | ||
if: ${{ inputs.python-version == '2.7' }} | ||
shell: bash | ||
run: | | ||
echo "Current system Python Version:" | ||
python --version | ||
echo "Setting paths" | ||
if [[ "${{ runner.os }}" == "Windows" ]]; then | ||
export PATH="/c/Python27:/c/Python27/Scripts:$PATH" | ||
echo "moving GitHub installed Python version" | ||
mv "/c/hostedtoolcache/windows/Python/3.9.13" "/c/hostedtoolcache/windows/Python/3.9.13-backup" | ||
# set venv path | ||
venv_base_path="/c/tmp/python27/venv" | ||
venv_base_path_windows="C:\\tmp\\python27\\venv" | ||
venv_dir="Scripts" | ||
elif [[ "${{ runner.os }}" == "Linux" ]]; then | ||
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 | ||
venv_base_path="/tmp/python27/venv" | ||
venv_dir="bin" | ||
elif [[ "${{ runner.os }}" == "macOS" ]]; then | ||
venv_base_path="/tmp/python27/venv" | ||
venv_dir="bin" | ||
fi | ||
echo "New Python version:" | ||
python --version | ||
echo "Bootstrapping pip" | ||
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py | ||
python get-pip.py | ||
rm -f get-pip.py | ||
echo "Installing virtualenv" | ||
python -m pip install virtualenv | ||
# create venv | ||
python -m virtualenv ${venv_base_path} | ||
# activate venv | ||
source ${venv_base_path}/${venv_dir}/activate | ||
# update | ||
python -m pip --no-python-version-warning --disable-pip-version-check install --upgrade pip setuptools | ||
# update the path environment, so the next steps can use the venv | ||
# required to use the shell | ||
if [[ "${{ runner.os }}" == "Windows" ]]; then | ||
echo "${venv_base_path_windows}\\${venv_dir}" >> $GITHUB_PATH | ||
else | ||
echo "${venv_base_path}/${venv_dir}" >> $GITHUB_PATH | ||
fi | ||
# show python version | ||
echo "Python venv version:" | ||
python --version |