-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2804f64
commit f6ed45e
Showing
16 changed files
with
218 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Python Lint & Docker Build | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
pull_request: | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup python | ||
uses: actions/setup-python@v5 | ||
with: | ||
cache: 'pip' | ||
|
||
- name: Run flake8 | ||
uses: py-actions/flake8@v2 | ||
with: | ||
exclude: "app/migrations/versions/" | ||
path: "app" | ||
|
||
build: | ||
name: Build docker image | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=pr | ||
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} | ||
- name: Build and push docker image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: app | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
name: Check Migrations | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
detect-diffs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Changes in models directories | ||
id: model-changes | ||
uses: tj-actions/changed-files@v45 | ||
with: | ||
path: "app/services" | ||
files: "./*/models/**" | ||
|
||
- name: Model changes output | ||
env: | ||
CHANGED_MODEL_FILES: ${{ steps.model-changes.outputs.all_changed_files }} | ||
run: | | ||
for file in "${CHANGED_MODEL_FILES}"; do | ||
echo "$file was changed" | ||
done | ||
- name: Changes in migrations | ||
id: migration-changes | ||
uses: tj-actions/changed-files@v45 | ||
with: | ||
path: "app/alembic/versions" | ||
files: "*.py" | ||
|
||
- name: Migration changes output | ||
env: | ||
CHANGED_MIGRATION_FILES: ${{ steps.migration-changes.outputs.all_changed_files }} | ||
run: | | ||
for file in ${CHANGED_MIGRATION_FILES}; do | ||
echo "$file was changed" | ||
done | ||
outputs: | ||
changed_migration_files: ${{ steps.migration-changes.outputs.all_changed_files }} | ||
changed_model_files: ${{ steps.model-changes.outputs.all_changed_files }} | ||
|
||
|
||
prevent-changes: | ||
runs-on: ubuntu-latest | ||
needs: detect-diffs | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.base_ref }} | ||
|
||
- name: prevent-changes-to-existing-migrations | ||
run: | | ||
EXISTING_MIGRATIONS=$(git ls-tree -r HEAD --name-only | grep "app/alembic/versions/.*\.py") | ||
CHANGED_MIGRATION_FILES="${{ needs.detect-diffs.outputs.changed_migration_files }}" | ||
for changed_migration in $CHANGED_MIGRATION_FILES; do | ||
if echo $EXISTING_MIGRATIONS | grep "$changed_migration"; then | ||
echo "An already existing migration should not be edited!" | ||
exit 1 | ||
fi | ||
done | ||
check-missing-imports: | ||
runs-on: ubuntu-latest | ||
needs: detect-diffs | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Check for Missing imports in alembic | ||
id: missing-imports | ||
run: | | ||
CHANGED_MODEL_FILES="${{ needs.detect-diffs.outputs.changed_model_files }}" | ||
IMPORTS=$(grep -oP "from services\.\w+\.models\.\w+ import \w+" app/alembic/env.py) | ||
MISSING_IMPORTS=() | ||
for line in $CHANGED_MODEL_FILES; do | ||
model_name=$(basename "$line" .py) | ||
if ! echo "$IMPORTS" | grep -q "$model_name"; then | ||
MISSING_IMPORTS+=("$model_name") | ||
fi | ||
done | ||
if [ ${#MISSING_IMPORTS[@]} -ne 0 ]; then | ||
echo "You probably forget to import follwoing models within the alembic/env file: ${MISSING_IMPORTS[*]}" | ||
exit 1 | ||
fi | ||
migrations: | ||
runs-on: ubuntu-latest | ||
services: | ||
postgres: | ||
image: postgres:17 | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
env: | ||
POSTGRES_HOST: localhost | ||
POSTGRES_PORT: 5432 | ||
POSTGRES_USER: app | ||
POSTGRES_PASSWORD: app | ||
POSTGRES_DB: app | ||
ports: | ||
- "5432:5432" | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup python | ||
uses: actions/setup-python@v5 | ||
with: | ||
cache: 'pip' | ||
|
||
- name: Install requirements | ||
working-directory: ./app | ||
run: pip install -r requirements.txt | ||
|
||
- name: Create .env File | ||
working-directory: ./app | ||
run: | | ||
echo "DATABASE_HOST=localhost" >> .env | ||
- name: Run Migrations UP | ||
working-directory: ./app | ||
run: alembic upgrade head | ||
|
||
- name: Run alembic check | ||
working-directory: ./app | ||
run: | | ||
alembic check | ||
- name: Run Migrations DOWN | ||
working-directory: ./app | ||
run: alembic downgrade base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
Text, | ||
) | ||
from sqlalchemy.dialects.postgresql import UUID | ||
|
||
from utils.database.connection import Base | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
from sqlalchemy.orm import Session | ||
|
||
from utils.database.connection import SessionLocal | ||
|
||
|
||
|