From 1f7c5a77e61fc598a9d64b8c7c9c33d7ff6dcdcd Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Mon, 4 Dec 2023 19:46:15 -0500 Subject: [PATCH] Add linters to scripts and drone pipeline --- .drone.yml | 5 +++-- scripts/bootstrap.sh | 13 +++++++++++-- scripts/run_linters.sh | 28 ++++++++++++++++++++++++++++ tasks.py | 6 ++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100755 scripts/run_linters.sh diff --git a/.drone.yml b/.drone.yml index 99b0c9f..66eb8e5 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,11 +4,12 @@ type: docker name: CI Test Pipeline steps: -- name: Unit Tests +- name: Unit Tests and Linters image: python:3.11-bullseye # Todo add command for lint checks commands: - - bash -c './scripts/run_unit_tests.sh' + - bash -xc './scripts/run_linters.sh' + - bash -xc './scripts/run_unit_tests.sh' group: test-lint - name: Lint Chart image: pelotech/drone-helm3 diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 8a0f4b6..0019db8 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -16,8 +16,17 @@ source "$(dirname "$0")/_common.sh" function project_bootstrap() { _setup_env pip install -U pip pip-tools=='7.3.0' - pip-compile requirements.in - pip-compile dev-requirements.in + + # Check if requirements.txt exists, if not, compile it from requirements.in + if [ ! -f requirements.txt ]; then + pip-compile requirements.in + fi + + # Check if dev-requirements.txt exists, if not, compile it from dev-requirements.in + if [ ! -f dev-requirements.txt ]; then + pip-compile dev-requirements.in + fi + pip-sync requirements.txt dev-requirements.txt } diff --git a/scripts/run_linters.sh b/scripts/run_linters.sh new file mode 100755 index 0000000..1659177 --- /dev/null +++ b/scripts/run_linters.sh @@ -0,0 +1,28 @@ +#! /usr/bin/env bash + +# shellcheck source=/dev/null +source "$(dirname "$0")/_common.sh" + +if [ "${DRONE}" == "true" ]; then + _setup_env + pip install -r requirements.txt -r dev-requirements.txt +fi + +# Run linting commands and capture their return codes +"${VIRTUAL_ENV}/bin/python3" -m isort --check ./speech_collect ./tests ./tasks.py +ISORT_EXIT_CODE=$? + +"${VIRTUAL_ENV}/bin/python3" -m black --check ./speech_collect ./tests ./tasks.py +BLACK_EXIT_CODE=$? + +"${VIRTUAL_ENV}/bin/python3" -m ruff ./speech_collect ./tests ./tasks.py +RUFF_EXIT_CODE=$? + +# Check if any linting command failed +if [ $ISORT_EXIT_CODE -ne 0 ] || [ $BLACK_EXIT_CODE -ne 0 ] || [ $RUFF_EXIT_CODE -ne 0 ]; then + echo "Some linting checks failed" + # Exit with a non-zero status, you can choose which error code to return + exit 1 +fi + +echo "All linting checks passed" diff --git a/tasks.py b/tasks.py index 0744c2e..26c70d5 100644 --- a/tasks.py +++ b/tasks.py @@ -43,6 +43,12 @@ def build_image(c, dev=True, registry_user=None, registry_token=None, push=False c.run(f"docker push {image_name}") +@task +def lint(c): + """Runs all linters against the project.""" + c.run("./scripts/run_linters.sh", pty=True) + + @task def delint(c): """Applies automated linters to project"""