Merge pull request #132 from dnvgl/remove-pkg-resources #202
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
# This workflow will lint, run unit tests, test CLI and build with a variety of Python versions | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
# 06.12.2024: modified slightly with inspiration from: | |
# https://github.com/marketplace/actions/install-poetry-action#testing-using-a-matrix | |
# https://adamj.eu/tech/2023/11/02/github-actions-faster-python-virtual-environments/ | |
name: Test Python package | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
jobs: | |
#---------------------------------------------- | |
# linting | |
#---------------------------------------------- | |
linting: | |
name: Linting | |
# linting has nothing to do with multiple versions of os and python | |
# (the result will be the same) and therefore separated to save time | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
- name: Load pip cache if cache exists | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip | |
restore-keys: ${{ runner.os }}-pip | |
- name: Install linters | |
run: python -m pip install black flake8 isort | |
- name: Lint code | |
run: | | |
flake8 ./qats/ --exit-zero --max-complexity=10 --statistics | |
black . | |
isort . | |
#---------------------------------------------- | |
# test using a matrix | |
#---------------------------------------------- | |
testing: | |
needs: linting | |
name: Test with Python ${{ matrix.python-version }} on ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: ["ubuntu-latest"] | |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | |
steps: | |
# https://stackoverflow.com/questions/75549995/why-do-the-pyside6-qt-modules-cause-tox-to-fail-during-a-github-action | |
- name: Install missing libraries on GitHub agent | |
run: sudo apt update && sudo apt install -y libegl1-mesa-dev | |
#---------------------------------------------- | |
# check-out repo and set-up python | |
#---------------------------------------------- | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Set up python ${{ matrix.python-version }} | |
id: setup-python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
#---------------------------------------------- | |
# install & configure poetry | |
#---------------------------------------------- | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
- name: Install dynamic versioning plugin | |
run: poetry self add "poetry-dynamic-versioning[plugin]" | |
#---------------------------------------------- | |
# load (restore) cached venv if cache exists | |
#---------------------------------------------- | |
- name: Load cached venv | |
id: cached-poetry-dependencies | |
uses: actions/cache/restore@v4 | |
with: | |
path: .venv | |
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
#---------------------------------------------- | |
# install dependencies if cache does not exist | |
#---------------------------------------------- | |
- name: Install dependencies | |
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | |
run: poetry install --no-interaction --no-root | |
#---------------------------------------------- | |
# save cached venv | |
#---------------------------------------------- | |
- name: Save cached venv | |
uses: actions/cache/save@v4 | |
with: | |
path: .venv | |
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
#---------------------------------------------- | |
# install root project, if required | |
#---------------------------------------------- | |
- name: Install project | |
run: poetry install --no-interaction | |
#---------------------------------------------- | |
# run tests | |
#---------------------------------------------- | |
- name: Run unit tests | |
run: | | |
source .venv/bin/activate | |
pytest test/ | |
- name: Test CLI | |
env: | |
QT_API: pyside6 | |
run: | | |
source .venv/bin/activate | |
qats -h | |
qats app -h | |
qats config -h | |
python -m qats -h | |
- name: Test building package | |
run: poetry build | |
- name: Test building documentation | |
run: | | |
source .venv/bin/activate | |
sphinx-build -b html docs/source docs/_build | |
#---------------------------------------------- | |
# upload artifacts | |
# (only done for one of the python versions) | |
#---------------------------------------------- | |
- name: Upload artifacts | |
if: ${{ matrix.python-version == '3.11' }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test-builds | |
path: | | |
dist/qats-*.tar.gz | |
dist/qats-*.whl |