Skip to content

Commit 2a0fde8

Browse files
committed
Add CI tests for fastapi project
1 parent 54ab7aa commit 2a0fde8

File tree

3 files changed

+178
-0
lines changed

3 files changed

+178
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Testing FastAPI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
env:
8+
CARGO_TERM_COLOR: always
9+
RUST_BACKTRACE: 1
10+
RUSTFLAGS: "-D warnings"
11+
WORKING_DIR: "my-project"
12+
MIN_PYTHON_VERSION: "3.11"
13+
SECRET_KEY: someKey
14+
FIRST_SUPERUSER_EMAIL: [email protected]
15+
FIRST_SUPERUSER_PASSWORD: My_password1
16+
FIRST_SUPERUSER_NAME: "Wade Watts"
17+
POSTGRES_HOST: 127.0.0.1
18+
POSTGRES_PORT: 5432
19+
POSTGRES_USER: postgres
20+
POSTGRES_PASSWORD: test_password
21+
POSTGRES_DB: test_db
22+
VALKEY_HOST: 127.0.0.1
23+
VALKEY_PASSWORD: test_password
24+
STACK_NAME: test-stack
25+
DOMAIN: 127.0.0.1
26+
PRODUCTION_MODE: false
27+
DATABASE_URL: postgresql://postgres:[email protected]:5432/test_db
28+
jobs:
29+
test:
30+
name: Tests
31+
strategy:
32+
fail-fast: false
33+
steps:
34+
- uses: actions/checkout@v5
35+
- name: install Rust
36+
uses: dtolnay/rust-toolchain@stable
37+
- name: Cache dependencies
38+
uses: Swatinem/[email protected]
39+
- name: Install uv
40+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
41+
- name: Set up Python
42+
uses: actions/setup-python@v6
43+
with:
44+
python-version: ${ env.MIN_PYTHON_VERSION }
45+
- name: Build package
46+
run: cargo build --release -F fastapi
47+
- name: Run creation
48+
run: ./scripts/ci_run_fastapi.sh
49+
shell: bash
50+
- name: Install Dependencies
51+
working-directory: ${{ env.WORKING_DIR }}
52+
run: |
53+
uv lock
54+
uv sync --frozen
55+
- name: Pre-commit check
56+
working-directory: ${{ env.WORKING_DIR }}
57+
run: |
58+
uv run pre-commit install
59+
git add .
60+
uv run pre-commit run --all-files
61+
- name: Build and start Docker containers
62+
working-directory: ${{ env.WORKING_DIR }}
63+
run: docker compose up -d
64+
- name: Test with pytest
65+
working-directory: ${{ env.WORKING_DIR }}
66+
run: uv run pytest -n auto

scripts/ci_run_fastapi.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
3+
project_name="My Project"
4+
project_slug=""
5+
source_dir=""
6+
project_description="Test Project"
7+
creator="Arthur Dent"
8+
creator_email="[email protected]"
9+
license="1"
10+
fastapi_project="1"
11+
copyright_year=""
12+
version=""
13+
python_version=""
14+
min_python_version=""
15+
gha_versions=""
16+
application=""
17+
project_manager="1"
18+
19+
# Check for user provided project manager input
20+
if [ $# -gt 1 ]; then
21+
if [ $2 -lt 1 ] || [ $2 -gt 5 ]; then
22+
echo "Invalid project_manager value"
23+
exit 1
24+
else
25+
project_manager=$2
26+
fi
27+
fi
28+
29+
# Check for user provided application input
30+
if [ $# -gt 0 ]; then
31+
if [ $1 = "application" ]; then
32+
application="1"
33+
elif [ $1 = "lib" ]; then
34+
application="2"
35+
else
36+
echo "Invalid application value"
37+
exit 1
38+
fi
39+
fi
40+
41+
database_manager=""
42+
max_line_length=""
43+
use_dependabot=""
44+
use_continuous_deployment=""
45+
use_release_drafter=""
46+
pyo3_python_manager=""
47+
48+
if [[ project_manager -eq 3 ]]; then
49+
./target/release/python-project create -s << EOF
50+
$project_name
51+
$project_slug
52+
$source_dir
53+
$project_description
54+
$creator
55+
$creator_email
56+
$license
57+
$copyright_year
58+
$version
59+
$python_version
60+
$min_python_version
61+
$gha_versions
62+
$project_manager
63+
$pyo3_python_manager
64+
$application
65+
$max_line_length
66+
$use_dependabot
67+
$use_continuous_deployment
68+
$use_release_drafter
69+
EOF
70+
else
71+
./target/release/python-project create -s << EOF
72+
$project_name
73+
$project_slug
74+
$source_dir
75+
$project_description
76+
$creator
77+
$creator_email
78+
$license
79+
$copyright_year
80+
$version
81+
$fastapi_project
82+
$python_version
83+
$min_python_version
84+
$gha_versions
85+
$project_manager
86+
$application
87+
$database_manager
88+
$max_line_length
89+
$use_dependabot
90+
$use_continuous_deployment
91+
$use_release_drafter
92+
EOF
93+
fi
94+
95+
if [ ! -d $project_slug ]; then
96+
echo "Directory not created"
97+
exit 1
98+
fi

src/project_info.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,20 @@ pub fn get_project_info(use_defaults: bool) -> Result<ProjectInfo> {
813813
true,
814814
use_defaults,
815815
)?;
816+
817+
#[cfg(feature = "fastapi")]
818+
let use_multi_os_ci = if is_fastapi_project {
819+
false
820+
} else {
821+
default_or_prompt_bool(
822+
"Use Multi OS CI\n 1 - Yes\n 2 - No\n Choose from [1, 2]".to_string(),
823+
config.use_multi_os_ci,
824+
true,
825+
use_defaults,
826+
)?
827+
};
828+
829+
#[cfg(not(feature = "fastapi"))]
816830
let use_multi_os_ci = default_or_prompt_bool(
817831
"Use Multi OS CI\n 1 - Yes\n 2 - No\n Choose from [1, 2]".to_string(),
818832
config.use_multi_os_ci,

0 commit comments

Comments
 (0)