Skip to content

Commit 7c21ba2

Browse files
committed
Integrate CI checks (linting, type-checking, tests)
1 parent 7394100 commit 7c21ba2

File tree

4 files changed

+91
-7
lines changed

4 files changed

+91
-7
lines changed

.github/workflows/ci-checks.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: CI Checks
2+
3+
on: [push]
4+
5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.ref }}
7+
cancel-in-progress: true
8+
9+
jobs:
10+
lint-and-type-check:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Extract project's active Python version
15+
id: python-version
16+
shell: bash
17+
run: echo "python-version=$(cat .tool-versions | grep python | cut -d ' ' -f 2)" >> "$GITHUB_OUTPUT"
18+
working-directory: .
19+
- uses: actions/setup-python@v4
20+
with:
21+
python-version: ${{ steps.python-version.outputs.python-version }}
22+
- uses: abatilo/actions-poetry@v3
23+
with:
24+
poetry-version: 1.7.1
25+
- uses: actions/cache@v4
26+
name: Configure Python poetry cache
27+
with:
28+
path: ./.venv
29+
key: ${{ runner.os }}-${{ runner.arch }}-poetry-venv-${{ hashFiles('poetry.lock') }}
30+
restore-keys: |
31+
${{ runner.os }}-${{ runner.arch }}-poetry-venv-
32+
- uses: arduino/setup-task@v2
33+
- name: Install dependencies
34+
shell: bash
35+
run: task install
36+
- name: Lint with ruff
37+
shell: bash
38+
run: task lint:ruff
39+
- name: Type check with mypy
40+
shell: bash
41+
run: task lint:types
42+
43+
test:
44+
runs-on: ubuntu-latest
45+
strategy:
46+
matrix:
47+
python-version: ["3.9", "3.10", "3.11", "3.12"]
48+
steps:
49+
- uses: actions/setup-python@v4
50+
with:
51+
python-version: ${{ matrix.python-version }}
52+
- uses: abatilo/actions-poetry@v3
53+
with:
54+
poetry-version: 1.7.1
55+
- uses: actions/cache@v4
56+
name: Configure Python poetry cache
57+
with:
58+
path: ./.venv
59+
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.python-version }}-poetry-venv-${{ hashFiles('poetry.lock') }}
60+
restore-keys: |
61+
${{ runner.os }}-${{ runner.arch }}-${{ matrix.python-version }}-poetry-venv-
62+
- uses: arduino/setup-task@v2
63+
- name: Install dependencies
64+
shell: bash
65+
run: task install
66+
- name: Run tests
67+
shell: bash
68+
run: task test

Taskfile.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ tasks:
3030
#==================== Internal Use ==========================#
3131
#============================================================#
3232
_verify_python_venv: |
33+
if [[ -n "$CI" ]]; then
34+
exit 0
35+
fi
3336
DETECTED_PYTHON_PATH=$(which python)
3437
if [[ $DETECTED_PYTHON_PATH != *"/envs/"* && $DETECTED_PYTHON_PATH != $PWD/* ]]; then
3538
echo "Python path (${DETECTED_PYTHON_PATH}) is not scoped to project; please make sure you have activated your virtual environment."
@@ -46,14 +49,20 @@ tasks:
4649
#============================================================#
4750
#================= Linting / Testing ========================#
4851
#============================================================#
49-
lint:
50-
deps: [_verify_python_venv]
51-
cmd: |
52-
poetry run ruff check "$PACKAGE_DIR"
53-
mypy "$PACKAGE_DIR"
52+
lint:ruff:
53+
deps: [_verify_python_venv, install]
54+
cmd: poetry run ruff check "$PACKAGE_DIR"
55+
lint:types:
56+
deps: [_verify_python_venv, install]
57+
cmd: poetry run mypy "$PACKAGE_DIR"
58+
lint:all:
59+
deps: [_verify_python_venv, install]
60+
cmds:
61+
- task: lint:ruff
62+
- task: lint:types
5463
test:
55-
deps: [_verify_python_venv]
56-
cmd: poetry run pytest -n 4
64+
deps: [_verify_python_venv, install]
65+
cmd: poetry run pytest -n auto
5766
#============================================================#
5867
#================= SECTION_HEADING ==========================#
5968
#============================================================#

django_utils_lib/testing/pytest_plugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ def get_config_val(self, config_key: PluginConfigKey):
205205

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

210213
@property

poetry.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[virtualenvs]
2+
create = true
3+
in-project = true
4+
path = ".venv"

0 commit comments

Comments
 (0)