Skip to content

Commit

Permalink
ci: refactor execution of python tests
Browse files Browse the repository at this point in the history
Previously we inconsitently used ubuntu-latest and ubuntu-20.04. We now
pin that (consistently) to 24.04 to avoid floating refs (and the
corresponding GitHub warning). As Python 3.6 and 3.7 is not supported on
ubuntu 24.04, we still execute them on 20.04 (officially EOL in April
2025).

To reduce the test code duplication, we carve out the pytest execution
into an action.

Signed-off-by: Felix Moessbauer <[email protected]>
  • Loading branch information
fmoessbauer committed Jan 7, 2025
1 parent 1d9a3e6 commit 5a148d7
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 54 deletions.
46 changes: 46 additions & 0 deletions .github/actions/perform-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: perform-tests
inputs:
python-version:
required: true

runs:
steps:
- name: Check out repo
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
architecture: x64
- name: Install Python dependencies of kas and tests
run: |
# install kas to have all kas dependencies:
pip install .
# test dependencies:
pip install -U pytest
- name: Install python-newt
run: |
sudo apt-get update
sudo apt-get install libpopt-dev libslang2-dev
wget -q https://releases.pagure.org/newt/newt-$NEWT_VERSION.tar.gz
echo "$NEWT_SHA256 newt-$NEWT_VERSION.tar.gz" | sha256sum -c
tar -C /tmp -xzf newt-$NEWT_VERSION.tar.gz
cd /tmp/newt-$NEWT_VERSION
autoconf
./configure --with-python=python${{ matrix.python-version }}
make -j $(nproc)
sudo make install
ln -s /usr/local/lib/python${{ matrix.python-version }}/site-packages/_snack.so \
$(python3 -c 'import site; print(site.getsitepackages()[0])')/
ln -s /usr/local/lib/python${{ matrix.python-version }}/site-packages/snack.py \
$(python3 -c 'import site; print(site.getsitepackages()[0])')/
- name: Run offline tests
env:
TERM: xterm
http_proxy: http://0.0.0.0:8118
https_proxy: http://0.0.0.0:8118
run: pytest -m "not online"
- name: Run online tests
env:
TERM: xterm
run: pytest -m "online"
2 changes: 1 addition & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
deploy_containers:
name: Build and deploy container images
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
permissions:
id-token: write
packages: write
Expand Down
92 changes: 39 additions & 53 deletions .github/workflows/next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,67 +12,53 @@ env:
NEWT_SHA256: 5ded7e221f85f642521c49b1826c8de19845aa372baf5d630a51774b544fbdbb

jobs:
perform_tests:
name: Run tests on kas code
codestyle:
name: Check code style
runs-on: ubuntu-24.04
steps:
- name: Install Checkcode dependencies
run: |
pip install flake8 pycodestyle doc8 Pygments
- name: Install recent shellcheck
run: |
wget -q https://github.com/koalaman/shellcheck/releases/download/$SHELLCHECK_VERSION/shellcheck-$SHELLCHECK_VERSION.linux.x86_64.tar.xz
echo "$SHELLCHECK_SHA256 shellcheck-$SHELLCHECK_VERSION.linux.x86_64.tar.xz" | sha256sum -c
tar -xJf shellcheck-$SHELLCHECK_VERSION.linux.x86_64.tar.xz
sudo cp shellcheck-$SHELLCHECK_VERSION/shellcheck /usr/local/bin/
- name: Check code
run: scripts/checkcode.sh .

perform_tests_legacy:
name: Test legacy Python versions
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.6", "3.7"]
steps:
- name: Check out repo
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- name: PyTest
uses: ./.github/actions/perform-tests
with:
python-version: ${{ matrix.python-version }}

perform_tests_modern:
name: Test modern Python versions
runs-on: ubuntu-24.04
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- name: PyTest
uses: ./.github/actions/perform-tests
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Install Python dependencies of kas and tests
run: |
# install kas to have all kas dependencies:
pip install .
# checkcode dependencies:
pip install flake8 pycodestyle doc8 Pygments
# test dependencies:
pip install -U pytest
- name: Install recent shellcheck
run: |
wget -q https://github.com/koalaman/shellcheck/releases/download/$SHELLCHECK_VERSION/shellcheck-$SHELLCHECK_VERSION.linux.x86_64.tar.xz
echo "$SHELLCHECK_SHA256 shellcheck-$SHELLCHECK_VERSION.linux.x86_64.tar.xz" | sha256sum -c
tar -xJf shellcheck-$SHELLCHECK_VERSION.linux.x86_64.tar.xz
sudo cp shellcheck-$SHELLCHECK_VERSION/shellcheck /usr/local/bin/
- name: Install python-newt
run: |
sudo apt-get update
sudo apt-get install libpopt-dev libslang2-dev
wget -q https://releases.pagure.org/newt/newt-$NEWT_VERSION.tar.gz
echo "$NEWT_SHA256 newt-$NEWT_VERSION.tar.gz" | sha256sum -c
tar -C /tmp -xzf newt-$NEWT_VERSION.tar.gz
cd /tmp/newt-$NEWT_VERSION
autoconf
./configure --with-python=python${{ matrix.python-version }}
make -j $(nproc)
sudo make install
ln -s /usr/local/lib/python${{ matrix.python-version }}/site-packages/_snack.so \
$(python3 -c 'import site; print(site.getsitepackages()[0])')/
ln -s /usr/local/lib/python${{ matrix.python-version }}/site-packages/snack.py \
$(python3 -c 'import site; print(site.getsitepackages()[0])')/
- name: Check code
run: scripts/checkcode.sh .
- name: Run offline tests
env:
TERM: xterm
http_proxy: http://0.0.0.0:8118
https_proxy: http://0.0.0.0:8118
run: pytest -m "not online"
- name: Run online tests
env:
TERM: xterm
run: pytest -m "online"

build_containers:
name: Build, test and deploy container images
needs: perform_tests
runs-on: ubuntu-latest
needs:
- codestyle
- perform_tests_legacy
- perform_tests_modern
runs-on: ubuntu-24.04
permissions:
id-token: write
packages: write
Expand Down Expand Up @@ -131,7 +117,7 @@ jobs:

cleanup_ghcr_containers:
name: cleanup untagged ${{ matrix.image-name }} containers
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
needs: build_containers
permissions:
packages: write
Expand Down

0 comments on commit 5a148d7

Please sign in to comment.