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 77a1997
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 3 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, windows-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
5 changes: 5 additions & 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,12 +2,17 @@
# -*- coding: utf-8 -*-
__author__ = "g3n35i5"

import os

import pytest

import shop_db2.exceptions as exc
from shop_db2.api import db
from shop_db2.models import Product
from tests.base_api import BaseAPITestCase


@pytest.mark.skipif(os.environ.get("RUNNER_OS") == "Windows", reason="Does not work on Windows")
class GetStocktakingPrintTemplateAPITestCase(BaseAPITestCase):
def test_get_stocktaking_template_file_type(self):
"""This test verifies that the file format returned by the API is correct."""
Expand Down
12 changes: 9 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit 77a1997

Please sign in to comment.