Skip to content

Commit

Permalink
Merge pull request #8 from SkywardAI/feat/ci
Browse files Browse the repository at this point in the history
[CI]: feature/update CI
  • Loading branch information
Micost authored Mar 19, 2024
2 parents 515de15 + 7fc80fc commit d5923b4
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 88 deletions.
206 changes: 118 additions & 88 deletions .github/workflows/ci-backend.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
name: 'CI - Backend'
name: 'Backend CI/CD 🚀'
on:
workflow_dispatch:
push:
branches:
- 'feature/**'
- 'feat/**'
- 'fix/**'
pull_request:
branches:
- 'feature/**'
- 'feat/**'
- 'fix/**'

jobs:
Expand All @@ -25,9 +26,9 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Check repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
Expand All @@ -54,9 +55,9 @@ jobs:

steps:
- name: Check repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
Expand All @@ -69,110 +70,139 @@ jobs:
- name: Install Dependencies for Linting
run: |
pip install flake8
- name: Lint with Black
uses: psf/black@stable
with:
options: "--exclude=tests/"
src: "backend/src/"
- name: Lint with Isort
run: |
isort . --profile black
- name: Lint with Flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Lint with MyPy
run: |
mypy . --pretty
test:
name: 'Test 🔬'
needs: build
# test:
# name: 'Test 🔬'
# needs: build
# strategy:
# matrix:
# os:
# - ubuntu-latest
# python-version:
# - "3.11"
# defaults:
# run:
# working-directory: backend/
# services:
# postgres:
# image: postgres:14.2-alpine
# env:
# POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
# POSTGRES_USER: ${{ secrets.POSTGRES_USERNAME }}
# POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
# ports:
# - 5432:5432
# options: >-
# --health-cmd pg_isready
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
# env:
# ENVIRONMENT: ${{ secrets.ENVIRONMENT }}
# DEBUG: ${{ secrets.DEBUG }}
# POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
# POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}
# POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
# POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }}
# POSTGRES_SCHEMA: ${{ secrets.POSTGRES_SCHEMA }}
# POSTGRES_USERNAME: ${{ secrets.POSTGRES_USERNAME }}
# BACKEND_SERVER_HOST: ${{ secrets.BACKEND_SERVER_HOST }}
# BACKEND_SERVER_PORT: ${{ secrets.BACKEND_SERVER_PORT }}
# BACKEND_SERVER_WORKERS: ${{ secrets.BACKEND_SERVER_WORKERS }}
# DB_TIMEOUT: ${{ secrets.DB_TIMEOUT }}
# DB_POOL_SIZE: ${{ secrets.DB_POOL_SIZE }}
# DB_MAX_POOL_CON: ${{ secrets.DB_MAX_POOL_CON }}
# DB_POOL_OVERFLOW: ${{ secrets.DB_POOL_OVERFLOW }}
# IS_DB_ECHO_LOG: ${{ secrets.IS_DB_ECHO_LOG }}
# IS_DB_EXPIRE_ON_COMMIT: ${{ secrets.IS_DB_EXPIRE_ON_COMMIT }}
# IS_DB_FORCE_ROLLBACK: ${{ secrets.IS_DB_FORCE_ROLLBACK }}
# IS_ALLOWED_CREDENTIALS: ${{ secrets.IS_ALLOWED_CREDENTIALS }}
# API_TOKEN: ${{ secrets.API_TOKEN }}
# AUTH_TOKEN: ${{ secrets.AUTH_TOKEN }}
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }}
# JWT_SUBJECT: ${{ secrets.JWT_SUBJECT }}
# JWT_TOKEN_PREFIX: ${{ secrets.JWT_TOKEN_PREFIX }}
# JWT_ALGORITHM: ${{ secrets.JWT_ALGORITHM }}
# JWT_MIN: ${{ secrets.JWT_MIN }}
# JWT_HOUR: ${{ secrets.JWT_HOUR }}
# JWT_DAY: ${{ secrets.JWT_DAY }}
# HASHING_ALGORITHM_LAYER_1: ${{ secrets.HASHING_ALGORITHM_LAYER_1 }}
# HASHING_ALGORITHM_LAYER_2: ${{ secrets.HASHING_ALGORITHM_LAYER_2 }}
# HASHING_SALT: ${{ secrets.HASHING_SALT }}

