-
Notifications
You must be signed in to change notification settings - Fork 131
294 lines (253 loc) · 9.49 KB
/
Copy pathtest.yml
File metadata and controls
294 lines (253 loc) · 9.49 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
# Run unit tests across all SDKs.
#
# This workflow runs unit tests only (no VM/integration tests).
# GitHub runners do not support nested virtualization, so we cannot run
# tests that require actual VMs.
#
# Test coverage:
# - Rust: cargo-nextest (unit tests only, with llvm-cov coverage)
# - Python: pytest with -m "not integration"
# - Node.js: vitest (all tests are unit tests)
name: Test
on:
merge_group:
push:
branches: [main]
paths:
- 'src/boxlite/**'
- 'src/shared/**'
- 'src/cli/**'
- 'src/guest/**'
- 'sdks/**'
- '**/Cargo.toml'
- 'Cargo.lock'
- '.github/workflows/test.yml'
- '.github/workflows/config.yml'
# No path filter on pull_request: the `Test (conclusion)` job is a required
# status check, so this workflow must run on EVERY PR and report it. A
# path-skipped workflow leaves the required check stuck "Pending" → PR blocked.
# Per-suite filtering still happens in the `changes` job (jobs skip when
# unaffected); the conclusion job reports success-or-skipped.
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: '0'
jobs:
# Load shared configuration
config:
uses: ./.github/workflows/config.yml
# Detect which files changed to conditionally run tests
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
rust: ${{ steps.filter.outputs.rust }}
cli: ${{ steps.filter.outputs.boxlite_cli }}
python: ${{ steps.filter.outputs.python }}
node: ${{ steps.filter.outputs.node }}
go: ${{ steps.filter.outputs.go }}
steps:
- uses: actions/checkout@v5
- uses: dorny/paths-filter@v4
id: filter
with:
# In a merge queue, diff against the merge-group base/head (no PR base
# exists). Empty on pull_request/push, where paths-filter ignores them.
base: ${{ github.event_name == 'merge_group' && github.event.merge_group.base_sha || '' }}
ref: ${{ github.event_name == 'merge_group' && github.event.merge_group.head_sha || '' }}
filters: |
rust:
- 'src/boxlite/**'
- 'src/shared/**'
- 'src/guest/**'
- '**/Cargo.toml'
- 'Cargo.lock'
cli:
- 'src/cli/**'
python:
- 'sdks/python/**'
node:
- 'sdks/node/**'
go:
- 'sdks/go/**'
# Rust unit tests (boxlite-shared only - boxlite requires native libs not available in CI)
rust:
name: Rust Tests (${{ matrix.platform.target }})
needs: [config, changes]
if: ${{ needs.changes.outputs.rust == 'true' }}
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform: ${{ fromJson(needs.config.outputs.platforms) }}
permissions:
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ needs.config.outputs.rust-toolchain }}
- name: Install system dependencies (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Install system dependencies (macOS)
if: runner.os == 'macOS'
run: brew install protobuf
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Run Rust unit tests with coverage
# Only test boxlite-shared - boxlite requires libkrun/libgvproxy not available in CI
run: cargo llvm-cov nextest -p boxlite-shared --lib --profile ci --lcov --output-path lcov.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
file: lcov.info
flags: rust-shared
use_oidc: true
fail_ci_if_error: false
# cli unit tests (integration tests in tests/ are ignored - require VM)
cli:
name: CLI Unit Tests (${{ matrix.platform.target }})
needs: [config, changes]
if: ${{ needs.changes.outputs.cli == 'true' }}
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform: ${{ fromJson(needs.config.outputs.platforms) }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ needs.config.outputs.rust-toolchain }}
- name: Install system dependencies (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Install system dependencies (macOS)
if: runner.os == 'macOS'
run: brew install protobuf
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest
- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.9
continue-on-error: true
- name: Export GHA cache env vars
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
core.exportVariable('ACTIONS_CACHE_SERVICE_V2', process.env.ACTIONS_CACHE_SERVICE_V2 || '');
- name: Run boxlite-cli unit tests
# Only run tests in src/ (name contains "::tests::"); skip integration tests in tests/ (require VM)
env:
BOXLITE_DEPS_STUB: "1"
run: cargo nextest run -p boxlite-cli --profile ci -E 'test(::tests::)'
# Python SDK unit tests
python:
name: Python Tests (${{ matrix.platform.target }} / Python ${{ matrix.python-version }})
needs: [config, changes]
if: ${{ needs.changes.outputs.python == 'true' }}
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform: ${{ fromJson(needs.config.outputs.platforms) }}
python-version: ${{ fromJson(needs.config.outputs.python-versions) }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install test dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-asyncio
- name: Run Python unit tests
working-directory: sdks/python
run: python -m pytest tests/ -v -m "not integration"
# Node.js SDK unit tests
node:
name: Node.js Tests (${{ matrix.platform.target }} / Node ${{ matrix.node-version }})
needs: [config, changes]
if: ${{ needs.changes.outputs.node == 'true' }}
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform: ${{ fromJson(needs.config.outputs.platforms) }}
node-version: ${{ fromJson(needs.config.outputs.node-versions) }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
working-directory: sdks/node
run: npm install
- name: Run Node.js unit tests
working-directory: sdks/node
run: npm run test
# Go SDK unit tests
go:
name: Go Tests (${{ matrix.platform.target }})
needs: [config, changes]
if: ${{ needs.changes.outputs.go == 'true' }}
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform: ${{ fromJson(needs.config.outputs.platforms) }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ needs.config.outputs.rust-toolchain }}
- name: Install build dependencies
run: make setup:build
- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.9
continue-on-error: true
- name: Export GHA cache env vars
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
core.exportVariable('ACTIONS_CACHE_SERVICE_V2', process.env.ACTIONS_CACHE_SERVICE_V2 || '');
- name: Run Go unit tests
run: make test:unit:go
# Single required status check for branch protection / merge queue.
# Passes only if every job above succeeded or was skipped (path-filtered).
# `if: !cancelled()` is required: without it a failed dependency would skip
# this job, and GitHub treats a skipped required check as success.
# NOTE: keep `needs` in sync with the jobs above when adding/removing jobs.
test-conclusion:
name: Test (conclusion)
needs: [config, changes, rust, cli, python, node, go]
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
permissions: {}
steps:
- name: All test jobs passed or were skipped
run: |
jq -C <<< '${{ toJSON(needs) }}'
jq --exit-status 'all(.result == "success" or .result == "skipped")' <<< '${{ toJSON(needs) }}'