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 9, 2024
1 parent b8dced7 commit a9b3afa
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 14 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
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: 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
1 change: 0 additions & 1 deletion src/shop_db2/routes/maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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
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
14 changes: 10 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ 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
isort . --check --diff
# Check formatting
black . --check
# Check type hinting
Expand All @@ -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/
Expand All @@ -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)'
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 a9b3afa

Please sign in to comment.