Skip to content

Commit

Permalink
Merge pull request #1 from mohamedramadan14/mohamedramadan14/liniting…
Browse files Browse the repository at this point in the history
…-testing-workflow

Simple CI with liniting and testing workflow
  • Loading branch information
mohamedramadan14 authored Nov 8, 2023
2 parents f72be56 + d420d51 commit cd6cfec
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ DEV_MAILGUN_DOMAIN=
DEV_B2_KEY_ID=
DEV_B2_APPLICATION_KEY=
DEV_B2_BUCKET_NAME=

DEV_SENTRY_DSN=
36 changes: 36 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11.5
uses: actions/setup-python@v3
with:
python-version: "3.11.5"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with ruff
run: |
ruff .
- name: Test with pytest with coverage
run: |
pytest --cov=socialmedia
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ log.txt

github_profile_to_notion.txt
logtail_email.txt

.ruff_cache
.github
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ python-multipart
passlib[bcrypt]
aiofiles
b2sdk
httpx
httpx
sentry-sdk[fastapi]
resend
16 changes: 13 additions & 3 deletions socialmedia/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,31 @@ class GlobalConfig(BaseConfig):
B2_KEY_ID: Optional[str] = None
B2_APPLICATION_KEY: Optional[str] = None
B2_BUCKET_NAME: Optional[str] = None
SENTRY_DSN: Optional[str] = None


class DevConfig(GlobalConfig):
model_config = SettingsConfigDict(env_prefix="DEV_" , extra="ignore",)
model_config = SettingsConfigDict(
env_prefix="DEV_",
extra="ignore",
)


class TestConfig(GlobalConfig):
DATABASE_URL: str = "sqlite:///test.db"
DB_FORCE_ROLLBACK: bool = True
JWT_ALGORITHM: str = "HS256"
model_config = SettingsConfigDict(env_prefix="TEST_", extra="ignore",)
model_config = SettingsConfigDict(
env_prefix="TEST_",
extra="ignore",
)


class ProdConfig(GlobalConfig):
model_config = SettingsConfigDict(env_prefix="PROD_", extra="ignore",)
model_config = SettingsConfigDict(
env_prefix="PROD_",
extra="ignore",
)


def get_config(env_state: str):
Expand Down
11 changes: 10 additions & 1 deletion socialmedia/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import logging
from contextlib import asynccontextmanager

import sentry_sdk
from asgi_correlation_id import CorrelationIdMiddleware
from fastapi import FastAPI, HTTPException
from fastapi.exception_handlers import http_exception_handler

from socialmedia.config import config
from socialmedia.database import database
from socialmedia.logging_conf import configure_logging
from socialmedia.routers.post import router as post_router
from socialmedia.routers.user import router as user_router
from socialmedia.routers.upload import router as upload_router
from socialmedia.routers.user import router as user_router

sentry_sdk.init(
dsn=config.SENTRY_DSN,
traces_sample_rate=1.0,
profiles_sample_rate=1.0,
)


logger = logging.getLogger(__name__)

Expand Down

0 comments on commit cd6cfec

Please sign in to comment.