Skip to content

Commit 48f38f6

Browse files
authored
Github: CI (#74)
* issue CI * first stab at continuous integration * fixing testcases and migrations * syncing with master * moving to python version 3.11.7 * making copy of env * updating env * added migrations * added uv sync * updating working directory * added step to activate env * updating working directory * updating working directory for codecov upload * updating script to upload to codecov * remove working directory * added working directory for % check * clenaup * cleanup * activating env * update the issue template * update readme and env file
1 parent 90c9b68 commit 48f38f6

File tree

5 files changed

+103
-12
lines changed

5 files changed

+103
-12
lines changed
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
# Domain
2+
23
# This would be set to the production domain with an env var on deployment
4+
35
# used by Traefik to transmit traffic and aqcuire TLS certificates
6+
47
DOMAIN=localhost
8+
59
# To test the local Traefik config
10+
611
# DOMAIN=localhost.tiangolo.com
712

813
# Used by the backend to generate links in emails to the frontend
14+
915
FRONTEND_HOST=http://localhost:5173
16+
1017
# In staging and production, set this env var to the frontend host, e.g.
18+
1119
# FRONTEND_HOST=https://dashboard.example.com
1220

1321
# Environment: local, staging, production
14-
ENVIRONMENT=local
1522

23+
ENVIRONMENT=local
1624

1725
PROJECT_NAME="AI Platform"
1826
STACK_NAME=ai-platform
1927

2028
# Backend
29+
2130
BACKEND_CORS_ORIGINS="http://localhost:5173"
2231
SECRET_KEY=changethis
2332
FIRST_SUPERUSER=[email protected]
2433
FIRST_SUPERUSER_PASSWORD=changethis
2534

2635
# Emails
36+
2737
SMTP_HOST=
2838
SMTP_USER=
2939
SMTP_PASSWORD=
@@ -33,14 +43,19 @@ SMTP_SSL=False
3343
SMTP_PORT=587
3444

3545
# Postgres
46+
3647
POSTGRES_SERVER=localhost
3748
POSTGRES_PORT=5432
38-
POSTGRES_DB=app
49+
POSTGRES_DB=ai_platform
3950
POSTGRES_USER=postgres
40-
POSTGRES_PASSWORD=changethis
51+
POSTGRES_PASSWORD=postgres
4152

4253
SENTRY_DSN=
4354

4455
# Configure these with your own Docker registry images
56+
4557
DOCKER_IMAGE_BACKEND=backend
46-
DOCKER_IMAGE_FRONTEND=frontend
58+
DOCKER_IMAGE_FRONTEND=frontend
59+
60+
CI=""
61+
OPENAI_API_KEY="this_is_not_a_secret"

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
## Summary
22

33
Target issue is #_PLEASE_TYPE_ISSUE_NUMBER_
4-
Explain the **motivation** for making this change. What existing problem does the pull request solve?
4+
Explain the **motivation** for making this change. What existing problem does the pull request solve?
55

66
## Checklist
77

88
Before submitting a pull request, please ensure that you mark these task.
99

10-
- [ ] Ran `poetry run uvicorn src.app.main:app --reload` in the repository root and test.
10+
- [ ] Ran `fastapi run --reload app/main.py` or `docker compose up` in the repository root and test.
1111
- [ ] If you've fixed a bug or added code that is tested and has test cases.
1212

1313
## Notes
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: AI Platform CI
2+
3+
on:
4+
push:
5+
branches: [staging]
6+
pull_request:
7+
branches: [staging]
8+
9+
jobs:
10+
checks:
11+
runs-on: ubuntu-latest
12+
services:
13+
postgres:
14+
image: postgres:16
15+
env:
16+
POSTGRES_USER: postgres
17+
POSTGRES_PASSWORD: postgres
18+
POSTGRES_DB: ai_platform
19+
ports:
20+
- 5432:5432
21+
options: --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5
22+
23+
strategy:
24+
matrix:
25+
python-version: ["3.11.7"]
26+
redis-version: [6]
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Set up Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@v4
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
36+
- name: Making env file
37+
run: cp .env.example .env
38+
39+
- name: Install uv
40+
uses: astral-sh/setup-uv@v5
41+
with:
42+
version: "0.4.15"
43+
enable-cache: true
44+
45+
- name: Install dependencies
46+
run: uv sync
47+
working-directory: backend
48+
49+
- name: Activate virtual environment and run Alembic migrations
50+
run: |
51+
source .venv/bin/activate
52+
alembic upgrade head
53+
working-directory: backend
54+
55+
- name: Run tests
56+
run: uv run bash scripts/tests-start.sh "Coverage for ${{ github.sha }}"
57+
working-directory: backend
58+
59+
- name: Upload coverage reports to codecov
60+
uses: codecov/codecov-action@v5
61+
with:
62+
token: ${{ secrets.CODECOV_TOKEN }}
63+
fail_ci_if_error: true
64+
65+
- name: Check coverage percentage
66+
run: |
67+
source .venv/bin/activate
68+
coverage report --fail-under=70
69+
working-directory: backend

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You can **just fork or clone** this repository and use it as is.
1616
Create env file using example file
1717

1818
```bash
19-
cp envSample .env
19+
cp .env.example .env
2020
```
2121

2222
You can then update configs in the `.env` files to customize your configurations.
@@ -26,7 +26,8 @@ Before deploying it, make sure you change at least the values for:
2626
- `SECRET_KEY`
2727
- `FIRST_SUPERUSER_PASSWORD`
2828
- `POSTGRES_PASSWORD`
29-
```bash
29+
30+
````bash
3031

3132
### Generate Secret Keys
3233

@@ -36,7 +37,7 @@ You have to change them with a secret key, to generate secret keys you can run t
3637

3738
```bash
3839
python -c "import secrets; print(secrets.token_urlsafe(32))"
39-
```
40+
````
4041
4142
Copy the content and use that as password / secret key. And run that again to generate another secure key.
4243
@@ -62,7 +63,6 @@ or by visiting: http://[your-domain]:8000/api/v1/utils/health-check/ in the brow
6263

6364
Backend docs: [backend/README.md](./backend/README.md).
6465

65-
6666
## Deployment
6767

6868
Deployment docs: [deployment.md](./deployment.md).

backend/scripts/test.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
#!/usr/bin/env bash
2-
1+
#!/bin/bash
32
set -e
43
set -x
54

5+
# Run tests with coverage tracking
66
coverage run --source=app -m pytest
7+
8+
# Generate a human-readable coverage report in the terminal
79
coverage report --show-missing
10+
11+
# Generate an HTML report for local viewing
812
coverage html --title "${@-coverage}"
13+
14+
# Generate the XML report for Codecov
15+
coverage xml

0 commit comments

Comments
 (0)