-
Notifications
You must be signed in to change notification settings - Fork 88
357 lines (310 loc) · 11.1 KB
/
unit-tests.yml
File metadata and controls
357 lines (310 loc) · 11.1 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
name: Unit Tests
on:
push:
branches: [main]
paths:
- 'components/backend/**'
- 'components/ambient-api-server/**'
- 'components/runners/ambient-runner/**'
- 'components/ambient-cli/**'
- 'components/ambient-sdk/go-sdk/**'
- 'components/frontend/**'
- '.github/scripts/**'
- 'tests/**'
- '.github/workflows/unit-tests.yml'
- '!**/*.md'
pull_request:
paths:
- 'components/backend/**'
- 'components/ambient-api-server/**'
- 'components/runners/ambient-runner/**'
- 'components/ambient-cli/**'
- 'components/ambient-sdk/go-sdk/**'
- 'components/frontend/**'
- '.github/scripts/**'
- 'tests/**'
- '.github/workflows/unit-tests.yml'
- '!**/*.md'
workflow_dispatch:
inputs:
test_label:
description: "Backend test label filter"
default: 'unit'
required: true
type: string
default_namespace:
description: "Default namespace for backend testing"
default: 'test-namespace'
required: false
type: string
concurrency:
group: unit-tests-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
backend: ${{ steps.filter.outputs.backend }}
api-server: ${{ steps.filter.outputs.api-server }}
runner: ${{ steps.filter.outputs.runner }}
cli: ${{ steps.filter.outputs.cli }}
frontend: ${{ steps.filter.outputs.frontend }}
scripts: ${{ steps.filter.outputs.scripts }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Detect changed components
uses: dorny/paths-filter@v4
id: filter
with:
filters: |
backend:
- 'components/backend/**'
api-server:
- 'components/ambient-api-server/**'
runner:
- 'components/runners/ambient-runner/**'
cli:
- 'components/ambient-cli/**'
- 'components/ambient-sdk/go-sdk/**'
frontend:
- 'components/frontend/**'
scripts:
- '.github/scripts/**'
- 'tests/test_model_discovery.py'
backend:
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.backend == 'true' || github.event_name == 'workflow_dispatch'
name: Backend Unit Tests
env:
TESTS_DIR: "./components/backend/handlers"
TESTS_LABEL: "unit"
JUNIT_FILENAME: "junit.xml"
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: 'components/backend/go.mod'
cache-dependency-path: 'components/backend/go.sum'
- name: Create reports directory
shell: bash
working-directory: ${{ env.TESTS_DIR }}
run: mkdir -p reports
- name: Configure Input Variables
shell: bash
id: configure
run: |
TEST_LABEL=${{ env.TESTS_LABEL }}
DEFAULT_NAMESPACE="test-namespace"
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
TEST_LABEL=${{ inputs.test_label }}
DEFAULT_NAMESPACE=${{ inputs.default_namespace }}
fi
{
echo "TEST_LABEL=$TEST_LABEL"
echo "DEFAULT_NAMESPACE=$DEFAULT_NAMESPACE"
} >> "$GITHUB_OUTPUT"
- name: Run Tests
id: run-tests
shell: bash
working-directory: ${{ env.TESTS_DIR }}
run: |
go run github.com/onsi/ginkgo/v2/ginkgo -r -v --cover --keep-going --github-output=true --tags=test --label-filter=${{ steps.configure.outputs.TEST_LABEL }} --junit-report=${{ env.JUNIT_FILENAME }} --output-dir=reports -- -testNamespace=${{ steps.configure.outputs.DEFAULT_NAMESPACE }}
continue-on-error: true
- name: Install Junit2Html plugin and generate report
if: (!cancelled())
shell: bash
run: |
pip install junit2html
junit2html ${{ env.TESTS_DIR }}/reports/${{ env.JUNIT_FILENAME }} ${{ env.TESTS_DIR }}/reports/test-report.html
continue-on-error: true
- name: Configure report name
id: name_gen
shell: bash
run: |
uuid=$(uuidgen)
REPORT_NAME="Backend Unit Tests HTML Report - ${{ github.run_id }}_${{ github.job }}_$uuid"
echo "REPORT_NAME=$REPORT_NAME" >> "$GITHUB_OUTPUT"
- name: Upload HTML Report
id: upload
uses: actions/upload-artifact@v6
if: (!cancelled())
with:
name: ${{ steps.name_gen.outputs.REPORT_NAME }}
path: ${{ env.TESTS_DIR }}/reports/test-report.html
retention-days: 7
continue-on-error: true
- name: Publish Test Summary With HTML Report
id: publish
uses: kubeflow/pipelines/.github/actions/junit-summary@master
if: (!cancelled()) && steps.upload.outcome != 'failure'
with:
xml_files: '${{ env.TESTS_DIR }}/reports'
custom_data: '{\"HTML Report\": \"${{ steps.upload.outputs.artifact-url }}\"}'
continue-on-error: true
- name: Publish Test Summary
id: summary
uses: kubeflow/pipelines/.github/actions/junit-summary@master
if: (!cancelled()) && steps.upload.outcome == 'failure'
with:
xml_files: '${{ env.TESTS_DIR }}/reports'
continue-on-error: true
- name: Mark Workflow failure if test step failed
if: steps.run-tests.outcome != 'success' && !cancelled()
shell: bash
run: exit 1
- name: Mark Workflow failure if test reporting failed
if: (steps.publish.outcome == 'failure' || steps.summary.outcome == 'failure' || steps.upload.outcome != 'success') && !cancelled()
shell: bash
run: exit 1
api-server:
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.api-server == 'true' || github.event_name == 'workflow_dispatch'
name: API Server Integration Tests
defaults:
run:
working-directory: components/ambient-api-server
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: 'components/ambient-api-server/go.mod'
cache-dependency-path: 'components/ambient-api-server/go.sum'
- name: Create secrets directory
run: |
mkdir -p secrets
printf '%s' 'localhost' > secrets/db.host
printf '%s' '5432' > secrets/db.port
printf '%s' 'ambient_api_server' > secrets/db.name
printf '%s' 'postgres' > secrets/db.user
printf '%s' 'postgres' > secrets/db.password
- name: Run tests
run: make test
runner:
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.runner == 'true' || github.event_name == 'workflow_dispatch'
name: Ambient Runner Tests
defaults:
run:
working-directory: components/runners/ambient-runner
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[all]"
pip install pytest pytest-asyncio pytest-cov httpx
- name: Run unit tests with coverage
run: |
pytest tests/ -v --tb=short --color=yes -x --cov=ambient_runner --cov-report=term-missing --cov-report=xml
cli:
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.cli == 'true' || github.event_name == 'workflow_dispatch'
name: CLI Build and Tests
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: 'components/ambient-cli/go.mod'
cache-dependency-path: 'components/ambient-cli/go.sum'
- name: Build binary
run: |
cd components/ambient-cli
go build -ldflags "-X github.com/ambient-code/platform/components/ambient-cli/pkg/info.Version=ci-${{ github.sha }}" -o acpctl ./cmd/acpctl/
- name: Verify binary runs
run: |
cd components/ambient-cli
./acpctl version
./acpctl --help
- name: Run unit tests
run: |
cd components/ambient-cli
go test -v -race -coverprofile=coverage.out ./...
- name: Upload coverage
uses: actions/upload-artifact@v6
if: always()
with:
name: cli-coverage-${{ github.run_id }}
path: components/ambient-cli/coverage.out
retention-days: 7
frontend:
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.frontend == 'true' || github.event_name == 'workflow_dispatch'
name: Frontend Unit Tests (Vitest)
defaults:
run:
working-directory: components/frontend
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version-file: 'components/frontend/package.json'
cache: 'npm'
cache-dependency-path: 'components/frontend/package-lock.json'
- name: Install dependencies
run: npm ci
- name: Run unit tests with coverage
run: npx vitest run --coverage
scripts:
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.scripts == 'true' || github.event_name == 'workflow_dispatch'
name: Script Tests (model-discovery)
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Run tests
run: python tests/test_model_discovery.py -v
summary:
runs-on: ubuntu-latest
needs: [detect-changes, backend, api-server, runner, cli, frontend, scripts]
if: always()
steps:
- name: Check overall status
run: |
failed=false
for result in \
"${{ needs.backend.result }}" \
"${{ needs.api-server.result }}" \
"${{ needs.runner.result }}" \
"${{ needs.cli.result }}" \
"${{ needs.frontend.result }}" \
"${{ needs.scripts.result }}"; do
if [ "$result" == "failure" ] || [ "$result" == "cancelled" ]; then
failed=true
fi
done
if [ "$failed" == "true" ]; then
echo "Unit tests failed"
echo " backend: ${{ needs.backend.result }}"
echo " api-server: ${{ needs.api-server.result }}"
echo " runner: ${{ needs.runner.result }}"
echo " cli: ${{ needs.cli.result }}"
echo " frontend: ${{ needs.frontend.result }}"
echo " scripts: ${{ needs.scripts.result }}"
exit 1
fi
echo "All unit tests passed!"