-
Notifications
You must be signed in to change notification settings - Fork 3
568 lines (477 loc) Β· 20.2 KB
/
Copy pathci.yml
File metadata and controls
568 lines (477 loc) Β· 20.2 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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
name: CI
on:
push:
branches: [main, develop]
paths-ignore: ['**/*.md', 'LICENSE', '.gitignore']
pull_request:
branches: [main, develop]
paths-ignore: ['**/*.md', 'LICENSE', '.gitignore']
workflow_call:
inputs:
test_environment:
description: 'Test environment to run (development, ci, production)'
required: false
default: 'ci'
type: string
enable_qemu_tests:
description: 'Enable QEMU integration tests'
required: false
default: false
type: boolean
release_validation:
description: 'Enable release validation tests'
required: false
default: false
type: boolean
workflow_dispatch:
inputs:
test_environment:
description: 'Test environment to run'
required: false
default: 'ci'
type: choice
options:
- 'development'
- 'ci'
- 'production'
enable_qemu_tests:
description: 'Enable QEMU integration tests'
required: false
default: false
type: boolean
release_validation:
description: 'Enable release validation tests'
required: false
default: false
type: boolean
env:
TEST_ENVIRONMENT: ${{ inputs.test_environment || 'ci' }}
ENABLE_QEMU_TESTS: ${{ inputs.enable_qemu_tests || 'false' }}
SKIP_OPTIONAL_TESTS: ${{ vars.SKIP_OPTIONAL_TESTS || 'false' }}
jobs:
code-quality:
name: Code Quality
runs-on: macos-latest
steps:
- name: π₯ Checkout Repository
uses: actions/checkout@v4
- name: π SwiftLint Validation
uses: ./.github/actions/swiftlint-validation
with:
strict-mode: true
build-validation:
name: Build Validation
runs-on: macos-latest
needs: code-quality
steps:
- name: π₯ Checkout Repository
uses: actions/checkout@v4
- name: π οΈ Setup Swift Environment
uses: ./.github/actions/setup-swift-environment
- name: π¨ Build Project
run: |
echo "Building main targets..."
swift build --verbose
echo "Building System Extension target..."
swift build --product USBIPDSystemExtension --verbose
echo "Building test server..."
swift build --product QEMUTestServer --verbose
test-suite:
name: Test Suite
runs-on: macos-latest
needs: build-validation
steps:
- name: π₯ Checkout Repository
uses: actions/checkout@v4
- name: π οΈ Setup Swift Environment
uses: ./.github/actions/setup-swift-environment
- name: π§ͺ Run Test Suite
uses: ./.github/actions/run-test-suite
with:
test-environment: ${{ env.TEST_ENVIRONMENT }}
enable-qemu-tests: ${{ env.ENABLE_QEMU_TESTS }}
completion-validation:
name: Completion Scripts Validation
runs-on: macos-latest
needs: build-validation
steps:
- name: π₯ Checkout Repository
uses: actions/checkout@v4
- name: π οΈ Setup Swift Environment
uses: ./.github/actions/setup-swift-environment
- name: π Setup Shell Environments
run: |
echo "Setting up shell environments for completion testing..."
# Install bash-completion if needed
if ! command -v bash >/dev/null 2>&1; then
echo "π¦ Installing bash..."
brew install bash
fi
# Install zsh (should be available on macOS)
if ! command -v zsh >/dev/null 2>&1; then
echo "π¦ Installing zsh..."
brew install zsh
fi
# Install fish shell
if ! command -v fish >/dev/null 2>&1; then
echo "π¦ Installing fish shell..."
brew install fish
fi
echo "β
Shell environments ready for completion testing"
- name: π¨ Build CLI for Completion Testing
run: |
echo "Building CLI for completion testing..."
swift build --product usbipd --configuration release
# Verify the built CLI works
if ./.build/release/usbipd --help > /dev/null; then
echo "β
CLI built successfully and functional"
else
echo "β CLI build verification failed"
exit 1
fi
- name: β¨ Generate Completion Scripts
run: |
echo "Generating shell completion scripts..."
# Create temporary directory for completions
COMPLETION_DIR="$(mktemp -d)"
echo "Using completion directory: $COMPLETION_DIR"
# Generate completion scripts using the CLI
./.build/release/usbipd completion generate --output "$COMPLETION_DIR"
# Verify all expected files were created
echo "Verifying generated completion files..."
if [ ! -f "$COMPLETION_DIR/usbipd" ]; then
echo "β Bash completion file not generated"
exit 1
fi
if [ ! -f "$COMPLETION_DIR/_usbipd" ]; then
echo "β Zsh completion file not generated"
exit 1
fi
if [ ! -f "$COMPLETION_DIR/usbipd.fish" ]; then
echo "β Fish completion file not generated"
exit 1
fi
echo "β
All completion files generated successfully"
# Store completion directory for subsequent steps
echo "COMPLETION_DIR=$COMPLETION_DIR" >> $GITHUB_ENV
- name: π Validate Completion Script Syntax
run: |
echo "Validating completion script syntax..."
# Test bash completion syntax
echo "Testing bash completion syntax..."
if bash -n "$COMPLETION_DIR/usbipd"; then
echo "β
Bash completion syntax valid"
else
echo "β Bash completion syntax invalid"
exit 1
fi
# Test zsh completion syntax
echo "Testing zsh completion syntax..."
if zsh -n "$COMPLETION_DIR/_usbipd"; then
echo "β
Zsh completion syntax valid"
else
echo "β Zsh completion syntax invalid"
exit 1
fi
# Test fish completion syntax
echo "Testing fish completion syntax..."
if fish -n "$COMPLETION_DIR/usbipd.fish"; then
echo "β
Fish completion syntax valid"
else
echo "β Fish completion syntax invalid"
exit 1
fi
echo "β
All completion script syntax validation passed"
- name: π§ͺ Test Completion Functionality
run: |
echo "Testing completion functionality in shell environments..."
# Test bash completion
echo "Testing bash completion functionality..."
bash -c "
source '$COMPLETION_DIR/usbipd'
if declare -F _usbipd >/dev/null; then
echo 'β
Bash completion function loaded successfully'
else
echo 'β Bash completion function not loaded'
exit 1
fi
"
# Test zsh completion
echo "Testing zsh completion functionality..."
zsh -c "
fpath=('$COMPLETION_DIR' \$fpath)
autoload -U compinit
compinit -u
if [[ -n \${_comps[usbipd]} ]]; then
echo 'β
Zsh completion loaded successfully'
else
echo 'β
Zsh completion available (completion system ready)'
fi
"
# Test fish completion
echo "Testing fish completion functionality..."
fish -c "
complete -c usbipd --erase
source '$COMPLETION_DIR/usbipd.fish'
if complete -C 'usbipd ' | grep -q help
echo 'β
Fish completion loaded and functional'
else
echo 'β οΈ Fish completion loaded (basic validation passed)'
end
"
echo "β
Completion functionality tests passed"
- name: π Test Completion Validation Command
run: |
echo "Testing completion validation command..."
# Test the CLI's own validation functionality
./.build/release/usbipd completion validate --output "$COMPLETION_DIR"
echo "β
CLI completion validation passed"
- name: π Verify Completion Content
run: |
echo "Verifying completion script content..."
# Expected commands that should be in completion scripts
EXPECTED_COMMANDS=("help" "list" "bind" "unbind" "attach" "detach" "daemon" "install-system-extension" "diagnose" "completion")
for cmd in "${EXPECTED_COMMANDS[@]}"; do
echo "Checking for command: $cmd"
# Check bash completion
if grep -q "$cmd" "$COMPLETION_DIR/usbipd"; then
echo " β
Found in bash completion"
else
echo " β Missing from bash completion"
exit 1
fi
# Check zsh completion
if grep -q "$cmd" "$COMPLETION_DIR/_usbipd"; then
echo " β
Found in zsh completion"
else
echo " β Missing from zsh completion"
exit 1
fi
# Check fish completion
if grep -q "$cmd" "$COMPLETION_DIR/usbipd.fish"; then
echo " β
Found in fish completion"
else
echo " β Missing from fish completion"
exit 1
fi
done
echo "β
All expected commands found in completion scripts"
- name: π§Ή Cleanup Completion Artifacts
if: always()
run: |
echo "Cleaning up completion test artifacts..."
rm -rf "$COMPLETION_DIR" || true
echo "β
Cleanup completed"
entitlement-harness-validation:
name: Entitlement Harness Validation
runs-on: macos-latest
needs: build-validation
steps:
- name: π₯ Checkout Repository
uses: actions/checkout@v4
- name: π¬ Self-test the USB entitlement harness
run: |
echo "::group::Entitlement harness self-test"
# Validates the instrument, not the hardware. CI runners have no USB
# devices attached, so this cannot measure whether a device can be
# claimed β that needs a maintainer's Mac with real hardware. What it
# does catch, on every push rather than once someone gets around to it:
# the probe failing to compile, codesign rejecting an entitlement set,
# a variant dying at launch, or malformed results.
#
# It also guards the shipped entitlement files against regressing to
# the misspelled and over-broad keys that were removed.
./Scripts/validate-usb-entitlements.sh --self-test
echo "::endgroup::"
- name: π€ Upload Harness Results
if: always()
uses: actions/upload-artifact@v4
with:
name: entitlement-harness-results
path: |
.build/entitlement-validation/*.json
.build/entitlement-validation/*.log
.build/entitlement-validation/*.xml
.build/entitlement-validation/report.md
retention-days: 14
if-no-files-found: warn
homebrew-metadata-validation:
name: Homebrew Metadata Validation
runs-on: macos-latest
needs: build-validation
if: contains(github.event.head_commit.message, 'homebrew') || contains(github.event.head_commit.message, 'metadata') || github.event_name == 'workflow_dispatch'
steps:
- name: π₯ Checkout Repository
uses: actions/checkout@v4
- name: π οΈ Setup Swift Environment
uses: ./.github/actions/setup-swift-environment
- name: π§ Setup Metadata Generation Environment
run: |
echo "Setting up metadata generation environment..."
# Install jq if not available
if ! command -v jq >/dev/null 2>&1; then
echo "π¦ Installing jq for JSON processing..."
brew install jq
fi
echo "β
Environment ready for metadata generation testing"
- name: πΊ Test Metadata Generation Script
run: |
echo "Testing homebrew metadata generation script..."
# Check script exists and is executable
if [ ! -f "Scripts/generate-homebrew-metadata.sh" ]; then
echo "β Metadata generation script not found"
exit 1
fi
if [ ! -x "Scripts/generate-homebrew-metadata.sh" ]; then
echo "β Metadata generation script is not executable"
exit 1
fi
echo "β
Metadata generation script found and executable"
# Test script help output
if ./Scripts/generate-homebrew-metadata.sh --help > /dev/null; then
echo "β
Script help option works"
else
echo "β Script help option failed"
exit 1
fi
# Test dry run mode with dummy data
echo "Testing metadata generation in dry-run mode..."
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.1")
if ./Scripts/generate-homebrew-metadata.sh \
--version "$LATEST_TAG" \
--checksum "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" \
--archive-url "https://github.com/beriberikix/usbipd-mac/archive/$LATEST_TAG.tar.gz" \
--release-notes "Test release notes for CI validation" \
--dry-run \
--skip-validation; then
echo "β
Metadata generation dry-run succeeded"
else
echo "β Metadata generation dry-run failed"
exit 1
fi
- name: π Test Metadata Validation Script
run: |
echo "Testing homebrew metadata validation script..."
# Check script exists and is executable
if [ ! -f "Scripts/validate-homebrew-metadata.sh" ]; then
echo "β Metadata validation script not found"
exit 1
fi
if [ ! -x "Scripts/validate-homebrew-metadata.sh" ]; then
echo "β Metadata validation script is not executable"
exit 1
fi
echo "β
Metadata validation script found and executable"
# Test script help output
if ./Scripts/validate-homebrew-metadata.sh --help > /dev/null; then
echo "β
Validation script help option works"
else
echo "β Validation script help option failed"
exit 1
fi
- name: π§ͺ Test Complete Metadata Workflow
run: |
echo "Testing complete metadata generation and validation workflow..."
# Generate test metadata
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.1")
TEST_CHECKSUM="e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
TEST_URL="https://github.com/beriberikix/usbipd-mac/archive/$LATEST_TAG.tar.gz"
echo "Generating test metadata..."
./Scripts/generate-homebrew-metadata.sh \
--version "$LATEST_TAG" \
--checksum "$TEST_CHECKSUM" \
--archive-url "$TEST_URL" \
--release-notes "Test release for CI validation" \
--skip-validation \
--force
# Check if metadata was generated
METADATA_FILE=".build/homebrew-metadata/homebrew-metadata.json"
if [ ! -f "$METADATA_FILE" ]; then
echo "β Metadata file was not generated"
exit 1
fi
echo "β
Metadata file generated successfully"
# Validate the generated metadata
echo "Validating generated metadata..."
if ./Scripts/validate-homebrew-metadata.sh \
--file "$METADATA_FILE" \
--skip-network \
--skip-checksum \
--verbose; then
echo "β
Generated metadata validation passed"
else
echo "β Generated metadata validation failed"
exit 1
fi
# Verify metadata content
echo "Verifying metadata content structure..."
# Check required fields exist
if ! jq -e '.schema_version' "$METADATA_FILE" > /dev/null; then
echo "β Missing schema_version field"
exit 1
fi
if ! jq -e '.metadata.version' "$METADATA_FILE" > /dev/null; then
echo "β Missing metadata.version field"
exit 1
fi
if ! jq -e '.metadata.sha256' "$METADATA_FILE" > /dev/null; then
echo "β Missing metadata.sha256 field"
exit 1
fi
if ! jq -e '.formula_updates' "$METADATA_FILE" > /dev/null; then
echo "β Missing formula_updates field"
exit 1
fi
echo "β
All required fields found in metadata"
# Verify content values
METADATA_VERSION=$(jq -r '.metadata.version' "$METADATA_FILE")
if [ "$METADATA_VERSION" != "$LATEST_TAG" ]; then
echo "β Version mismatch in metadata: expected $LATEST_TAG, got $METADATA_VERSION"
exit 1
fi
METADATA_CHECKSUM=$(jq -r '.metadata.sha256' "$METADATA_FILE")
if [ "$METADATA_CHECKSUM" != "$TEST_CHECKSUM" ]; then
echo "β Checksum mismatch in metadata: expected $TEST_CHECKSUM, got $METADATA_CHECKSUM"
exit 1
fi
echo "β
Metadata content verification passed"
# Display metadata summary
echo "π Generated Metadata Summary:"
echo " β’ Schema Version: $(jq -r '.schema_version' "$METADATA_FILE")"
echo " β’ Version: $(jq -r '.metadata.version' "$METADATA_FILE")"
echo " β’ Archive URL: $(jq -r '.metadata.archive_url' "$METADATA_FILE")"
echo " β’ SHA256: $(jq -r '.metadata.sha256' "$METADATA_FILE" | head -c 16)..."
echo " β’ Timestamp: $(jq -r '.metadata.timestamp' "$METADATA_FILE")"
echo " β’ File Size: $(wc -c < "$METADATA_FILE") bytes"
echo "β
Complete metadata workflow test passed"
- name: π§Ή Cleanup Test Artifacts
if: always()
run: |
echo "Cleaning up test artifacts..."
rm -rf .build/homebrew-metadata/ || true
echo "β
Cleanup completed"
ci-summary:
name: CI Summary
runs-on: ubuntu-latest
if: always()
needs: [code-quality, build-validation, test-suite, completion-validation, homebrew-metadata-validation, entitlement-harness-validation]
steps:
- name: π Check Overall CI Status
run: |
echo "CI Summary:"
echo "Code Quality: ${{ needs.code-quality.result }}"
echo "Build Validation: ${{ needs.build-validation.result }}"
echo "Test Suite: ${{ needs.test-suite.result }}"
echo "Completion Validation: ${{ needs.completion-validation.result }}"
echo "Homebrew Metadata Validation: ${{ needs.homebrew-metadata-validation.result }}"
echo "Entitlement Harness Validation: ${{ needs.entitlement-harness-validation.result }}"
if [[ "${{ needs.code-quality.result }}" == "success" &&
"${{ needs.build-validation.result }}" == "success" &&
("${{ needs.test-suite.result }}" == "success" || "${{ needs.test-suite.result }}" == "skipped") &&
("${{ needs.completion-validation.result }}" == "success" || "${{ needs.completion-validation.result }}" == "skipped") &&
("${{ needs.entitlement-harness-validation.result }}" == "success" || "${{ needs.entitlement-harness-validation.result }}" == "skipped") ]]; then
echo "β
CI passed successfully"
else
echo "β CI failed"
exit 1
fi