Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/_reusable_quality_check_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Reusable quality check:
# - black: Code format
# - pylint: Code quality
# - bandit: Security linting
name: Reusable Quality Check Workflow

# Workflow runs on being called by others
on:
workflow_call:
inputs:
working-directory:
required: true
type: string
python-version:
required: false
type: string
default: "3.10"
linting-threshold:
required: false
type: number
default: 8.0

jobs:
quality-check:
name: Code Quality and Security Check
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Install dependencies
working-directory: ${{ inputs.working-directory }}
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt

- name: Format check with Black
working-directory: ${{ inputs.working-directory }}
run: |
black --check app/ tests/

- name: Lint with Pylint
working-directory: ${{ inputs.working-directory }}
run: |
pylint app/ --fail-under=${{ inputs.linting-threshold }}

- name: Security scan with Bandit
working-directory: ${{ inputs.working-directory }}
run: |
bandit -r app/ -ll
119 changes: 119 additions & 0 deletions .github/workflows/_reusable_test_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Reusable test workflow
# - pytest: run all defined test files in tests/
# - pytest-cov: test coverage
name: Reusable Test Workflow

# Workflow runs on being called by others
on:
workflow_call:
inputs:
working-directory:
required: true
type: string
python-version:
required: false
type: string
default: "3.10"
coverage-threshold:
required: false
type: number
default: 80

env:
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_db

jobs:
unit-test:
name: Run Unit Testing (schemas, basic logic)
runs-on: ubuntu-latest

services:
postgres:
image: postgres:15
env:
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ env.POSTGRES_DB }}
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Install dependencies
working-directory: ${{ inputs.working-directory }}
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt

- name: Run unit tests
working-directory: ${{ inputs.working-directory }}
run: |
pytest tests/unit/ -v

integration-test:
name: Run Integration Testing (API + database)
runs-on: ubuntu-latest
needs: unit-test

services:
postgres:
image: postgres:15
env:
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ env.POSTGRES_DB }}
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Install dependencies
working-directory: ${{ inputs.working-directory }}
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt

- name: Run tests
working-directory: ${{ inputs.working-directory }}
env:
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ env.POSTGRES_DB }}
POSTGRES_HOST: ${{ env.POSTGRES_HOST }}
POSTGRES_PORT: 5432
run: |
pytest tests/integration/ -v --cov=app --cov-report=xml --cov-report=term-missing

- name: Check coverage
working-directory: ${{ inputs.working-directory }}
run: |
coverage report --fail-under=${{ inputs.coverage-threshold }}
36 changes: 36 additions & 0 deletions .github/workflows/feature_test_notes_service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Feature Branch CI - Note Service

on:
# Manual trigger
workflow_dispatch:

# Workflow runs on any changes on Note Services, commited on feature or fix branches
push:
branches:
- "feature/**"
- "fix/**"
paths:
- "backend/notes_service/**"
- ".github/workflows/*notes_service*.yml"

# Re-run the test when the new PR to develop is created
pull_request:
branches:
- "develop"

jobs:
quality-checks:
name: Quality Check for Notes Service
uses: ./.github/workflows/_reusable_quality_check_workflow.yml
secrets: inherit
with:
working-directory: "./backend/notes_service"
linting-threshold: 8.0

test:
name: Run Tests for Notes Service
uses: ./.github/workflows/_reusable_test_workflow.yml
secrets: inherit
with:
working-directory: "./backend/notes_service"
coverage-threshold: 80
Loading