-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (105 loc) · 3.87 KB
/
ci-tests.yml
File metadata and controls
125 lines (105 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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-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)"