Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Python 3.11 and 3.12 GH Action Testing #95

Merged
merged 26 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
10f28ce
Merge pull request #69 from esnet-security/develop
crankynetman Nov 11, 2024
eb47978
Create staticfiles directory
grigorescu Nov 25, 2024
566144d
Merge branch 'develop' into topic/vlad/fix_static_files_warning
grigorescu Nov 25, 2024
ba2c6aa
Dump docker logs on failure
grigorescu Nov 25, 2024
0f1a19e
Add some additional debugging
grigorescu Nov 25, 2024
1b43fa4
Django container was failing to make the directory
grigorescu Nov 25, 2024
41a9ce1
Merge branch 'develop' into topic/vlad/fix_static_files_warning
grigorescu Nov 25, 2024
aacb685
Try running on Python 3.11 as well; expecting a failure.
grigorescu Nov 25, 2024
3bd52b6
Add per-version DB to migrations as well
grigorescu Nov 25, 2024
60c09fa
Provide default value for USE_DOCKER
grigorescu Nov 25, 2024
1ab1fe1
Fail if we can't apply migrations
grigorescu Nov 25, 2024
735d90f
Fix syntax of env
grigorescu Nov 25, 2024
a4961fb
Simplify migration logic
grigorescu Nov 25, 2024
bbb9e2e
Fix duplicate migration check
grigorescu Nov 25, 2024
e976033
Turn Python/Postgres versions into variables
grigorescu Nov 25, 2024
b477f18
Try passing a Python version to behave
grigorescu Nov 25, 2024
6667573
Now try 2 Python versions to behave
grigorescu Nov 25, 2024
425d031
Only upload coverage for the latest version
grigorescu Nov 25, 2024
f270bab
Pass vars through to the build command
grigorescu Nov 25, 2024
f0b0c43
Fix Dockerfile args
grigorescu Nov 25, 2024
1f6021d
The variable was set in the Makefile, but set as an empty string
grigorescu Nov 26, 2024
7363da8
Add a behave test for the next version of Python (expected to fail)
grigorescu Nov 26, 2024
2ab3376
Bump pyscopg2 to support Python 3.13
grigorescu Nov 26, 2024
c560d90
Try to allow failing test to move forward
grigorescu Nov 26, 2024
8d3ec24
Provide better name for behave
grigorescu Nov 26, 2024
0720e47
Merge branch 'develop' into topic/vlad/build_matrix
grigorescu Dec 7, 2024
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
40 changes: 24 additions & 16 deletions .github/workflows/behave.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,71 @@ jobs:
behave:
name: Run Behave
runs-on: ubuntu-latest

services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: scram
POSTGRES_PASSWORD: ''
POSTGRES_DB: test_scram
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U scram"
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
max-parallel: 4
matrix:
python-version: ['3.11', '3.12']

steps:
- name: Check out the code
uses: actions/checkout@v4

- name: Set up Docker
uses: docker/setup-buildx-action@v3

- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose make

- name: Check Docker state (pre-build)
run: docker ps

- name: Build Docker images
run: make build
env:
PYTHON_IMAGE_VER: "${{ matrix.python-version }}"

- name: Migrate Database
run: make migrate

- name: Run Application
run: make run

- name: Check Docker state (pre-test)
run: docker ps

- name: Run pytest + behave with Coverage
samoehlert marked this conversation as resolved.
Show resolved Hide resolved
env:
POSTGRES_USER: scram
POSTGRES_DB: test_scram
run: make coverage.xml

- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v2

- name: Upload Coverage to Coveralls
if: matrix.python-version == '3.12'
uses: coverallsapp/github-action@v2

- name: Upload Coverage to GitHub
if: matrix.python-version == '3.12'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.xml

- name: Display Coverage Metrics
if: matrix.python-version == '3.12'
samoehlert marked this conversation as resolved.
Show resolved Hide resolved
uses: 5monkeys/cobertura-action@v14
with:
minimum_coverage: '50'

- name: Check Docker state (post-test)
if: always()
run: docker ps

- name: Stop Services
if: always()
run: make stop
Expand Down
77 changes: 77 additions & 0 deletions .github/workflows/behave_next_python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
name: Run behave with unsupported Python versions

on:
push:
branches:
- '**'
pull_request:
branches:
- main
- develop

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
behave_next_python:
name: Run Behave
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: ['3.13']

steps:
- name: Check out the code
uses: actions/checkout@v4

- name: Set up Docker
uses: docker/setup-buildx-action@v3

- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose make

- name: Check Docker state (pre-build)
run: docker ps

- name: Build Docker images
run: make build
env:
PYTHON_IMAGE_VER: "${{ matrix.python-version }}"

- name: Migrate Database
run: |
make migrate || echo "::warning:: migrate failed on future Python version ${{ matrix.python-version }}."
samoehlert marked this conversation as resolved.
Show resolved Hide resolved

- name: Run Application
run: |
make run || echo "::warning:: run failed on future Python version ${{ matrix.python-version }}."

- name: Check Docker state (pre-test)
run: docker ps

- name: Run pytest + behave with Coverage
env:
POSTGRES_USER: scram
POSTGRES_DB: test_scram
run: |
make coverage.xml || echo "::warning:: pytest + behave failed on future Python version ${{ matrix.python-version }}."

- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v2

- name: Check Docker state (post-test)
if: always()
run: docker ps

- name: Stop Services
if: always()
run: make stop

- name: Clean Up
if: always()
run: make clean
25 changes: 10 additions & 15 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ['3.12']
python-version: ['3.11', '3.12']