# runs-on: ${{ matrix.os }}
# steps:
# - name: Check repository
# uses: actions/checkout@v3
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v4
# with:
# python-version: ${{ matrix.python-version }}
# cache: 'pip'
# - name: Display Python version
# run: python -c "import sys; print(sys.version)"
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
# - name: Install Dependencies for Testing
# run: |
# pip install pytest pytest-asyncio pytest pytest-xdist
# - name: Test with Pytest-Cov
# run: |
# pytest --cov --cov-report xml .
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v3
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# fail_ci_if_error: false
# flags: backend_app_tests
# name: codecov-umbrella
# verbose: true

docker_build:
name: 'Docker Build 🐳'
needs: code-quality
strategy:
matrix:
os:
os:
- ubuntu-latest
python-version:
- "3.11"
defaults:
run:
working-directory: backend/
services:
postgres:
image: postgres:14.2-alpine
env:
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_USER: ${{ secrets.POSTGRES_USERNAME }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
ENVIRONMENT: ${{ secrets.ENVIRONMENT }}
DEBUG: ${{ secrets.DEBUG }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }}
POSTGRES_SCHEMA: ${{ secrets.POSTGRES_SCHEMA }}
POSTGRES_USERNAME: ${{ secrets.POSTGRES_USERNAME }}
BACKEND_SERVER_HOST: ${{ secrets.BACKEND_SERVER_HOST }}
BACKEND_SERVER_PORT: ${{ secrets.BACKEND_SERVER_PORT }}
BACKEND_SERVER_WORKERS: ${{ secrets.BACKEND_SERVER_WORKERS }}
DB_TIMEOUT: ${{ secrets.DB_TIMEOUT }}
DB_POOL_SIZE: ${{ secrets.DB_POOL_SIZE }}
DB_MAX_POOL_CON: ${{ secrets.DB_MAX_POOL_CON }}
DB_POOL_OVERFLOW: ${{ secrets.DB_POOL_OVERFLOW }}
IS_DB_ECHO_LOG: ${{ secrets.IS_DB_ECHO_LOG }}
IS_DB_EXPIRE_ON_COMMIT: ${{ secrets.IS_DB_EXPIRE_ON_COMMIT }}
IS_DB_FORCE_ROLLBACK: ${{ secrets.IS_DB_FORCE_ROLLBACK }}
IS_ALLOWED_CREDENTIALS: ${{ secrets.IS_ALLOWED_CREDENTIALS }}
API_TOKEN: ${{ secrets.API_TOKEN }}
AUTH_TOKEN: ${{ secrets.AUTH_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }}
JWT_SUBJECT: ${{ secrets.JWT_SUBJECT }}
JWT_TOKEN_PREFIX: ${{ secrets.JWT_TOKEN_PREFIX }}
JWT_ALGORITHM: ${{ secrets.JWT_ALGORITHM }}
JWT_MIN: ${{ secrets.JWT_MIN }}
JWT_HOUR: ${{ secrets.JWT_HOUR }}
JWT_DAY: ${{ secrets.JWT_DAY }}
HASHING_ALGORITHM_LAYER_1: ${{ secrets.HASHING_ALGORITHM_LAYER_1 }}
HASHING_ALGORITHM_LAYER_2: ${{ secrets.HASHING_ALGORITHM_LAYER_2 }}
HASHING_SALT: ${{ secrets.HASHING_SALT }}

runs-on: ${{ matrix.os }}
steps:
- name: Check repository
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
python-version: '3.11'
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install Dependencies for Testing
- name: Login to Github Container Registry
uses: docker/login-action@v3
if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') && success()
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Docker image
if: startsWith(github.ref, 'refs/tags/') != true && success()
run: |
pip install pytest pytest-asyncio pytest pytest-xdist
- name: Test with Pytest-Cov
docker build -t ${{ secrets.DOCKER_REGISTRY }}/${{ secrets.IMAGE_NAME }}:${GITHUB_SHA::7} .
- name: Push Docker image
if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') && success()
run: |
pytest --cov --cov-report xml .
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
flags: backend_app_tests
name: codecov-umbrella
verbose: true
docker push ghcr.io/${{ secrets.DOCKER_REGISTRY }}/${{ secrets.IMAGE_NAME }}:${GITHUB_REF/refs\/tags\//}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,5 @@ volumes/
# Uploaded file
uploaded_files/
uploaded_files/*

.devcontainer/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
</a>
</div>

[![CI - Backend](https://github.com/SkywardAI/chat-backend/actions/workflows/ci-backend.yaml/badge.svg)](https://github.com/SkywardAI/chat-backend/actions/workflows/ci-backend.yaml)

<br>

This is a repository is the backend of the chat machine trainer websit. It's using the following tech stack:
Expand Down

0 comments on commit d5923b4

Please sign in to comment.