-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.yml
124 lines (106 loc) · 4.3 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
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
architecture:
description: |
The target architecture (x86, x64) of the Python or PyPy interpreter.
For Python 2.7, this is only supported on Windows.
required: false
default: "x64"
runs:
using: "composite"
steps:
- name: Setup Python 3+
if: ${{ inputs.python-version != '2.7' }}
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
architecture: ${{ inputs.architecture }}
- name: Windows Install
shell: bash
if: ${{ inputs.python-version == '2.7' && runner.os == 'Windows' }}
run: |
if [[ "${{ inputs.architecture }}" == "x86" ]]; then
extra_flags="-x86"
fi
choco install python2 --version=2.7.18 -y --no-progress ${extra_flags}
- name: Unix Install
shell: bash
if: ${{ inputs.python-version == '2.7' && (runner.os == 'Linux' || runner.os == 'macOS') }}
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
curl https://pyenv.run | bash
export PATH="$HOME/.pyenv/bin:$PATH"
elif [[ "${{ runner.os }}" == "macOS" ]]; then
# if macos version >= 13
if [[ $(sw_vers -productVersion | cut -d '.' -f1) -ge 13 ]]; then
echo "macOS version >= 13, relinking [email protected] to avoid brew error"
brew unlink [email protected]
brew link --overwrite [email protected]
fi
# install pyenv
brew install pyenv
export PATH="$(pyenv root)/shims:$(pyenv root)/bin:$PATH"
fi
# install python 2.7
pyenv install 2.7.18
- 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" || "${{ runner.os }}" == "macOS" ]]; then
if [[ "${{ runner.os }}" == "Linux" ]]; then
export PATH="$HOME/.pyenv/bin:$PATH"
# update alternatives
sudo update-alternatives --install /usr/bin/python python $(pyenv root)/shims/python 1
elif [[ "${{ runner.os }}" == "macOS" ]]; then
export PATH="$(pyenv root)/shims:$(pyenv root)/bin:$PATH" # use this instead of GITHUB_PATH to be first
fi
pyenv global 2.7.18
# set python to use `$(pyenv root)/versions/2.7.18/bin`
# export PATH="$(pyenv root)/versions/2.7.18/bin:$PATH"
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