-
Notifications
You must be signed in to change notification settings - Fork 2
214 lines (182 loc) · 6.9 KB
/
integration-tests.yml
File metadata and controls
214 lines (182 loc) · 6.9 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
name: Integration Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
schedule:
# Run integration tests nightly at 3 AM UTC to catch integration issues early
- cron: "0 3 * * *"
env:
REGISTRY: ghcr.io
IMAGE_PREFIX: ghcr.io/${{ github.repository_owner }}/nexuslims-test
jobs:
integration-test:
name: Integration Tests (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull pre-built test images
run: |
docker pull ${{ env.IMAGE_PREFIX }}-nemo:latest || echo "NEMO image not found, will build locally"
docker pull ${{ env.IMAGE_PREFIX }}-cdcs:latest || echo "CDCS image not found, will build locally"
- name: Tag images for local use
continue-on-error: true
run: |
docker tag ${{ env.IMAGE_PREFIX }}-nemo:latest nexuslims-test-nemo:latest 2>/dev/null || true
docker tag ${{ env.IMAGE_PREFIX }}-cdcs:latest nexuslims-test-cdcs:latest 2>/dev/null || true
- name: Start Docker services
working-directory: tests/integration/docker
run: |
# Try to use pre-built images first, fall back to building if needed
if docker image inspect nexuslims-test-nemo:latest >/dev/null 2>&1 && \
docker image inspect nexuslims-test-cdcs:latest >/dev/null 2>&1; then
echo "Using pre-built images from registry"
docker compose -f docker-compose.ci.yml up -d
else
echo "Building images locally (pre-built images not available)"
docker compose up -d
fi
- name: Wait for services to be healthy
run: |
echo "Waiting for NEMO to be ready..."
timeout 180 bash -c 'until curl -f http://localhost:8000/ > /dev/null 2>&1; do echo -n "."; sleep 3; done'
echo "✓ NEMO is ready"
echo "Waiting for CDCS to be ready..."
timeout 240 bash -c 'until curl -f http://localhost:8080/ > /dev/null 2>&1; do echo -n "."; sleep 5; done'
echo "✓ CDCS is ready"
echo "Waiting for MailPit to be ready..."
timeout 60 bash -c 'until curl -f http://localhost:8025/ > /dev/null 2>&1; do echo -n "."; sleep 2; done'
echo "✓ MailPit is ready"
- name: Show Docker service status
if: always()
working-directory: tests/integration/docker
run: docker compose ps
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y findutils
- name: Set up uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: uv sync
- name: Create test environment for module imports
run: |
# Create test directories
mkdir -p /tmp/nexuslims-test-instrument-data
mkdir -p /tmp/nexuslims-test-data
# Create empty database file (Settings validates it exists)
touch /tmp/nexuslims-test-data/nexuslims_test.db
# Create .env file with minimal config for import-time validation
cat > .env << 'EOF'
# CI Integration Test Environment
# These values allow NexusLIMS modules to be imported during test collection
# The actual test fixtures will override these with monkeypatch
# Test data paths
NX_INSTRUMENT_DATA_PATH=/tmp/nexuslims-test-instrument-data
NX_DATA_PATH=/tmp/nexuslims-test-data
NX_DB_PATH=/tmp/nexuslims-test-data/nexuslims_test.db
# CDCS configuration (will be overridden by fixtures)
NX_CDCS_URL=http://localhost:8080
NX_CDCS_USER=admin
NX_CDCS_PASS=admin
EOF
- name: Run unit tests
run: |
uv run pytest tests/ \
--ignore=tests/integration \
-v \
--mpl \
--mpl-baseline-path=tests/unit/files/figs \
--cov=nexusLIMS \
--cov-report term-missing \
--tb=short \
--maxfail=5
- name: Run integration tests
run: |
uv run pytest tests/integration/ \
-v \
-m integration \
--cov=nexusLIMS \
--cov-append \
--cov-report html:tests/coverage-combined \
--cov-report term-missing \
--cov-report=xml:coverage-combined.xml \
--tb=short \
--maxfail=5
env:
# Integration test environment variables
PYTEST_TIMEOUT: 600
- name: Upload combined test coverage
uses: actions/upload-artifact@v4
with:
name: coverage-combined-${{ matrix.python-version }}
path: |
.coverage
coverage-combined.xml
include-hidden-files: true
- name: Upload HTML coverage report
if: matrix.python-version == '3.11'
uses: actions/upload-artifact@v4
with:
name: coverage-combined-html
path: tests/coverage-combined
- name: Show Docker logs on failure
if: failure()
working-directory: tests/integration/docker
run: |
echo "=== NEMO Logs ==="
docker compose logs nemo | tail -100
echo ""
echo "=== CDCS Logs ==="
docker compose logs cdcs | tail -100
echo ""
echo "=== MongoDB Logs ==="
docker compose logs cdcs-mongo | tail -50
echo ""
echo "=== PostgreSQL Logs ==="
docker compose logs cdcs-postgres | tail -50
- name: Cleanup Docker services
if: always()
working-directory: tests/integration/docker
run: |
docker compose down -v --remove-orphans || true
upload-coverage:
name: Upload Combined Coverage to Codecov
needs: integration-test
runs-on: ubuntu-latest
if: always()
steps:
- uses: actions/checkout@v4
- name: Download all coverage artifacts
uses: actions/download-artifact@v4
with:
pattern: coverage-combined-*
path: coverage-reports
- name: Upload combined coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage-reports/**/*.xml
flags: combined
fail_ci_if_error: false