The job kept the fixed container names and the fixed 5432 that compose.ci.yml resets for every other job, so a second run could not start. Layering that file leaves the db on a port Docker assigns, which the suite is told about, and the project name is now per run so one teardown cannot take another run's database with it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H7LwYgJfpkbLCTeiAf8U4A
68 lines
2.6 KiB
YAML
68 lines
2.6 KiB
YAML
name: Test Backend
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
pull_request:
|
|
types:
|
|
- opened
|
|
- synchronize
|
|
|
|
env:
|
|
# The compose files live in docker/, so a bare `docker compose` from the repo
|
|
# root finds nothing. With COMPOSE_FILE set, compose reads .env from the
|
|
# working directory — the same file the backend settings load as ../.env.
|
|
# compose.ci.yml drops the fixed container_names and the fixed 5432 — both
|
|
# daemon-global, so without it a second run on the same host cannot start.
|
|
COMPOSE_FILE: docker/compose.yml:docker/compose.dev.yml:docker/compose.ci.yml
|
|
|
|
jobs:
|
|
test-backend:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
# Per run, so the `down -v` steps reach neither a dev stack nor a run
|
|
# still going. Unique names cannot be recycled, hence the always-on
|
|
# teardown below.
|
|
COMPOSE_PROJECT_NAME: fluksio-app-ci-backend-${{ github.run_id }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.10"
|
|
- name: Set up uv
|
|
uses: astral-sh/setup-uv@v7
|
|
with:
|
|
cache-dependency-glob: |
|
|
pyproject.toml
|
|
backend/pyproject.toml
|
|
uv.lock
|
|
- name: Write .env
|
|
# Not committed, and both compose and the backend settings need it.
|
|
# The suite runs on the runner and reaches the container over
|
|
# POSTGRES_SERVER=localhost from there, on the port resolved below.
|
|
run: cp .env.example .env
|
|
- run: docker compose down -v --remove-orphans
|
|
# Postgres is the only service the suite needs: the mail paths are
|
|
# patched in tests/, and the flow engine falls back to in-memory state
|
|
# while REDIS_HOST is empty.
|
|
- run: docker compose up -d --wait db
|
|
- name: Resolve the db port
|
|
# Docker assigns it (docker/compose.ci.yml), so concurrent runs get one
|
|
# each. An env var outranks the .env file in the backend settings.
|
|
run: echo "POSTGRES_PORT=$(docker compose port db 5432 | tail -n1 | cut -d: -f2)" >> "$GITHUB_ENV"
|
|
- run: uv sync
|
|
- name: Migrate DB and seed the superuser
|
|
run: uv run bash scripts/prestart.sh
|
|
working-directory: backend
|
|
# scripts/tests-start.sh waits for the DB, then runs pytest under
|
|
# coverage and prints the report (see backend/scripts/test.sh).
|
|
- name: Run tests with coverage
|
|
run: uv run bash scripts/tests-start.sh "Coverage for ${{ github.sha }}"
|
|
working-directory: backend
|
|
- name: Tear down
|
|
if: always()
|
|
run: docker compose down -v --remove-orphans
|