Skip to content

Commit 1386529

Browse files
authored
Merge pull request #1330 from moreati/gha-workflow-cleanup
CI: Refactor and de-duplicate Github Actions workflow
2 parents 4cad51a + 618eccc commit 1386529

File tree

7 files changed

+92
-150
lines changed

7 files changed

+92
-150
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+
}

.ci/show_python_versions

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
set -o errexit -o nounset -o pipefail
3+
4+
INDENT=" "
5+
POSSIBLE_PYTHONS=(
6+
python
7+
python2
8+
python3
9+
/usr/bin/python
10+
/usr/bin/python2
11+
/usr/bin/python3
12+
# GitHub macOS 12 images: python2.7 is installed, but not on $PATH
13+
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
14+
)
15+
16+
for p in "${POSSIBLE_PYTHONS[@]}"; do
17+
echo "$p"
18+
if [[ ${p:0:1} == "/" && -e $p ]]; then
19+
:
20+
elif type "$p" > /dev/null 2>&1; then
21+
type "$p" 2>&1 | sed -e "s/^/${INDENT}type: /"
22+
else
23+
echo "${INDENT}Not present"
24+
echo
25+
continue
26+
fi
27+
28+
$p -c "import sys; print('${INDENT}version: %d.%d.%d' % sys.version_info[:3])"
29+
# macOS builders lack a realpath command
30+
$p -c "import os.path; print('${INDENT}realpath: %s' % os.path.realpath('$(type -p "$p")'))"
31+
$p -c "import sys; print('${INDENT}sys.executable: %s' % sys.executable)"
32+
echo
33+
done

.github/workflows/tests.yml

Lines changed: 24 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ jobs:
2929
- tox_env: py27-m_ans-ans4
3030

3131
- tox_env: py36-m_ans-ans2.10
32-
python_version: '3.6'
3332
- tox_env: py36-m_ans-ans4
34-
python_version: '3.6'
3533

3634
- tox_env: py27-m_mtg
3735
- tox_env: py36-m_mtg
38-
python_version: '3.6'
3936

