Skip to content

Commit e3dbabf

Browse files
authored
add: Github workflows (#11)
1 parent c53384f commit e3dbabf

8 files changed

Lines changed: 136 additions & 22 deletions

File tree

.github/workflows/check.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Lint & Test
2+
3+
on: [push]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- name: Install uv
11+
uses: astral-sh/setup-uv@v5
12+
- name: "Set up Python"
13+
uses: actions/setup-python@v5
14+
with:
15+
python-version-file: "pyproject.toml"
16+
- name: Install the project
17+
run: uv sync --all-extras --dev
18+
- name: Lint with Ruff
19+
run: uv run ruff check .
20+
- name: Run tests
21+
run: uv run pytest tests -s -v

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ lint:
1212
uv run ruff check . --fix --unsafe-fixes
1313

1414
test:
15-
uv run pytest tests -s
15+
uv run pytest tests -s -v
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Lint & Test
2+
3+
on: [push]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- name: Install uv
11+
uses: astral-sh/setup-uv@v5
12+
- name: "Set up Python"
13+
uses: actions/setup-python@v5
14+
with:
15+
python-version-file: "pyproject.toml"
16+
- name: Install the project
17+
run: uv sync --all-extras --dev
18+
- name: Lint with Ruff
19+
run: uv run ruff check .
20+
{%- if cookiecutter.use_postgres %}
21+
test:
22+
runs-on: ubuntu-latest
23+
services:
24+
postgres:
25+
image: postgres:13.8-bullseye
26+
env:
27+
POSTGRES_PASSWORD: postgres
28+
POSTGRES_USER: postgres
29+
POSTGRES_DB: postgres
30+
ports:
31+
- 5432
32+
options: >-
33+
--health-cmd "pg_isready"
34+
--health-interval 10s
35+
--health-timeout 5s
36+
--health-retries 5
37+
steps:
38+
- uses: actions/checkout@v4
39+
- name: Install uv
40+
uses: astral-sh/setup-uv@v5
41+
- name: "Set up Python"
42+
uses: actions/setup-python@v5
43+
with:
44+
python-version-file: "pyproject.toml"
45+
- name: Install the project
46+
run: uv sync --all-extras --dev
47+
- name: Run tests
48+
env:
49+
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_HOST: localhost
50+
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_PORT: {% raw %}${{ job.services.postgres.ports['5432'] }}{% endraw %}
51+
run: uv run pytest ./tests -v -s
52+
{%- endif %}

fastapi_forge/template/{{cookiecutter.project_name}}/docker-compose.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
services:
2-
32
api:
43
build:
54
context: .
@@ -23,11 +22,13 @@ services:
2322
{{ cookiecutter.project_name|upper|replace('-', '_') }}_RELOAD: "True"
2423
{{ cookiecutter.project_name|upper|replace('-', '_') }}_SERVER_HOST: 0.0.0.0
2524
{{ cookiecutter.project_name|upper|replace('-', '_') }}_SERVER_PORT: 8000
25+
{%- if cookiecutter.use_postgres %}
2626
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_HOST: {{ cookiecutter.project_name }}-pg
2727
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_PORT: 5432
2828
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_USER: {{ cookiecutter.project_name }}
2929
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_PASS: {{ cookiecutter.project_name }}
3030
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_DATABASE: {{ cookiecutter.project_name }}
31+
{% endif %}
3132
{%- if cookiecutter.use_redis %}
3233
{{ cookiecutter.project_name|upper|replace('-', '_') }}_REDIS_HOST: "redis"
3334
{{ cookiecutter.project_name|upper|replace('-', '_') }}_REDIS_PORT: 6379

fastapi_forge/template/{{cookiecutter.project_name}}/pyproject.toml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
[project]
2-
name = "{{cookiecutter.project_name}}"
3-
version = "0.1.0"
4-
description = "Add your description here"
5-
readme = "README.md"
6-
requires-python = ">=3.12"
72
dependencies = [
83
"fastapi>=0.115.8",
94
"uvicorn>=0.34.0",
@@ -24,7 +19,7 @@ dependencies = [
2419
{% endif %}
2520
{%- if cookiecutter.use_alembic -%}
2621
"alembic>=1.14.1",
27-
{% endif %}
22+
{%- endif %}
2823
"pytest>=8.3.4",
2924
"pytest-env>=1.1.5",
3025
"httpx==0.28.1",
@@ -34,17 +29,26 @@ dependencies = [
3429
{% endif %}
3530
{%- if cookiecutter.use_rabbitmq -%}
3631
"aio-pika>=9.5.5",
37-
{% endif %}
38-
]
32+
{%- endif %}
33+
]name = "{{cookiecutter.project_name}}"
34+
version = "0.1.0"
35+
description = "Add your description here"
36+
readme = "README.md"
37+
requires-python = ">=3.12"
3938

4039
[tool.pytest.ini_options]
41-
env = ["{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_DATABASE=test", "{{ cookiecutter.project_name|upper|replace('-', '_') }}_ENV=test"]
40+
env = [
41+
"{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_DATABASE=test",
42+
"{{ cookiecutter.project_name|upper|replace('-', '_') }}_ENV=test",
43+
]
4244

4345
[tool.ruff]
4446
exclude = ["migrations"]
4547
target-version = "py312"
4648
line-length = 88
4749
indent-width = 4
50+
51+
[tool.ruff.lint]
4852
select = ["ALL"]
4953
ignore = [
5054
#### modules
@@ -59,8 +63,8 @@ ignore = [
5963
#### specific rules
6064
"A001",
6165
"A002",
62-
"BLE001",
6366
"B904",
67+
"BLE001",
6468
"D100",
6569
"D101",
6670
"D102",
@@ -70,6 +74,7 @@ ignore = [
7074
"D106",
7175
"D107",
7276
"D200",
77+
"D203",
7378
"D205",
7479
"D212",
7580
"D400",
@@ -106,3 +111,4 @@ line-ending = "auto"
106111

107112
[tool.ruff.lint.per-file-ignores]
108113
"tests/*" = ["S101", "PT006"]
114+
"__init__.py" = ["F401"]

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description = "Generate FastAPI projects based on database schema."
88
readme = "README.md"
99
requires-python = ">=3.12"
1010
dynamic = ["version"]
11-
dependencies = ["click", "nicegui", "cookiecutter", "pytest"]
11+
dependencies = ["click", "nicegui", "cookiecutter", "pytest", "ruff"]
1212
authors = [{ name = "mslaursen", email = "mslaursendk@gmail.com" }]
1313

1414
[project.urls]
@@ -24,6 +24,8 @@ exclude = ["template", "__init__.py"]
2424
target-version = "py312"
2525
line-length = 88
2626
indent-width = 4
27+
28+
[tool.ruff.lint]
2729
select = ["ALL"]
2830
ignore = [
2931
#### modules
@@ -47,6 +49,7 @@ ignore = [
4749
"D106",
4850
"D107",
4951
"D200",
52+
"D203",
5053
"D205",
5154
"D212",
5255
"D400",
@@ -78,7 +81,7 @@ line-ending = "auto"
7881

7982
[tool.ruff.lint.per-file-ignores]
8083
"tests/*" = ["S101", "PT006"]
84+
"__init__.py" = ["F401"]
8185

8286
[tool.pytest]
8387
testpaths = ["tests", "integration"]
84-
"__init__.py" = ["F401"]

tests/test_dtos.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ def test_invalid_field_name(invalid_name: str) -> None:
5858
[
5959
(FieldDataType.STRING, 'factory.Faker("text")'),
6060
(FieldDataType.INTEGER, 'factory.Faker("random_int")'),
61-
(FieldDataType.FLOAT, 'factory.Faker("random_float")'),
61+
(
62+
FieldDataType.FLOAT,
63+
'factory.Faker("pyfloat", positive=True, min_value=0.1, max_value=100)',
64+
),
6265
(FieldDataType.BOOLEAN, 'factory.Faker("boolean")'),
6366
(FieldDataType.DATETIME, 'factory.Faker("date_time")'),
6467
(FieldDataType.UUID, None),

uv.lock

Lines changed: 35 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)