Skip to content

Instantly share code, notes, and snippets.

@hnduke

hnduke/ci.yml Secret

Created September 23, 2023 19:19
Show Gist options
  • Save hnduke/4046126fb12cf6762f6525d591b69055 to your computer and use it in GitHub Desktop.
Save hnduke/4046126fb12cf6762f6525d591b69055 to your computer and use it in GitHub Desktop.
CI workflow example for a simple, one-app Django project
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | python3 -
- name: Install dependencies
run: poetry install
- name: Run isort
run: poetry run isort --check-only .
- name: Run black
run: poetry run black --check .
- name: Run flake8
run: poetry run flake8 .
- name: Run PyCQA/Bandit
run: poetry run bandit -r enterprises
- name: Setup Database
run: PGPASSWORD=postgres psql -h localhost -U postgres -c "CREATE DATABASE test_db;"
- name: Set up environment
run: |
echo "SECRET_KEY=$(poetry run python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())')" >> $GITHUB_ENV
echo "DATABASE_HOST=localhost" >> $GITHUB_ENV
echo "DATABASE_PORT=5432" >> $GITHUB_ENV
echo "DATABASE_NAME=test_db" >> $GITHUB_ENV
echo "DATABASE_USER=postgres" >> $GITHUB_ENV
echo "DATABASE_PASSWORD=postgres" >> $GITHUB_ENV
- name: Run Tests
run: poetry run pytest --cov=enterprises --cov-fail-under=90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment