Pre-commit and Tests #4
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
name: Pre-commit and Tests | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
schedule: | |
- cron: '0 0 * * 1' # Runs every Monday at midnight | |
jobs: | |
pre-commit: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.12.3' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install poetry | |
poetry install | |
- name: Run pre-commit hooks | |
run: | | |
poetry run pre-commit run --all-files | |
tests: | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:13 | |
ports: | |
- 5432:5432 | |
env: | |
POSTGRES_DB: test_db | |
POSTGRES_USER: test_user | |
POSTGRES_PASSWORD: test_password | |
options: >- | |
--health-cmd "pg_isready -U test_user" | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.12.3' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install poetry | |
poetry install | |
- name: Wait for PostgreSQL to be ready | |
run: | | |
echo "Waiting for PostgreSQL to be ready..." | |
while ! pg_isready -h localhost -p 5432 -U test_user; do | |
sleep 1 | |
done | |
- name: Run Django tests | |
env: | |
# Django | |
EMAIL_HOST_USER: '[email protected]' | |
EMAIL_HOST_PASSWORD: 'dummypassword' | |
EMAIL_PORT: '587' | |
EMAIL_USE_TLS: 'True' | |
DEFAULT_FROM_EMAIL: '[email protected]' | |
# Database | |
DB_NAME: test_db | |
DB_USER: test_user | |
DB_PASSWORD: test_password | |
DB_HOST: localhost | |
DB_PORT: 5432 | |
# Production Database URL | |
DATABASE_URL: postgres://test_user:test_password@localhost:5432/test_db | |
# Frontend URL | |
FRONTEND_URL: 'https://dummy-frontend.example.com' | |
# AWS S3 Configuration | |
AWS_ACCESS_KEY_ID: 'DUMMYACCESSKEYID' | |
AWS_SECRET_ACCESS_KEY: 'DUMMYSECRETACCESSKEY' | |
AWS_STORAGE_BUCKET_NAME: 'dummy-bucket' | |
AWS_S3_REGION_NAME: 'us-east-1' | |
# Django Configuration | |
DEBUG: 'False' | |
run: | | |
poetry run python manage.py test |