Skip to content

Commit

Permalink
build(tasks): move circle ci commands to tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-W committed Nov 16, 2023
1 parent bc14f05 commit 85b0a1a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
33 changes: 17 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,34 @@ jobs:
name: docker-executor
python_version: "<<parameters.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)"
Expand Down
15 changes: 13 additions & 2 deletions tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 10 additions & 2 deletions tasks/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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")

0 comments on commit 85b0a1a

Please sign in to comment.