4037
steps:
4138
- uses: actions/checkout@v4
@@ -44,90 +41,38 @@ jobs:
4441
registry: ghcr.io
4542
username: ${{ github.actor }}
4643
password: ${{ secrets.GITHUB_TOKEN }}
47-
- name: Install build deps
44+
- run: .ci/show_python_versions
45+
- name: Install deps
46+
id: install-deps
4847
run: |
4948
set -o errexit -o nounset -o pipefail
50-
51-
PYTHON=$(python -c 'import re; print(re.sub(r"^py([23])([0-9]{1,2}).*", r"python\1.\2", "${{ matrix.tox_env }}"))')
52-
53-
if [[ -z $PYTHON ]]; then
54-
echo 1>&2 "Python interpreter could not be determined"
55-
exit 1
56-
fi
49+
source .ci/bash_functions
50+
PYTHON="$(toxenv-python '${{ matrix.tox_env }}')"
5751
5852
sudo apt-get update
5953
6054
if [[ $PYTHON == "python2.7" ]]; then
6155
sudo apt install -y python2-dev sshpass virtualenv
62-
elif [[ $PYTHON == "python3.6" ]]; then
63-
sudo apt install -y gcc-10 make libbz2-dev liblzma-dev libreadline-dev libsqlite3-dev libssl-dev sshpass virtualenv zlib1g-dev
64-
curl --fail --silent --show-error --location https://pyenv.run | bash
65-
CC=gcc-10 ~/.pyenv/bin/pyenv install --force 3.6
66-
else
67-
echo 1>&2 "Python interpreter $PYTHON not available"
68-
exit 1
69-
fi
70-
- name: Show Python versions
71-
run: |
72-
set -o errexit -o nounset -o pipefail
73-
74-
# macOS builders lack a realpath command
75-
type python && python -c"import os.path;print(os.path.realpath('$(type -p python)'))" && python --version
76-
type python2 && python2 -c"import os.path;print(os.path.realpath('$(type -p python2)'))" && python2 --version
77-
type python3 && python3 -c"import os.path;print(os.path.realpath('$(type -p python3)'))" && python3 --version
78-
echo
79-
80-
if [ -e /usr/bin/python ]; then
81-
echo "/usr/bin/python: sys.executable: $(/usr/bin/python -c 'import sys; print(sys.executable)')"
82-
fi
83-
84-
if [ -e /usr/bin/python2 ]; then
85-
echo "/usr/bin/python2: sys.executable: $(/usr/bin/python2 -c 'import sys; print(sys.executable)')"
86-
fi
87-
88-
if [ -e /usr/bin/python2.7 ]; then
89-
echo "/usr/bin/python2.7: sys.executable: $(/usr/bin/python2.7 -c 'import sys; print(sys.executable)')"
90-
fi
91-
- name: Install tooling
92-
run: |
93-
set -o errexit -o nounset -o pipefail
94-
95-
# Tox environment name (e.g. py312-m_mtg) -> Python executable name (e.g. python3.12)
96-
PYTHON=$(python -c 'import re; print(re.sub(r"^py([23])([0-9]{1,2}).*", r"python\1.\2", "${{ matrix.tox_env }}"))')
97-
98-
if [[ -z $PYTHON ]]; then
99-
echo 1>&2 "Python interpreter could not be determined"
100-
exit 1
101-
fi
102-
103-
if [[ $PYTHON == "python2.7" ]]; then
10456
curl "https://bootstrap.pypa.io/pip/2.7/get-pip.py" --output "get-pip.py"
10557
"$PYTHON" get-pip.py --user --no-python-version-warning
10658
# Avoid Python 2.x pip masking system pip
10759
rm -f ~/.local/bin/{easy_install,pip,wheel}
10860
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
10964
PYTHON="$HOME/.pyenv/versions/3.6.15/bin/python3.6"
11065
fi
11166
11267
"$PYTHON" -m pip install -r "tests/requirements-tox.txt"
68+
echo "python=$PYTHON" >> $GITHUB_OUTPUT
11369
- name: Run tests
11470
env:
11571
GITHUB_ACTOR: ${{ github.actor }}
11672
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11773
run: |
11874
set -o errexit -o nounset -o pipefail
119-
120-
# Tox environment name (e.g. py312-m_mtg) -> Python executable name (e.g. python3.12)
121-
PYTHON=$(python -c 'import re; print(re.sub(r"^py([23])([0-9]{1,2}).*", r"python\1.\2", "${{ matrix.tox_env }}"))')
122-
123-
if [[ -z $PYTHON ]]; then
124-
echo 1>&2 "Python interpreter could not be determined"
125-
exit 1
126-
fi
127-
128-
if [[ $PYTHON == "python3.6" ]]; then
129-
PYTHON="$HOME/.pyenv/versions/3.6.15/bin/python3.6"
130-
fi
75+
PYTHON="${{ steps.install-deps.outputs.python }}"
13176
13277
"$PYTHON" -m tox -e "${{ matrix.tox_env }}"
13378
@@ -183,60 +128,26 @@ jobs:
183128
registry: ghcr.io
184129
username: ${{ github.actor }}
185130
password: ${{ secrets.GITHUB_TOKEN }}
186-
- name: Install build deps
131+
- run: .ci/show_python_versions
132+
- name: Install deps
133+
id: install-deps
187134
run: |
188135
set -o errexit -o nounset -o pipefail
136+
source .ci/bash_functions
137+
PYTHON="$(toxenv-python '${{ matrix.tox_env }}')"
189138
190139
sudo apt-get update
191140
sudo apt-get install -y sshpass virtualenv
192-
- name: Show Python versions
193-
run: |
194-
set -o errexit -o nounset -o pipefail
195-
196-
# macOS builders lack a realpath command
197-
type python && python -c"import os.path;print(os.path.realpath('$(type -p python)'))" && python --version
198-
type python2 && python2 -c"import os.path;print(os.path.realpath('$(type -p python2)'))" && python2 --version
199-
type python3 && python3 -c"import os.path;print(os.path.realpath('$(type -p python3)'))" && python3 --version
200-
echo
201-
202-
if [ -e /usr/bin/python ]; then
203-
echo "/usr/bin/python: sys.executable: $(/usr/bin/python -c 'import sys; print(sys.executable)')"
204-
fi
205-
206-
if [ -e /usr/bin/python2 ]; then
207-
echo "/usr/bin/python2: sys.executable: $(/usr/bin/python2 -c 'import sys; print(sys.executable)')"
208-
fi
209-
210-
if [ -e /usr/bin/python2.7 ]; then
211-
echo "/usr/bin/python2.7: sys.executable: $(/usr/bin/python2.7 -c 'import sys; print(sys.executable)')"
212-
fi
213-
- name: Install tooling
214-
run: |
215-
set -o errexit -o nounset -o pipefail
216-
217-
# Tox environment name (e.g. py312-m_mtg) -> Python executable name (e.g. python3.12)
218-
PYTHON=$(python -c 'import re; print(re.sub(r"^py([23])([0-9]{1,2}).*", r"python\1.\2", "${{ matrix.tox_env }}"))')
219-
220-
if [[ -z $PYTHON ]]; then
221-
echo 1>&2 "Python interpreter could not be determined"
222-
exit 1
223-
fi
224141
225142
"$PYTHON" -m pip install -r "tests/requirements-tox.txt"
143+
echo "python=$PYTHON" >> $GITHUB_OUTPUT
226144
- name: Run tests
227145
env:
228146
GITHUB_ACTOR: ${{ github.actor }}
229147
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
230148
run: |
231149
set -o errexit -o nounset -o pipefail
232-
233-
# Tox environment name (e.g. py312-m_mtg) -> Python executable name (e.g. python3.12)
234-
PYTHON=$(python -c 'import re; print(re.sub(r"^py([23])([0-9]{1,2}).*", r"python\1.\2", "${{ matrix.tox_env }}"))')
235-
236-
if [[ -z $PYTHON ]]; then
237-
echo 1>&2 "Python interpreter could not be determined"
238-
exit 1
239-
fi
150+
PYTHON="${{ steps.install-deps.outputs.python }}"
240151
241152
"$PYTHON" -m tox -e "${{ matrix.tox_env }}"
242153
@@ -265,61 +176,25 @@ jobs:
265176
with:
266177
python-version: ${{ matrix.python_version }}
267178
if: ${{ matrix.python_version }}
268-
- name: Show Python versions
269-
run: |
270-
set -o errexit -o nounset -o pipefail
271-
272-
# macOS builders lack a realpath command
273-
type python && python -c"import os.path;print(os.path.realpath('$(type -p python)'))" && python --version
274-
type python2 && python2 -c"import os.path;print(os.path.realpath('$(type -p python2)'))" && python2 --version
275-
type python3 && python3 -c"import os.path;print(os.path.realpath('$(type -p python3)'))" && python3 --version
276-
echo
277-
278-
if [ -e /usr/bin/python ]; then
279-
echo "/usr/bin/python: sys.executable: $(/usr/bin/python -c 'import sys; print(sys.executable)')"
280-
fi
281-
282-
if [ -e /usr/bin/python2 ]; then
283-
echo "/usr/bin/python2: sys.executable: $(/usr/bin/python2 -c 'import sys; print(sys.executable)')"
284-
fi
285-
286-
if [ -e /usr/bin/python2.7 ]; then
287-
echo "/usr/bin/python2.7: sys.executable: $(/usr/bin/python2.7 -c 'import sys; print(sys.executable)')"
288-
fi
289-
290-
if [ -e /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 ]; then
291-
# GitHub macOS 12 images: python2.7 is installed, but not on $PATH
292-
echo "/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7: sys.executable: $(/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 -c 'import sys; print(sys.executable)')"
293-
fi
179+
- run: .ci/show_python_versions
294180
- run: .ci/install_sshpass ${{ matrix.sshpass_version }}
295181
if: ${{ matrix.sshpass_version }}
296-
- name: Install tooling
182+
- name: Install deps
183+
id: install-deps
297184
run: |
298185
set -o errexit -o nounset -o pipefail
299-
300-
# Tox environment name (e.g. py312-m_mtg) -> Python executable name (e.g. python3.12)
301-
PYTHON=$(python -c 'import re; print(re.sub(r"^py([23])([0-9]{1,2}).*", r"python\1.\2", "${{ matrix.tox_env }}"))')
302-
303-
if [[ -z $PYTHON ]]; then
304-
echo 1>&2 "Python interpreter could not be determined"
305-
exit 1
306-
fi
186+
source .ci/bash_functions
187+
PYTHON="$(toxenv-python '${{ matrix.tox_env }}')"
307188
308189
"$PYTHON" -m pip install -r "tests/requirements-tox.txt"
190+
echo "python=$PYTHON" >> $GITHUB_OUTPUT
309191
- name: Run tests
310192
env:
311193
GITHUB_ACTOR: ${{ github.actor }}
312194
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
313195
run: |
314196
set -o errexit -o nounset -o pipefail
315-
316-
# Tox environment name (e.g. py312-m_mtg) -> Python executable name (e.g. python3.12)
317-
PYTHON=$(python -c 'import re; print(re.sub(r"^py([23])([0-9]{1,2}).*", r"python\1.\2", "${{ matrix.tox_env }}"))')
318-
319-
if [[ -z $PYTHON ]]; then
320-
echo 1>&2 "Python interpreter could not be determined"
321-
exit 1
322-
fi
197+
PYTHON="${{ steps.install-deps.outputs.python }}"
323198
324199
"$PYTHON" -m tox -e "${{ matrix.tox_env }}"
325200

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ 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+
* :gh:issue:`1315` CI: macOS: Increase failed logins limit of test users
26+
2427

