ci: Added build, Code coverage and security workflows

This commit is contained in:
2026-07-03 08:38:38 +05:30
parent 8488e3bdd0
commit 9e1a5f83d4
6 changed files with 1148 additions and 1 deletions

76
.github/workflows/docker.yml vendored Normal file
View File

@@ -0,0 +1,76 @@
name: Docker CI
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
env:
REGISTRY: ghcr.io
IMAGE_NAME_WEB: ghcr.io/${{ github.repository }}/web
IMAGE_NAME_WORKER: ghcr.io/${{ github.repository }}/worker
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
if: github.event_name == 'push'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Web
id: meta-web
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME_WEB }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,format=short
latest
- name: Build and Push Web Image
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name == 'push' }}
tags: ${{ steps.meta-web.outputs.tags }}
labels: ${{ steps.meta-web.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Extract metadata (tags, labels) for Worker
id: meta-worker
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME_WORKER }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,format=short
latest
- name: Build and Push Worker Image
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name == 'push' }}
tags: ${{ steps.meta-worker.outputs.tags }}
labels: ${{ steps.meta-worker.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

57
.github/workflows/security.yml vendored Normal file
View File

@@ -0,0 +1,57 @@
name: Security Scanning
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
bandit:
name: Run Bandit (SAST)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
python-version: "3.14"
- name: Run Bandit
run: uvx bandit -r app/ -ll -ii
pip-audit:
name: Dependency Audit
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
python-version: "3.14"
- name: Compile requirements
run: uv pip compile pyproject.toml -o requirements.txt
- name: Run pip-audit
run: uvx pip-audit -r requirements.txt
gitleaks:
name: Secret Scanning
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run Gitleaks
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

60
.github/workflows/tests.yml vendored Normal file
View File

@@ -0,0 +1,60 @@
name: Run Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: alemno_test_db
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
python-version: "3.14"
- name: Run Tests with Coverage
env:
DATABASE_URL: postgresql+asyncpg://postgres:postgres@localhost:5432/alemno_test_db
REDIS_URL: redis://localhost:6379/0
TESTING: "True"
run: |
uv run pytest --cov=app --cov-report=xml --cov-report=term-missing -v
- name: Upload Coverage Report
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: coverage.xml