-
Notifications
You must be signed in to change notification settings - Fork 0
220 lines (188 loc) · 6.01 KB
/
Copy pathci.yml
File metadata and controls
220 lines (188 loc) · 6.01 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
name: CI - Continuous Integration
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
workflow_dispatch:
# Cancel in-progress runs for the same workflow and ref
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# Detect which parts of the codebase changed
changes:
name: Detect Changes
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
python: ${{ steps.filter.outputs.python }}
frontend: ${{ steps.filter.outputs.frontend }}
docker: ${{ steps.filter.outputs.docker }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
python:
- 'phentrieve/**'
- 'api/**'
- 'tests/**'
- 'pyproject.toml'
- 'uv.lock'
- '.github/workflows/ci.yml'
frontend:
- 'frontend/**'
- '.github/workflows/ci.yml'
docker:
- '**/Dockerfile'
- 'docker-compose*.yml'
- '.github/workflows/ci.yml'
# Python Backend CI
python-ci:
name: Python CI
needs: changes
if: needs.changes.outputs.python == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "latest"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache uv dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/uv
.venv
key: ${{ runner.os }}-uv-${{ matrix.python-version }}-${{ hashFiles('uv.lock') }}
restore-keys: |
${{ runner.os }}-uv-${{ matrix.python-version }}-
${{ runner.os }}-uv-
- name: Install dependencies
run: |
uv sync --all-extras --dev
- name: Run Ruff format check
run: |
uv run ruff format --check phentrieve/ api/ tests/
- name: Run Ruff linting
run: |
uv run ruff check phentrieve/ api/ tests/
- name: Run mypy type checking
run: |
uv run mypy phentrieve/ api/
continue-on-error: true # Don't fail on type errors (gradual typing)
- name: Run pytest
run: |
uv run pytest tests/ -v -m "not e2e" --cov=phentrieve --cov=api --cov-report=xml --cov-report=term
- name: Upload coverage to Codecov
if: matrix.python-version == '3.10'
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
flags: python
name: python-${{ matrix.python-version }}
continue-on-error: true
# Frontend CI
frontend-ci:
name: Frontend CI
needs: changes
if: needs.changes.outputs.frontend == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
working-directory: frontend
run: npm ci
- name: Run ESLint
working-directory: frontend
run: npm run lint
- name: Run Prettier format check
working-directory: frontend
run: npm run format:check
- name: Run Vitest tests
working-directory: frontend
run: npm run test:coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: ./frontend/coverage/coverage-final.json
flags: frontend
name: frontend
continue-on-error: true
- name: Build frontend
working-directory: frontend
run: npm run build
env:
VITE_API_URL: /api/v1
# Docker Build Test
docker-build-test:
name: Docker Build Test
needs: changes
if: needs.changes.outputs.docker == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
service: [api, frontend]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
docker system prune -af
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build ${{ matrix.service }} image
uses: docker/build-push-action@v5
with:
context: ${{ matrix.service == 'api' && '.' || './frontend' }}
file: ${{ matrix.service == 'api' && './api/Dockerfile' || './frontend/Dockerfile' }}
push: false
tags: ghcr.io/berntpopp/phentrieve/${{ matrix.service }}:test
# No caching for test builds - we just need to verify they complete
build-args: |
${{ matrix.service == 'frontend' && 'VITE_API_URL=/api/v1' || '' }}
# Summary job that requires all checks to pass
ci-summary:
name: CI Summary
needs: [changes, python-ci, frontend-ci, docker-build-test]
if: always()
runs-on: ubuntu-latest
steps:
- name: Check CI results
run: |
echo "Python CI: ${{ needs.python-ci.result }}"
echo "Frontend CI: ${{ needs.frontend-ci.result }}"
echo "Docker Build: ${{ needs.docker-build-test.result }}"
# Fail if any required job failed
if [[ "${{ needs.python-ci.result }}" == "failure" ]] || \
[[ "${{ needs.frontend-ci.result }}" == "failure" ]] || \
[[ "${{ needs.docker-build-test.result }}" == "failure" ]]; then
echo "❌ One or more CI jobs failed"
exit 1
fi
echo "✅ All CI checks passed"