Skip to content

Commit

Permalink
Integrate CI checks (linting, type-checking, tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuatz committed Sep 14, 2024
1 parent 7394100 commit f4d6f72
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 7 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/ci-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: CI Checks

on: [push]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint-and-type-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract project's active Python version
id: python-version
shell: bash
run: echo "python-version=$(cat .tool-versions | grep python | cut -d ' ' -f 2)" >> "$GITHUB_OUTPUT"
working-directory: .
- uses: actions/setup-python@v4
with:
python-version: ${{ steps.python-version.outputs.python-version }}
- uses: abatilo/actions-poetry@v3
with:
poetry-version: 1.7.1
- uses: actions/cache@v4
name: Configure Python poetry cache
with:
path: ./.venv
key: ${{ runner.os }}-${{ runner.arch }}-poetry-venv-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-poetry-venv-
- uses: arduino/setup-task@v2
- name: Install dependencies
shell: bash
run: task install
- name: Lint with ruff
shell: bash
run: task lint:ruff
- name: Type check with mypy
shell: bash
run: task lint:types

test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9, 3.10, 3.11, 3.12]
steps:
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: abatilo/actions-poetry@v3
with:
poetry-version: 1.7.1
- uses: actions/cache@v4
name: Configure Python poetry cache
with:
path: ./.venv
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.python-version }}-poetry-venv-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-${{ matrix.python-version }}-poetry-venv-
- uses: arduino/setup-task@v2
- name: Install dependencies
shell: bash
run: task install
- name: Run tests
shell: bash
run: task test
23 changes: 16 additions & 7 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ tasks:
#==================== Internal Use ==========================#
#============================================================#
_verify_python_venv: |
if [[ -n "$CI" ]]; then
exit 0
fi
DETECTED_PYTHON_PATH=$(which python)
if [[ $DETECTED_PYTHON_PATH != *"/envs/"* && $DETECTED_PYTHON_PATH != $PWD/* ]]; then
echo "Python path (${DETECTED_PYTHON_PATH}) is not scoped to project; please make sure you have activated your virtual environment."
Expand All @@ -46,14 +49,20 @@ tasks:
#============================================================#
#================= Linting / Testing ========================#
#============================================================#
lint:
deps: [_verify_python_venv]
cmd: |
poetry run ruff check "$PACKAGE_DIR"
mypy "$PACKAGE_DIR"
lint:ruff:
deps: [_verify_python_venv, install]
cmd: poetry run ruff check "$PACKAGE_DIR"
lint:types:
deps: [_verify_python_venv, install]
cmd: poetry run mypy "$PACKAGE_DIR"
lint:all:
deps: [_verify_python_venv, install]
cmds:
- task: lint:ruff
- task: lint:types
test:
deps: [_verify_python_venv]
cmd: poetry run pytest -n 4
deps: [_verify_python_venv, install]
cmd: poetry run pytest -n auto
#============================================================#
#================= SECTION_HEADING ==========================#
#============================================================#
3 changes: 3 additions & 0 deletions django_utils_lib/testing/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ def get_config_val(self, config_key: PluginConfigKey):

@property
def auto_debug(self) -> bool:
# Disable if CI is detected
if os.getenv("CI", "").lower() == "true":
return False
return bool(self.get_config_val("auto_debug")) or bool(os.getenv(f"{PACKAGE_NAME}_AUTO_DEBUG", ""))

@property
Expand Down
4 changes: 4 additions & 0 deletions poetry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[virtualenvs]
create = true
in-project = true
path = ".venv"

0 comments on commit f4d6f72

Please sign in to comment.