Skip to content

Commit

Permalink
Merge pull request #2 from kirillsulim/dev
Browse files Browse the repository at this point in the history
Add checkstyle and GitHub Actions CI
  • Loading branch information
kirillsulim authored Oct 20, 2022
2 parents 484e254 + d3f3da9 commit 1dde99d
Show file tree
Hide file tree
Showing 21 changed files with 584 additions and 81 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Release app

on:
push:
branches:
- "master"

jobs:
test:
uses: ./.github/workflows/test.yaml
publish:
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Build package
run: poetry build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Tag
run: |
export TAG="$(poetry version -s)"
git tag "${TAG}"
git push origin "${TAG}"
echo "TAG=${TAG}" >> $GITHUB_ENV
- name: Release on github
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.TAG }}
31 changes: 31 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build and test app

on: [pull_request, workflow_call]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Install oak for self build
run: |
poetry install
- name: Run tests
run: |
poetry run oak tests
- name: Check style
run: |
poetry run oak check_style
11 changes: 11 additions & 0 deletions integration_tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from subprocess import run
from unittest import TestCase

from oak_build.oak_file import DEFAULT_OAK_FILE


class BaseTestCase(TestCase):
def get_resources_dir(self) -> Path:
Expand All @@ -10,3 +12,12 @@ def get_resources_dir(self) -> Path:
@classmethod
def setUpClass(cls) -> None:
run(["poetry", "install"], check=True)

def run_oak(self, cwd: Path, *tasks) -> None:
task_list = " ".join(tasks)
oak_file = cwd / DEFAULT_OAK_FILE
run(
f"poetry run oak --log-level=debug --file={oak_file} {task_list}",
check=True,
shell=True,
)
4 changes: 1 addition & 3 deletions integration_tests/resources/file_import/oak_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
from task_2.task_2 import task_2


@task(
depends_on=[task_1, task_2]
)
@task(depends_on=[task_1, task_2])
def collector(task_1_result, task_2_result):
with open(Path("result.txt"), "w") as txt:
txt.write(f"{task_1_result}{task_2_result}\n")
4 changes: 1 addition & 3 deletions integration_tests/resources/param_passing/oak_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ def param_source():
}


@task(
depends_on=[param_source]
)
@task(depends_on=[param_source])
def param_consumer(param_source_param):
with open(Path("result.txt"), "w") as txt:
txt.write(f"{param_source_param}\n")
25 changes: 15 additions & 10 deletions integration_tests/test_oak_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pathlib import Path
from shutil import copytree
from subprocess import run
from tempfile import TemporaryDirectory

from integration_tests.base_test import BaseTestCase
Expand All @@ -10,26 +9,32 @@ class TestOakApp(BaseTestCase):
def test_file_creator(self):
test_project_dir = self.get_resources_dir() / "file_creator"
with TemporaryDirectory() as tmp_dir:
tmp_dir = Path(tmp_dir)

copytree(test_project_dir, tmp_dir, dirs_exist_ok=True)
run(["oak", "create_file"], check=True, cwd=tmp_dir)
self.run_oak(tmp_dir, "create_file")

created_file = Path(tmp_dir) / "result.txt"
self.assertEquals("test content\n", created_file.read_text())
created_file = tmp_dir / "result.txt"
self.assertEqual("test content\n", created_file.read_text())

def test_param_passing(self):
test_project_dir = self.get_resources_dir() / "param_passing"
with TemporaryDirectory() as tmp_dir:

tmp_dir = Path(tmp_dir)
copytree(test_project_dir, tmp_dir, dirs_exist_ok=True)
run(["oak", "param_consumer"], check=True, cwd=tmp_dir)
self.run_oak(tmp_dir, "param_consumer")

created_file = Path(tmp_dir) / "result.txt"
self.assertEquals("value\n", created_file.read_text())
created_file = tmp_dir / "result.txt"
self.assertEqual("value\n", created_file.read_text())

def test_file_import(self):
test_project_dir = self.get_resources_dir() / "file_import"
with TemporaryDirectory() as tmp_dir:
tmp_dir = Path(tmp_dir)

copytree(test_project_dir, tmp_dir, dirs_exist_ok=True)
run(["oak", "collector"], check=True, cwd=tmp_dir)
self.run_oak(tmp_dir, "collector")

created_file = Path(tmp_dir) / "result.txt"
self.assertEquals("12\n", created_file.read_text())
created_file = tmp_dir / "result.txt"
self.assertEqual("12\n", created_file.read_text())
6 changes: 4 additions & 2 deletions integration_tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from shutil import copytree
from subprocess import run
from tempfile import TemporaryDirectory

from integration_tests.base_test import BaseTestCase
Expand All @@ -9,5 +9,7 @@ class TestOakApp(BaseTestCase):
def test_shell_run(self):
test_project_dir = self.get_resources_dir() / "shell_run"
with TemporaryDirectory() as tmp_dir:
tmp_dir = Path(tmp_dir)

copytree(test_project_dir, tmp_dir, dirs_exist_ok=True)
run(["oak", "run_echo"], check=True, cwd=tmp_dir)
self.run_oak(tmp_dir, "run_echo")
68 changes: 68 additions & 0 deletions oak_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from oak_build import task, run


LINE_LENGTH = 120

STYLE_TARGETS = [
"integration_tests",
"src",
"tests",
"oak_file.py",
]

FLAKE8_IGNORE = [
"E203",
"E231",
"W503",
]


@task
def unit_tests():
run("poetry run pytest tests")


@task
def integration_tests():
run("poetry run pytest integration_tests")


@task(
depends_on=[
unit_tests,
integration_tests,
]
)
def tests():
pass


@task
def flake8():
ignore = ",".join(FLAKE8_IGNORE)
targets = " ".join(STYLE_TARGETS)
run(
f"poetry run flake8 --max-line-length {LINE_LENGTH} --extend-ignore {ignore} --show-source {targets}"
)


@task
def black():
targets = " ".join(STYLE_TARGETS)
run(f"poetry run black --check {targets}")


@task
def reformat_with_black():
targets = " ".join(STYLE_TARGETS)
run(f"poetry run black {targets}")


@task(
depends_on=[
flake8,
black,
]
)
def check_style():
pass
Loading

0 comments on commit 1dde99d

Please sign in to comment.