2528
v0.3.26 (2025-08-04)
2629
--------------------

tests/image_prep/_user_accounts.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@
5050
mitogen_test_groups:
5151
- name: mitogen__group
5252
- name: mitogen__sudo_nopw
53-
tasks:
53+
54+
user_policies_max_failed_logins: 1000
55+
user_policies_users: "{{ all_users }}"
56+
pre_tasks:
5457
- name: Disable non-localhost SSH for Mitogen users
5558
when: false
5659
blockinfile:
@@ -180,3 +183,5 @@
180183
validate: '/usr/sbin/visudo -cf %s'
181184
when:
182185
- ansible_virtualization_type != "docker"
186+
roles:
187+
- role: user_policies
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
user_policies_max_failed_logins: 10
2+
user_policies_users: []
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- name: Set login attempts (macOS)
2+
vars:
3+
max_failed_logins: "{{ item.policies.max_failed_logins | default(user_policies_max_failed_logins) }}"
4+
command: >
5+
pwpolicy
6+
-u '{{ item.name }}'
7+
-setpolicy 'maxFailedLoginAttempts={{ max_failed_logins }}'
8+
with_items: "{{ user_policies_users }}"
9+
when:
10+
- ansible_system == 'Darwin'
11+
changed_when: true

0 commit comments

Comments
 (0)