Skip to content

Commit 9e3377c

Browse files
committed
CI: Combine build deps & tooling steps
1 parent e324191 commit 9e3377c

File tree

3 files changed

+38
-80
lines changed

3 files changed

+38
-80
lines changed

.ci/bash_functions

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# shellcheck shell=bash
2+
3+
# Tox environment name -> Python executable name (e.g. py312-m_mtg -> python3.12)
4+
toxenv-python() {
5+
local pattern='^py([23])([0-9]{1,2}).*'
6+
if [[ $1 =~ $pattern ]]; then
7+
echo "python${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
8+
return
9+
else
10+
echo "${FUNCNAME[0]}: $1: environment name not recognised" >&2
11+
return 1
12+
fi
13+
}

.github/workflows/tests.yml

Lines changed: 23 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -41,70 +41,38 @@ jobs:
4141
registry: ghcr.io
4242
username: ${{ github.actor }}
4343
password: ${{ secrets.GITHUB_TOKEN }}
44-
- name: Install build deps
44+
- run: .ci/show_python_versions
45+
- name: Install deps
46+
id: install-deps
4547
run: |
4648
set -o errexit -o nounset -o pipefail
47-
48-
PYTHON=$(python -c 'import re; print(re.sub(r"^py([23])([0-9]{1,2}).*", r"python\1.\2", "${{ matrix.tox_env }}"))')
49-
50-
if [[ -z $PYTHON ]]; then
51-
echo 1>&2 "Python interpreter could not be determined"
52-
exit 1
53-
fi
49+
source .ci/bash_functions
50+
PYTHON="$(toxenv-python '${{ matrix.tox_env }}')"
5451
5552
sudo apt-get update
5653
5754
if [[ $PYTHON == "python2.7" ]]; then
5855
sudo apt install -y python2-dev sshpass virtualenv
59-
elif [[ $PYTHON == "python3.6" ]]; then
60-
sudo apt install -y gcc-10 make libbz2-dev liblzma-dev libreadline-dev libsqlite3-dev libssl-dev sshpass virtualenv zlib1g-dev
61-
curl --fail --silent --show-error --location https://pyenv.run | bash
62-
CC=gcc-10 ~/.pyenv/bin/pyenv install --force 3.6
63-
else
64-
echo 1>&2 "Python interpreter $PYTHON not available"
65-
exit 1
66-
fi
67-
- run: .ci/show_python_versions
68-
- name: Install tooling
69-
run: |
70-
set -o errexit -o nounset -o pipefail
71-
72-
# Tox environment name (e.g. py312-m_mtg) -> Python executable name (e.g. python3.12)
73-
PYTHON=$(python -c 'import re; print(re.sub(r"^py([23])([0-9]{1,2}).*", r"python\1.\2", "${{ matrix.tox_env }}"))')
74-
75-
if [[ -z $PYTHON ]]; then
76-
echo 1>&2 "Python interpreter could not be determined"
77-
exit 1
78-
fi
79-
80-
if [[ $PYTHON == "python2.7" ]]; then
8156
curl "https://bootstrap.pypa.io/pip/2.7/get-pip.py" --output "get-pip.py"
8257
"$PYTHON" get-pip.py --user --no-python-version-warning
8358
# Avoid Python 2.x pip masking system pip
8459
rm -f ~/.local/bin/{easy_install,pip,wheel}
8560
elif [[ $PYTHON == "python3.6" ]]; then
61+
sudo apt install -y gcc-10 make libbz2-dev liblzma-dev libreadline-dev libsqlite3-dev libssl-dev sshpass virtualenv zlib1g-dev
62+
curl --fail --silent --show-error --location https://pyenv.run | bash
63+
CC=gcc-10 ~/.pyenv/bin/pyenv install --force 3.6
8664
PYTHON="$HOME/.pyenv/versions/3.6.15/bin/python3.6"
8765
fi
8866
8967
"$PYTHON" -m pip install -r "tests/requirements-tox.txt"
68+
echo "python=$PYTHON" >> $GITHUB_OUTPUT
9069
- name: Run tests
9170
env:
9271
GITHUB_ACTOR: ${{ github.actor }}
9372
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9473
run: |
9574
set -o errexit -o nounset -o pipefail
96-
97-
# Tox environment name (e.g. py312-m_mtg) -> Python executable name (e.g. python3.12)
98-
PYTHON=$(python -c 'import re; print(re.sub(r"^py([23])([0-9]{1,2}).*", r"python\1.\2", "${{ matrix.tox_env }}"))')
99-
100-
if [[ -z $PYTHON ]]; then
101-
echo 1>&2 "Python interpreter could not be determined"
102-
exit 1
103-
fi
104-
105-
if [[ $PYTHON == "python3.6" ]]; then
106-
PYTHON="$HOME/.pyenv/versions/3.6.15/bin/python3.6"
107-
fi
75+
PYTHON="${{ steps.install-deps.outputs.python }}"
10876
10977
"$PYTHON" -m tox -e "${{ matrix.tox_env }}"
11078
@@ -160,40 +128,26 @@ jobs:
160128
registry: ghcr.io
161129
username: ${{ github.actor }}
162130
password: ${{ secrets.GITHUB_TOKEN }}
163-
- name: Install build deps
131+
- run: .ci/show_python_versions
132+
- name: Install deps
133+
id: install-deps
164134
run: |
165135
set -o errexit -o nounset -o pipefail
136+
source .ci/bash_functions
137+
PYTHON="$(toxenv-python '${{ matrix.tox_env }}')"
166138
167139
sudo apt-get update
168140
sudo apt-get install -y sshpass virtualenv
169-
- run: .ci/show_python_versions
170-
- name: Install tooling
171-
run: |
172-
set -o errexit -o nounset -o pipefail
173-
174-
# Tox environment name (e.g. py312-m_mtg) -> Python executable name (e.g. python3.12)
175-
PYTHON=$(python -c 'import re; print(re.sub(r"^py([23])([0-9]{1,2}).*", r"python\1.\2", "${{ matrix.tox_env }}"))')
176-
177-
if [[ -z $PYTHON ]]; then
178-
echo 1>&2 "Python interpreter could not be determined"
179-
exit 1
180-
fi
181141
182142
"$PYTHON" -m pip install -r "tests/requirements-tox.txt"
143+
echo "python=$PYTHON" >> $GITHUB_OUTPUT
183144
- name: Run tests
184145
env:
185146
GITHUB_ACTOR: ${{ github.actor }}
186147
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
187148
run: |
188149
set -o errexit -o nounset -o pipefail
189-
190-
# Tox environment name (e.g. py312-m_mtg) -> Python executable name (e.g. python3.12)
191-
PYTHON=$(python -c 'import re; print(re.sub(r"^py([23])([0-9]{1,2}).*", r"python\1.\2", "${{ matrix.tox_env }}"))')
192-
193-
if [[ -z $PYTHON ]]; then
194-
echo 1>&2 "Python interpreter could not be determined"
195-
exit 1
196-
fi
150+
PYTHON="${{ steps.install-deps.outputs.python }}"
197151
198152
"$PYTHON" -m tox -e "${{ matrix.tox_env }}"
199153
@@ -225,33 +179,22 @@ jobs:
225179
- run: .ci/show_python_versions
226180
- run: .ci/install_sshpass ${{ matrix.sshpass_version }}
227181
if: ${{ matrix.sshpass_version }}
228-
- name: Install tooling
182+
- name: Install deps
183+
id: install-deps
229184
run: |
230185
set -o errexit -o nounset -o pipefail
231-
232-
# Tox environment name (e.g. py312-m_mtg) -> Python executable name (e.g. python3.12)
233-
PYTHON=$(python -c 'import re; print(re.sub(r"^py([23])([0-9]{1,2}).*", r"python\1.\2", "${{ matrix.tox_env }}"))')
234-
235-
if [[ -z $PYTHON ]]; then
236-
echo 1>&2 "Python interpreter could not be determined"
237-
exit 1
238-
fi
186+
source .ci/bash_functions
187+
PYTHON="$(toxenv-python '${{ matrix.tox_env }}')"
239188
240189
"$PYTHON" -m pip install -r "tests/requirements-tox.txt"
190+
echo "python=$PYTHON" >> $GITHUB_OUTPUT
241191
- name: Run tests
242192
env:
243193
GITHUB_ACTOR: ${{ github.actor }}
244194
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
245195
run: |
246196
set -o errexit -o nounset -o pipefail
247-
248-
# Tox environment name (e.g. py312-m_mtg) -> Python executable name (e.g. python3.12)
249-
PYTHON=$(python -c 'import re; print(re.sub(r"^py([23])([0-9]{1,2}).*", r"python\1.\2", "${{ matrix.tox_env }}"))')
250-
251-
if [[ -z $PYTHON ]]; then
252-
echo 1>&2 "Python interpreter could not be determined"
253-
exit 1
254-
fi
197+
PYTHON="${{ steps.install-deps.outputs.python }}"
255198
256199
"$PYTHON" -m tox -e "${{ matrix.tox_env }}"
257200

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ To avail of fixes in an unreleased version, please download a ZIP file
2121
In progress (unreleased)
2222
------------------------
2323

24+
* :gh:issue:`1329` CI: Refactor and de-duplicate Github Actions workflow
25+
2426

2527
v0.3.26 (2025-08-04)
2628
--------------------

0 commit comments

Comments
 (0)