diff --git a/.circleci/config.yml b/.circleci/config.yml index 33836cd1..1fd6db6e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,33 +25,34 @@ jobs: name: docker-executor python_version: "<>" parallelism: 4 - working_directory: ~/project/api steps: - - checkout: - path: ~/project + - checkout - run: - name: Install Dependencies - command: poetry install --no-root + name: Install poetry + command: python -m pip install poetry - run: - name: Set PYTHONPATH - command: echo 'export PYTHONPATH=$PYTHONPATH:.' >> $BASH_ENV + name: Install dev tool dependency + command: python -m poetry install + - run: + name: Install backend API dependency + command: python -m poetry run inv api.init-poetry-env - run: name: Run tests - command: | - poetry run pytest ../tests || poetry run pytest --last-failed ../tests + command: python -m poetry run inv api.test precommit: executor: docker-executor - working_directory: ~/project/api steps: - - checkout: - path: ~/project + - checkout - run: - name: Install Pre-commit - command: pip install pre-commit + name: Install poetry + command: python -m pip install poetry - run: - name: Run pre-commit hooks - command: pre-commit run --all-files + name: Install dev tool dependency + command: python -m poetry install --with pre-commit + - run: + name: Run tests + command: python -m poetry run inv run-pre-commit build-docs: description: "Build docs check (the actual publishing is handled by .readthedocs.yaml)" diff --git a/tasks/__init__.py b/tasks/__init__.py index 964ce7c3..0773b1e8 100644 --- a/tasks/__init__.py +++ b/tasks/__init__.py @@ -1,8 +1,19 @@ -from invoke import Collection +from invoke import Collection, task +from invoke.context import Context from tasks import api, docs, ui +from tasks.common import project_root + + +@task +def run_pre_commit(ctx: Context) -> None: + """Run pre-commit""" + with ctx.cd(project_root): + ctx.run("pre-commit run --all-files") + ns = Collection() ns.add_collection(api) -ns.add_collection(docs) ns.add_collection(ui) +ns.add_collection(docs) +ns.add_task(run_pre_commit) diff --git a/tasks/api.py b/tasks/api.py index ed6a15b5..c124e4ac 100644 --- a/tasks/api.py +++ b/tasks/api.py @@ -46,7 +46,7 @@ def run_with_docker( follow_logs: bool = True, ) -> None: """Run ask-astro API server with docker""" - with ctx.cd("api"): + with ctx.cd(api_root): if build_image: print(f"Building image {image_name}") ctx.run(f"docker build . --tag {image_name}") @@ -61,9 +61,17 @@ def run_with_docker( ) def stop_container(ctx: Context, container_name: str = api_container_name, remove_container: bool = True) -> None: """Stop ask-astro API server container""" - with ctx.cd("api"): + with ctx.cd(api_root): print(f"stop container {container_name}") ctx.run(f"docker stop {container_name}") if remove_container: print(f"remove container {container_name}") ctx.run(f"docker remove {container_name}") + + +@task +def test(ctx: Context) -> None: + """Run ask-astro API tests""" + with ctx.cd(api_root): + print("Run ask-astro API tests") + ctx.run("poetry run ../tests || poetry run pytest --last-failed ../tests")