services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: scram
POSTGRES_PASSWORD: ''
POSTGRES_DB: test_scram
POSTGRES_DB: test_scram_${{ matrix.python-version }}
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
Expand Down Expand Up @@ -57,30 +57,25 @@ jobs:
pip install -r requirements/local.txt
pip install pytest-github-actions-annotate-failures

- name: Apply unapplied migrations
- name: Apply migrations
env:
DATABASE_URL: "postgres://scram:@localhost:5432/test_scram"
DATABASE_URL: "postgres://scram:@localhost:5432/test_scram_${{ matrix.python-version }}"
run: |
python manage.py makemigrations --noinput || true
UNAPPLIED_MIGRATIONS=$(python manage.py showmigrations --plan | grep '\[ \]' | awk '{print $2}')
if [ -n "$UNAPPLIED_MIGRATIONS" ]; then
for migration in $UNAPPLIED_MIGRATIONS; do
python manage.py migrate $migration --fake-initial --noinput
done
else
echo "No unapplied migrations."
fi
python manage.py makemigrations --noinput
samoehlert marked this conversation as resolved.
Show resolved Hide resolved
python manage.py migrate --noinput

- name: Check for duplicate migrations
env:
DATABASE_URL: "postgres://scram:@localhost:5432/test_scram_${{ matrix.python-version }}"
run: |
if python manage.py makemigrations --dry-run | grep "No changes detected"; then
echo "No duplicate migrations detected."
else
echo "Warning: Potential duplicate migrations detected. Please review."
echo "::warning:: Potential duplicate migrations detected. Please review."
fi

- name: Run Pytest
env:
DATABASE_URL: "postgres://scram:@localhost:5432/test_scram"
DATABASE_URL: "postgres://scram:@localhost:5432/test_scram_${{ matrix.python-version }}"
REDIS_HOST: "localhost"
run: pytest
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
workflow_dispatch:

jobs:
pytest:
pytest_next_python:
name: Run Pytest
runs-on: ubuntu-latest
strategy:
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# It'd be nice to keep these in sync with the defaults of the Dockerfiles
samoehlert marked this conversation as resolved.
Show resolved Hide resolved
PYTHON_IMAGE_VER ?= 3.12
POSTGRES_IMAGE_VER ?= 12.3

.DEFAULT_GOAL := help

## toggle-prod: configure make to use the production stack
Expand Down Expand Up @@ -37,7 +41,8 @@ behave-translator: compose.override.yml
## build: rebuilds all your containers or a single one if CONTAINER is specified
.Phony: build
build: compose.override.yml
@docker compose up -d --no-deps --build $(CONTAINER)
@docker compose build --build-arg PYTHON_IMAGE_VER=$(PYTHON_IMAGE_VER) --build-arg POSTGRES_IMAGE_VER=$(POSTGRES_IMAGE_VER) $(CONTAINER)
@docker compose up -d --no-deps $(CONTAINER)
@docker compose restart $(CONTAINER)

## coverage.xml: generate coverage from test runs
Expand Down
4 changes: 3 additions & 1 deletion compose/local/django/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM python:3.12-slim-bookworm
ARG PYTHON_IMAGE_VER=3.12

FROM python:${PYTHON_IMAGE_VER}-slim-bookworm

ENV PIP_ROOT_USER_ACTION ignore
ENV PYTHONUNBUFFERED 1
Expand Down
1 change: 1 addition & 0 deletions compose/local/django/start
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ set -o errexit
set -o pipefail
set -o nounset

mkdir -p /app/staticfiles
python manage.py migrate
uvicorn config.asgi:application --host 0.0.0.0 --reload
4 changes: 3 additions & 1 deletion compose/local/docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM python:3.12-slim-bookworm
ARG PYTHON_IMAGE_VER=3.12

FROM python:${PYTHON_IMAGE_VER}-slim-bookworm

samoehlert marked this conversation as resolved.
Show resolved Hide resolved
ENV PIP_ROOT_USER_ACTION ignore
ENV PYTHONUNBUFFERED 1
Expand Down
3 changes: 2 additions & 1 deletion compose/production/django/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ARG PYTHON_IMAGE_VER=3.12

FROM python:3.12-slim-bookwork
FROM python:${PYTHON_IMAGE_VER}-slim-bookworm

ENV PYTHONUNBUFFERED 1

Expand Down
4 changes: 3 additions & 1 deletion compose/production/postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM postgres:12.3
ARG POSTGRES_IMAGE_VER=12.3

FROM postgres:${POSTGRES_IMAGE_VER}

COPY ./compose/production/postgres/maintenance /usr/local/bin/maintenance
RUN chmod +x /usr/local/bin/maintenance/*
Expand Down
2 changes: 1 addition & 1 deletion config/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
}
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#internal-ips
INTERNAL_IPS = ["127.0.0.1", "10.0.2.2"]
if env("USE_DOCKER") == "yes":
if env("USE_DOCKER", default="no") == "yes":
import socket

hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
Expand Down
2 changes: 1 addition & 1 deletion requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Werkzeug[watchdog]==2.0.3 # https://github.com/pallets/werkzeug
ipdb==0.13.9 # https://github.com/gotcha/ipdb
psycopg2-binary==2.9.3 # https://github.com/psycopg/psycopg2
psycopg2-binary==2.9.10 # https://github.com/psycopg/psycopg2
samoehlert marked this conversation as resolved.
Show resolved Hide resolved
watchgod==0.8.2 # https://github.com/samuelcolvin/watchgod

# Testing
Expand Down
Loading