Skip to content

Commit 34bceba

Browse files
committed
ci(tox): add tox for multiple env test and also use it for CI
1 parent 716bc83 commit 34bceba

File tree

4 files changed

+124
-23
lines changed

4 files changed

+124
-23
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ insert_final_newline = true
1010
charset = utf-8
1111
end_of_line = lf
1212

13+
[*.ini]
14+
indent_size = 4
15+
1316
[*.py]
1417
indent_size = 4
1518

.github/workflows/test.yml

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ jobs:
1313
lint:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- name: Dump GitHub context
17-
env:
18-
GITHUB_CONTEXT: ${{ toJson(github) }}
19-
run: echo "$GITHUB_CONTEXT"
2016
- uses: actions/checkout@v4
21-
- name: Install the latest version of uv and set the python version to 3.13t
17+
- name: Install the latest version of uv
2218
uses: astral-sh/setup-uv@v5
2319
with:
24-
enable-cache: true
25-
python-version: 3.11
26-
- name: Lint
27-
run: uv run bash scripts/lint.sh
20+
enable-cache: true
21+
python-version: "3.11"
22+
- name: Install tox
23+
run: uv tool install tox --with tox-uv --with tox-gh
24+
- name: Run lint
25+
run: tox -e lint
2826

2927
test:
3028
runs-on: ubuntu-latest
@@ -62,25 +60,64 @@ jobs:
6260
POSTGRES_HOST: localhost
6361
POSTGRES_PORT: 5432
6462
REDIS_HOST: redis://localhost:6379
63+
TOX_GH_MAJOR_MINOR: ${{ matrix.python-version }}
6564
steps:
66-
- name: Dump GitHub context
67-
env:
68-
GITHUB_CONTEXT: ${{ toJson(github) }}
69-
run: echo "$GITHUB_CONTEXT"
7065
- uses: actions/checkout@v4
71-
- name: Install the latest version of uv and set the python version
66+
- name: Install the latest version of uv
7267
uses: astral-sh/setup-uv@v5
7368
with:
7469
enable-cache: true
7570
python-version: ${{ matrix.python-version }}
76-
- run: mkdir coverage
77-
- name: Test
78-
run: uv run --group test --all-extras coverage run -m pytest sandbox
71+
- name: Install tox
72+
run: uv tool install tox --with tox-uv --with tox-gh
73+
- name: Run tests
74+
run: tox
75+
76+
coverage:
77+
runs-on: ubuntu-latest
78+
services:
79+
postgres:
80+
image: postgres
7981
env:
80-
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}
81-
CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}
82-
- name: Store coverage files
83-
uses: actions/upload-artifact@v4
82+
POSTGRES_PASSWORD: chanx_test_pass
83+
POSTGRES_DB: chanx_test_db
84+
POSTGRES_USER: chanx_test_user
85+
options: >-
86+
--health-cmd pg_isready
87+
--health-interval 10s
88+
--health-timeout 5s
89+
--health-retries 5
90+
ports:
91+
- 5440:5432
92+
redis:
93+
image: redis
94+
options: >-
95+
--health-cmd "redis-cli ping"
96+
--health-interval 10s
97+
--health-timeout 5s
98+
--health-retries 5
99+
ports:
100+
- 6390:6379
101+
env:
102+
POSTGRES_DB: chanx_test_db
103+
POSTGRES_USER: chanx_test_user
104+
POSTGRES_PASSWORD: chanx_test_pass
105+
POSTGRES_HOST: localhost
106+
POSTGRES_PORT: 5440
107+
REDIS_HOST: redis://localhost:6390
108+
steps:
109+
- uses: actions/checkout@v4
110+
- name: Install the latest version of uv
111+
uses: astral-sh/setup-uv@v5
112+
with:
113+
enable-cache: true
114+
python-version: "3.11"
115+
- name: Install tox
116+
run: uv tool install tox --with tox-uv --with tox-gh
117+
- name: Run coverage
118+
run: tox -e coverage
119+
- name: Upload coverage reports to Codecov
120+
uses: codecov/codecov-action@v5
84121
with:
85-
name: coverage
86-
path: coverage
122+
token: ${{ secrets.CODECOV_TOKEN }}
123+
slug: huynguyengl99/chanx

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ exclude = '''
102102
| \.vscode
103103
| __pycache__
104104
| .venv
105+
| .tox
105106
| build
106107
| coverage
107108
)/

tox.ini

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[tox]
2+
env_list = py311-django5, py312-django5, py313-django5, lint, coverage
3+
isolated_build = True
4+
5+
[gh]
6+
python =
7+
3.11 = py311-django5
8+
3.12 = py312-django5
9+
3.13 = py313-django5
10+
11+
[testenv]
12+
pass_env =
13+
POSTGRES_*
14+
REDIS_*
15+
allowlist_externals =
16+
pytest
17+
py
18+
python
19+
package = uv
20+
runner = uv-venv-runner
21+
setenv =
22+
PYTHONPATH = {toxinidir}
23+
DJANGO_SETTINGS_MODULE = config.settings.test
24+
commands =
25+
pytest {posargs:sandbox}
26+
27+
[testenv:py311-django5]
28+
extras = jwt
29+
dependency_groups = dev, test
30+
basepython = python3.11
31+
32+
[testenv:py312-django5]
33+
extras = jwt
34+
dependency_groups = dev, test
35+
basepython = python3.12
36+
37+
[testenv:py313-django5]
38+
extras = jwt
39+
dependency_groups = dev, test
40+
basepython = python3.13
41+
42+
[testenv:lint]
43+
dependency_groups = lint
44+
commands =
45+
black --check chanx
46+
ruff check chanx
47+
mypy chanx
48+
49+
[testenv:coverage]
50+
extras = jwt
51+
dependency_groups = dev, test
52+
commands =
53+
pytest --cov-report term-missing --cov-report=xml --cov=chanx sandbox
54+
55+
[pytest]
56+
DJANGO_SETTINGS_MODULE = config.settings.test
57+
filterwarnings =
58+
ignore::DeprecationWarning
59+
ignore:app_settings.USERNAME_REQUIRED is deprecated:UserWarning:dj_rest_auth.*
60+
ignore:app_settings.EMAIL_REQUIRED is deprecated:UserWarning:dj_rest_auth.*

0 commit comments

Comments
 (0)