Skip to content

Tests: main

Tests: main #55

Workflow file for this run

name: "CI: Tests"
run-name: "Tests: ${{ github.ref_name }}"
on:
push:
branches:
- main
- develop
- 'feature/**'
pull_request:
branches:
- main
- develop
- 'specification/**'
- 'implementation/**'
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
permissions:
contents: read
env:
ENVIRONMENT: test
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check for testable changes
id: check
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
CHANGED_FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA)
else
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "")
fi
echo "Changed files:"
echo "$CHANGED_FILES"
# Check for Python changes outside plots/ (api, core, tests, automation)
# Plot implementations don't have unit tests
TESTABLE_CHANGES=$(echo "$CHANGED_FILES" | grep '\.py$' | grep -v '^plots/' || true)
if [[ -n "$TESTABLE_CHANGES" ]]; then
echo "Found testable Python changes, will run tests"
echo "should_test=true" >> $GITHUB_OUTPUT
else
echo "No testable changes (only plots/ or non-Python), skipping tests"
echo "should_test=false" >> $GITHUB_OUTPUT
fi
- name: Set up Python
if: steps.check.outputs.should_test == 'true'
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install uv
if: steps.check.outputs.should_test == 'true'
uses: astral-sh/setup-uv@v7
- name: Install dependencies
if: steps.check.outputs.should_test == 'true'
run: uv sync --extra test
- name: Setup GCP authentication
if: steps.check.outputs.should_test == 'true'
uses: google-github-actions/auth@v3
with:
credentials_json: ${{ secrets.GCS_CREDENTIALS }}
- name: Start Cloud SQL Proxy
if: steps.check.outputs.should_test == 'true'
run: |
# Download Cloud SQL Proxy
curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.14.3/cloud-sql-proxy.linux.amd64
chmod +x cloud-sql-proxy
# Start proxy in background (localhost:5432 -> Cloud SQL)
./cloud-sql-proxy --port 5432 ${{ secrets.INSTANCE_CONNECTION_NAME }} &
# Wait for proxy to be ready
sleep 5
# Set DATABASE_URL for tests
echo "DATABASE_URL=postgresql+asyncpg://${{ secrets.DB_USER }}:${{ secrets.DB_PASS }}@localhost:5432/${{ secrets.DB_NAME }}" >> $GITHUB_ENV
- name: Run all tests with coverage
if: steps.check.outputs.should_test == 'true'
run: |
uv run pytest tests/unit tests/integration tests/e2e \
-v --tb=short \
--cov=core --cov=api --cov=automation \
--cov-report=term-missing \
--cov-report=xml
# Tests include:
# - Unit tests: Fast, mocked dependencies
# - Integration tests: SQLite in-memory for repository layer
# - E2E tests: Real PostgreSQL with separate 'test' database
- name: Upload coverage to GitHub Artifacts
if: steps.check.outputs.should_test == 'true' && always()
uses: actions/upload-artifact@v6
with:
name: coverage-report
path: coverage.xml
retention-days: 30
- name: Upload coverage to Codecov
if: steps.check.outputs.should_test == 'true'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
fail_ci_if_error: false
- name: Skip notice
if: steps.check.outputs.should_test == 'false'
run: echo "::notice::Tests skipped - no testable Python changes (only plots/ or non-Python files)"