feat: Refactor test workflow to separate lint, unit, and e2e jobs with health checks for PostgreSQL service
This commit is contained in:
@@ -2,8 +2,75 @@ name: Run Tests
|
|||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
lint:
|
||||||
name: ${{ matrix.target }} tests
|
name: Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Export PYTHONPATH
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
echo "PYTHONPATH=${{ github.workspace }}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
|
- name: Prepare Python environment
|
||||||
|
uses: ./.gitea/actions/setup-python-env
|
||||||
|
with:
|
||||||
|
use-system-python: 'true'
|
||||||
|
run-db-setup: 'false'
|
||||||
|
|
||||||
|
- name: Run lint checks
|
||||||
|
run: ruff check .
|
||||||
|
|
||||||
|
unit:
|
||||||
|
name: Unit Tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
DATABASE_DRIVER: postgresql
|
||||||
|
DATABASE_HOST: postgres
|
||||||
|
DATABASE_PORT: '5432'
|
||||||
|
DATABASE_NAME: calminer_ci
|
||||||
|
DATABASE_USER: calminer
|
||||||
|
DATABASE_PASSWORD: secret
|
||||||
|
DATABASE_SCHEMA: public
|
||||||
|
DATABASE_SUPERUSER: calminer
|
||||||
|
DATABASE_SUPERUSER_PASSWORD: secret
|
||||||
|
DATABASE_SUPERUSER_DB: calminer_ci
|
||||||
|
DATABASE_URL: postgresql+psycopg2://calminer:secret@postgres:5432/calminer_ci
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:16
|
||||||
|
env:
|
||||||
|
POSTGRES_DB: calminer_ci
|
||||||
|
POSTGRES_USER: calminer
|
||||||
|
POSTGRES_PASSWORD: secret
|
||||||
|
options: >-
|
||||||
|
--health-cmd "pg_isready -U calminer -d calminer_ci"
|
||||||
|
--health-interval 10s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 10
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Export PYTHONPATH
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
echo "PYTHONPATH=${{ github.workspace }}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
|
- name: Prepare Python environment
|
||||||
|
uses: ./.gitea/actions/setup-python-env
|
||||||
|
with:
|
||||||
|
use-system-python: 'true'
|
||||||
|
|
||||||
|
- name: Run unit tests
|
||||||
|
run: pytest tests/unit
|
||||||
|
|
||||||
|
e2e:
|
||||||
|
name: E2E Tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: mcr.microsoft.com/playwright/python:v1.55.0-jammy
|
container: mcr.microsoft.com/playwright/python:v1.55.0-jammy
|
||||||
env:
|
env:
|
||||||
@@ -18,10 +85,6 @@ jobs:
|
|||||||
DATABASE_SUPERUSER_PASSWORD: secret
|
DATABASE_SUPERUSER_PASSWORD: secret
|
||||||
DATABASE_SUPERUSER_DB: calminer_ci
|
DATABASE_SUPERUSER_DB: calminer_ci
|
||||||
DATABASE_URL: postgresql+psycopg2://calminer:secret@postgres:5432/calminer_ci
|
DATABASE_URL: postgresql+psycopg2://calminer:secret@postgres:5432/calminer_ci
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
target: [unit, e2e, lint]
|
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:16
|
image: postgres:16
|
||||||
@@ -50,29 +113,13 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
echo "PYTHONPATH=/workspace/allucanget/calminer" >> "$GITHUB_ENV"
|
echo "PYTHONPATH=${{ github.workspace }}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
# - name: Cache pip dependencies
|
|
||||||
# uses: actions/cache@v4
|
|
||||||
# with:
|
|
||||||
# path: ~/.cache/pip
|
|
||||||
# key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt', 'requirements-test.txt') }}
|
|
||||||
# restore-keys: |
|
|
||||||
# ${{ runner.os }}-pip-
|
|
||||||
|
|
||||||
- name: Prepare Python environment
|
- name: Prepare Python environment
|
||||||
uses: ./.gitea/actions/setup-python-env
|
uses: ./.gitea/actions/setup-python-env
|
||||||
with:
|
with:
|
||||||
install-playwright: ${{ matrix.target == 'e2e' }}
|
|
||||||
use-system-python: 'true'
|
use-system-python: 'true'
|
||||||
run-db-setup: ${{ matrix.target != 'lint' }}
|
install-playwright: 'true'
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run e2e tests
|
||||||
run: |
|
run: pytest tests/e2e
|
||||||
if [ "${{ matrix.target }}" = "unit" ]; then
|
|
||||||
pytest tests/unit
|
|
||||||
elif [ "${{ matrix.target }}" = "lint" ]; then
|
|
||||||
ruff check .
|
|
||||||
else
|
|
||||||
pytest tests/e2e
|
|
||||||
fi
|
|
||||||
|
|||||||
Reference in New Issue
Block a user