From a976b0305f85330151f8c58f41855fcfe9e34a23 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Schmidt Date: Sun, 9 Jun 2024 13:54:28 +0200 Subject: [PATCH] ci: Add GitHub actions pipeline --- .github/workflows/pipeline.yml | 94 +++++++++++++++++++ ...test_api_get_stocktaking_print_template.py | 1 + tox.ini | 12 ++- 3 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/pipeline.yml diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 0000000..dc98f3e --- /dev/null +++ b/.github/workflows/pipeline.yml @@ -0,0 +1,94 @@ +name: CI pipeline + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, ubuntu-latest] + python-version: ["3.8"] + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install wkhtmltopdf + run: | + if [ "$RUNNER_OS" == "Linux" ]; then + sudo apt-get install xvfb libfontconfig wkhtmltopdf + elif [ "$RUNNER_OS" == "macOS" ]; then + brew install wkhtmltopdf + fi + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install tox + run: python -m pip install --upgrade pip tox tox-gh-actions + + - name: Write example configuration file + run: cp configuration.example.py configuration.py + + - name: Run tests + run: tox + + - name: Upload coverage artifact + if: matrix.os == 'ubuntu-latest' + uses: actions/upload-artifact@v3.1.2 + with: + name: coverage-${{ matrix.python-version }} + path: reports/.coverage.*test + + coverage: + runs-on: ubuntu-latest + timeout-minutes: 5 + needs: test + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v4 + with: + python-version: 3.8 + + - name: Download all coverage artifacts + uses: actions/download-artifact@v3 + + - name: Copy coverage reports to reports folder + run: mkdir reports && find . -type f -path "./coverage-3.*/*" -exec cp {} reports/ \; + + - name: Install tox + run: python -m pip install --upgrade pip tox + + - name: Combine coverage results + run: tox run -e combine-test-reports + + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v4 + with: + python-version: 3.8 + + - name: Install tox + run: python -m pip install --upgrade tox + + - name: Run static checks + run: tox -e lint diff --git a/tests/unit/api/test_api_get_stocktaking_print_template.py b/tests/unit/api/test_api_get_stocktaking_print_template.py index 2b4aa24..1a0abaa 100644 --- a/tests/unit/api/test_api_get_stocktaking_print_template.py +++ b/tests/unit/api/test_api_get_stocktaking_print_template.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- __author__ = "g3n35i5" + import shop_db2.exceptions as exc from shop_db2.api import db from shop_db2.models import Product diff --git a/tox.ini b/tox.ini index fa52f29..276562f 100644 --- a/tox.ini +++ b/tox.ini @@ -5,12 +5,16 @@ envlist = combine-test-reports isolated_build = True +[gh-actions] +python = + 3.8: py38-test [testenv:lint] description = Run static checkers. basepython = py38 extras = lint -passenv = CODEMETER_HOST +passenv = + RUNNER_OS commands = # Check import ordering isort . --check @@ -32,7 +36,8 @@ extras = test setenv = PY_IGNORE_IMPORTMISMATCH=1 COVERAGE_FILE = reports{/}.coverage.{envname} -passenv = CODEMETER_HOST +passenv = + RUNNER_OS commands = # Run tests and doctests from .py files pytest --junitxml=reports/pytest.xml.{envname} {posargs} src/ tests/ @@ -56,7 +61,8 @@ commands = [testenv:build] description = Build the package. extras = build -passenv = CODEMETER_HOST +passenv = + RUNNER_OS commands = # Clean up build directories python -c 'from shutil import rmtree; rmtree("build", True); rmtree("dist", True)'