114 lines
4.6 KiB
YAML
114 lines
4.6 KiB
YAML
name: Test Suite
|
|
|
|
# One run per push. The deploy starts at the same time and updates the checkout this suite tests,
|
|
# so the jobs wait until that checkout contains the pushed commit. A workflow_run trigger
|
|
# (after the deploy) did not start reliably on this Gitea, see git log of this file.
|
|
on:
|
|
push:
|
|
branches: [develop]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
pytest-backend:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: pytest against Dev Postgres (tsumugu_test)
|
|
run: |
|
|
set -e
|
|
APP_DIR="/home/lars/docker/tsumugu-dev"
|
|
COMPOSE_FILE="docker-compose.dev-env.yml"
|
|
echo "pytest uses Dev Postgres (${APP_DIR}); event=${{ github.event_name }}"
|
|
if [ "${{ github.event_name }}" = "push" ]; then
|
|
for i in $(seq 1 180); do
|
|
if git -c safe.directory='*' -C "$APP_DIR" merge-base --is-ancestor "${{ github.sha }}" HEAD 2>/dev/null; then
|
|
echo "Dev checkout contains ${{ github.sha }} (attempt $i)"
|
|
break
|
|
fi
|
|
if [ "$i" -eq 180 ]; then
|
|
echo "the deploy did not reach ${{ github.sha }} within 15 minutes"
|
|
exit 1
|
|
fi
|
|
sleep 5
|
|
done
|
|
fi
|
|
cd "$APP_DIR"
|
|
for i in $(seq 1 60); do
|
|
if [ -f "$APP_DIR/backend/pytest.ini" ] && docker compose -f "$COMPOSE_FILE" exec -T backend true 2>/dev/null; then
|
|
echo "backend and pytest.ini ready (attempt $i)"
|
|
break
|
|
fi
|
|
if [ "$i" -eq 60 ]; then
|
|
echo "timeout waiting for Dev checkout/backend"
|
|
docker compose -f "$COMPOSE_FILE" ps || true
|
|
ls -la "$APP_DIR/backend" || true
|
|
exit 1
|
|
fi
|
|
sleep 5
|
|
done
|
|
PGUSER="$(docker compose -f "$COMPOSE_FILE" exec -T postgres printenv POSTGRES_USER | tr -d '\r')"
|
|
echo "test database tsumugu_test on the existing Dev Postgres (owner ${PGUSER})"
|
|
docker compose -f "$COMPOSE_FILE" exec -T postgres \
|
|
psql -U "$PGUSER" -d postgres -v ON_ERROR_STOP=1 \
|
|
-c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'tsumugu_test' AND pid <> pg_backend_pid();"
|
|
docker compose -f "$COMPOSE_FILE" exec -T postgres \
|
|
psql -U "$PGUSER" -d postgres -v ON_ERROR_STOP=1 \
|
|
-c "DROP DATABASE IF EXISTS tsumugu_test;"
|
|
docker compose -f "$COMPOSE_FILE" exec -T postgres \
|
|
psql -U "$PGUSER" -d postgres -v ON_ERROR_STOP=1 \
|
|
-c "CREATE DATABASE tsumugu_test OWNER ${PGUSER};"
|
|
docker compose -f "$COMPOSE_FILE" run --rm --no-deps \
|
|
-v "${APP_DIR}:/src:ro" \
|
|
-w /src/backend \
|
|
-e DB_NAME=tsumugu_test \
|
|
-e SEED_DEMO=false \
|
|
-e PYTHONUTF8=1 \
|
|
backend sh -lc '
|
|
set -e
|
|
export DB_NAME=tsumugu_test
|
|
export SEED_DEMO=false
|
|
pip install -q -r requirements-dev.txt
|
|
python -m pytest tests -ra --tb=short
|
|
'
|
|
|
|
smoke-dev:
|
|
# After pytest, so the deploy that started with the push has normally finished. The health check retries.
|
|
needs: pytest-backend
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Non-destructive smoke against the running Dev app
|
|
run: |
|
|
set -e
|
|
echo "live Dev API (tsumugu_dev), read-only health"
|
|
for url in http://localhost:8094/api/health http://localhost:3094/api/health; do
|
|
for i in $(seq 1 30); do
|
|
if curl -sf "$url"; then echo; break; fi
|
|
if [ "$i" -eq 30 ]; then echo "no health answer from $url"; exit 1; fi
|
|
sleep 10
|
|
done
|
|
done
|
|
echo "LAN smoke OK. Public URL after TLS: https://dev.tsumugu.jinkendo.de"
|
|
|
|
frontend-build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Frontend production build on Dev checkout
|
|
run: |
|
|
set -e
|
|
APP_DIR="/home/lars/docker/tsumugu-dev"
|
|
if [ "${{ github.event_name }}" = "push" ]; then
|
|
for i in $(seq 1 180); do
|
|
if git -c safe.directory='*' -C "$APP_DIR" merge-base --is-ancestor "${{ github.sha }}" HEAD 2>/dev/null; then
|
|
echo "Dev checkout contains ${{ github.sha }} (attempt $i)"
|
|
break
|
|
fi
|
|
if [ "$i" -eq 180 ]; then
|
|
echo "the deploy did not reach ${{ github.sha }} within 15 minutes"
|
|
exit 1
|
|
fi
|
|
sleep 5
|
|
done
|
|
fi
|
|
cd "$APP_DIR/frontend"
|
|
npm ci
|
|
npm run build
|