Skip to content

Commit

Permalink
ci: Add GitHub actions pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
g3n35i5 committed Jun 14, 2024
1 parent b8dced7 commit 4c44428
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 19 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
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", "3.9"]

steps:
- uses: actions/checkout@v4
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@v5
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: Store Python version without dot
run: |
echo "PY_VER_NO_DOT=$(echo ${{ matrix.python-version }} | tr -d '.')" >> $GITHUB_OUTPUT
id: version

- name: Upload coverage artifact
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: pytest.xml.py${{ steps.version.outputs.PY_VER_NO_DOT }}-test
path: reports/pytest.xml.py${{ steps.version.outputs.PY_VER_NO_DOT }}-test

coverage:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: test
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download all coverage artifacts
uses: actions/download-artifact@v4
with:
path: reports

- name: List artifacts
run: ls -ald reports/*

- name: Show file types
run: file reports/*

- uses: actions/setup-python@v5
with:
python-version: 3.9

- 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@v4
with:
fetch-depth: 0

- uses: actions/setup-python@v5
with:
python-version: 3.8

- name: Install tox
run: python -m pip install --upgrade tox

- name: Run static checks
run: tox -e lint
3 changes: 2 additions & 1 deletion Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager

import configuration as config
from shop_db2.api import app, db, set_app

import configuration as config # isort: skip

set_app(config.ProductiveConfig)
migrate = Migrate(app, db)
manager = Manager(app)
Expand Down
2 changes: 1 addition & 1 deletion backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sqlite3
import sys

from configuration import ProductiveConfig
from configuration import ProductiveConfig # isort: skip

if __name__ == "__main__":
_currentDate = datetime.datetime.now()
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,8 @@ module = [
# Ignore packages that do not provide type hints here
# For example, add "dash.*" to ignore all imports from Dash
"sphinxawesome_theme.postprocess",
"sqlalchemy.*",
"flask_script.*",
"flask_migrate.*",
]
ignore_missing_imports = true
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ url = https://github.com/g3n35i5/shop-db2


[options]
python_requires = ~=3.8
python_requires = >=3.8,<3.10
packages = find:
package_dir =
=src
Expand All @@ -30,7 +30,7 @@ install_requires =
MarkupSafe==1.1.1
nose==1.3.7
pdfkit==0.6.1
Pillow==8.3.1
Pillow==10.3.0
pycparser==2.19
PyJWT==1.7.1
python-dateutil==2.8.0
Expand Down
3 changes: 2 additions & 1 deletion setupdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

from sqlalchemy.exc import IntegrityError

import configuration as config
import shop_db2.exceptions as exc
from shop_db2.api import app, db, set_app
from shop_db2.helpers.users import insert_user
from shop_db2.models import Rank, User

import configuration as config # isort: skip


def _get_password():
"""Ask the user for a password and repeat it until both passwords match and
Expand Down
2 changes: 1 addition & 1 deletion shopdb_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys

try:
import configuration as config
import configuration as config # isort: skip
except ModuleNotFoundError:
sys.exit(
"No configuration file was found. Please make sure, "
Expand Down
3 changes: 2 additions & 1 deletion src/shop_db2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from flask import Flask, jsonify
from flask_bcrypt import Bcrypt

import configuration as config
from shop_db2.shared import db

import configuration as config # isort: skip

app = Flask(__name__)

# Default app settings (to suppress unittest warnings) will be overwritten.
Expand Down
3 changes: 2 additions & 1 deletion src/shop_db2/helpers/uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

from PIL import Image

import configuration as config
import shop_db2.exceptions as exc

import configuration as config # isort: skip


def insert_image(file: dict) -> str:
if not file:
Expand Down
3 changes: 2 additions & 1 deletion src/shop_db2/routes/maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
from flask import jsonify

import shop_db2.exceptions as exc
from configuration import PATH
from shop_db2.api import app
from shop_db2.helpers.decorators import adminRequired
from shop_db2.helpers.utils import json_body
from shop_db2.helpers.validators import check_fields_and_types

from configuration import PATH # isort: skip


@app.route("/maintenance", methods=["GET"])
def get_maintenance_mode():
Expand Down
3 changes: 2 additions & 1 deletion tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from flask_testing import TestCase

import configuration as config
from shop_db2.api import app, bcrypt, db, set_app
from shop_db2.models import (
AdminUpdate,
Expand All @@ -20,6 +19,8 @@
User,
)

import configuration as config # isort: skip

# Global password storage. Hashing the passwords for each unit test
# would take too long. For this reason, the passwords are created once
# and then stored in this array.
Expand Down
1 change: 1 addition & 0 deletions tests/unit/api/test_api_get_stocktaking_print_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/api/test_api_toggle_maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
from flask import json

import shop_db2.exceptions as exc
from configuration import PATH
from shop_db2.api import app
from tests.base_api import BaseAPITestCase

from configuration import PATH # isort: skip


class ToggleMaintenanceAPITestCase(BaseAPITestCase):
@staticmethod
Expand Down
21 changes: 14 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
[tox]
envlist =
lint
py38-test
{py38,py39}-test
combine-test-reports
isolated_build = True

[gh-actions]
python =
3.8: py38-test
3.9: py39-test

[testenv:lint]
description = Run static checkers.
basepython = py38
extras = lint
passenv = CODEMETER_HOST
passenv =
RUNNER_OS
commands =
# Check import ordering
isort . --check
isort . --check --diff
# Check formatting
black . --check
# Check type hinting
Expand All @@ -25,14 +30,15 @@ commands =
# pylint --load-plugins pylint.extensions.docparams src {posargs}


[testenv:py38-test]
[testenv:{py38,py39}-test]
description = Run doc tests and unit tests.
package = wheel
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/
Expand All @@ -43,7 +49,7 @@ description = Combine test and coverage data from multiple test runs.
skip_install = true
setenv =
COVERAGE_FILE = reports/.coverage
depends = py38-test
depends = {py38,py39}-test
deps =
junitparser
coverage[toml]
Expand All @@ -56,7 +62,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)'
Expand Down
3 changes: 2 additions & 1 deletion wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import gunicorn.app.base
from gunicorn.six import iteritems

import configuration as config
from shop_db2.api import app, set_app

import configuration as config # isort: skip


def number_of_workers():
return (multiprocessing.cpu_count() * 2) + 1
Expand Down

0 comments on commit 4c44428

Please sign in to comment.