| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- name: zzz [DO NOT RUN] Automated unit tests
- on:
- pull_request:
- branches:
- - dev
- types: [opened, synchronize]
- paths-ignore:
- - '**.md'
- - '**/README'
- - '**.yml'
- - '**.txt'
- push:
- branches:
- - dev
- paths-ignore:
- - '**.md'
- - '**/README'
- - '**.yml'
- - '**.txt'
- jobs:
- # Guards the TrioAlgorithm SPM package declared in Package.swift.
- #
- # Package.swift is a "shadow" package: it compiles a hand-enumerated subset of
- # the app's sources so the oref algorithm builds standalone on macOS, which is
- # what lets CLI tools replay recorded inputs against it.
- #
- # The `test` job below cannot catch drift in that list, because the Xcode
- # target globs whole directories. Any commit that adds a cross-file dependency
- # inside an already-listed file breaks `swift test` while `test` stays green.
- # This job is the only thing that notices.
- #
- # Runs in parallel with `test` and needs no simulator, so it reports in well
- # under a minute.
- algorithm-package:
- name: Algorithm Package (swift test)
- runs-on: macos-26
- if: github.repository_owner == 'nightscout'
- steps:
- - name: Select Xcode version
- run: sudo xcode-select -s /Applications/Xcode_26.2.app/Contents/Developer
- # No submodules: the package declares no external dependencies and
- # compiles only files under Trio/Sources and TrioTests/OpenAPSSwiftTests.
- - name: Checkout code
- uses: actions/checkout@v5
- with:
- fetch-depth: 1
- - name: Restore cache
- id: spm-cache-restore
- uses: actions/cache/restore@v5
- with:
- path: .build
- key: ${{ runner.os }}-spm-algorithm-${{ hashFiles('Package.swift', 'Trio/Sources/**/*.swift', 'TrioTests/OpenAPSSwiftTests/**/*.swift') }}
- restore-keys: |
- ${{ runner.os }}-spm-algorithm-
- - name: Show Swift version
- run: swift --version
- - name: Run algorithm tests
- run: time swift test
- - name: Save cache
- if: always() && steps.spm-cache-restore.outputs.cache-hit != 'true'
- uses: actions/cache/save@v5
- with:
- path: .build
- key: ${{ runner.os }}-spm-algorithm-${{ hashFiles('Package.swift', 'Trio/Sources/**/*.swift', 'TrioTests/OpenAPSSwiftTests/**/*.swift') }}
- - name: Annotate algorithm package results
- if: always()
- run: |
- if [ "${{ job.status }}" = "success" ]; then
- echo "::notice title=Algorithm Package::✅ swift test passed"
- echo "✅ Algorithm package builds standalone on macOS and all tests passed" >> $GITHUB_STEP_SUMMARY
- else
- echo "::error title=Algorithm Package::❌ swift test failed"
- {
- echo "## ❌ Algorithm package (\`swift test\`) failed"
- echo ""
- echo "\`Package.swift\` enumerates its sources by hand, so it drifts when a"
- echo "listed file gains a dependency on a file that is not listed."
- echo ""
- echo "If the error is \`cannot find 'X' in scope\`, add the file declaring \`X\`"
- echo "to \`algorithmModels\` or \`algorithmHelpers\` in \`Package.swift\`."
- } >> $GITHUB_STEP_SUMMARY
- fi
- shell: bash
- test:
- name: Run Unit Tests
- runs-on: macos-26
- if: github.repository_owner == 'nightscout'
- steps:
- - name: Select Xcode version
- run: sudo xcode-select -s /Applications/Xcode_26.2.app/Contents/Developer
- - name: Checkout code
- uses: actions/checkout@v5
- with:
- fetch-depth: 1
- submodules: recursive
- - name: Restore cache
- id: cache-restore
- uses: actions/cache/restore@v5
- with:
- path: |
- /Users/runner/Library/Developer/Xcode/DerivedData
- .build
- key: ${{ runner.os }}-trio-${{ hashFiles('**/*.swift', '**/*.xcodeproj', '**/*.xcworkspace') }}
- restore-keys: |
- ${{ runner.os }}-trio-
- - name: Show cache contents before build
- run: |
- echo "📂 Contents of DerivedData:"
- ls -lah /Users/runner/Library/Developer/Xcode/DerivedData || echo "Directory not found"
- echo ""
- echo "📂 Contents of .build:"
- ls -lah .build || echo ".build directory not found"
- - name: List available simulators
- run: xcrun simctl list devices available
- - name: Build for testing
- run: |
- set -o pipefail && \
- time xcodebuild build-for-testing \
- -workspace Trio.xcworkspace \
- -scheme "Trio Tests" \
- -destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' \
- - name: Check for uncommitted changes
- run: |
- CHANGES=$(git status --porcelain)
- if [ -n "$CHANGES" ]; then
- echo "Uncommitted changes detected:"
- echo "$CHANGES"
- echo "$CHANGES" | while read -r line; do
- FILE=$(echo $line | cut -c4-)
- echo "::warning file=$FILE::Uncommitted change detected"
- done
- exit 0
- else
- echo "No uncommitted changes detected."
- fi
- shell: bash
- - name: Show cache contents after build
- run: |
- echo "📂 Updated DerivedData contents:"
- du -sh /Users/runner/Library/Developer/Xcode/DerivedData || echo "Directory not found"
- ls -lah /Users/runner/Library/Developer/Xcode/DerivedData || echo "Directory not found"
- echo ""
- echo "📂 Updated .build contents:"
- du -sh .build || echo ".build directory not found"
- ls -lah .build || echo ".build directory not found"
-
- - name: Save cache
- if: steps.cache-restore.outputs.cache-hit != 'true'
- uses: actions/cache/save@v5
- with:
- path: |
- /Users/runner/Library/Developer/Xcode/DerivedData
- .build
- key: ${{ runner.os }}-trio-${{ hashFiles('**/*.swift', '**/*.xcodeproj', '**/*.xcworkspace') }}
- - name: Run tests
- run: |
- set -o pipefail
- time xcodebuild test-without-building \
- -workspace Trio.xcworkspace \
- -scheme "Trio Tests" \
- -destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' \
- $([ "$ENABLE_PARALLEL_TESTING" = "true" ] && echo "-parallel-testing-enabled YES") \
- 2>&1 | tee xcodebuild.log
- - name: Annotate test results
- if: always()
- run: |
- if [ -f xcodebuild.log ]; then
- if grep -q "Failing tests:" xcodebuild.log; then
- echo "::error title=Unit Tests Failed::Some tests failed"
- echo "## ❌ Some tests failed:" >> $GITHUB_STEP_SUMMARY
- grep -A 20 "Failing tests:" xcodebuild.log | \
- grep -E '^\s+[A-Za-z0-9]+\..+\(\)' | \
- sed 's/^/ - /' >> $GITHUB_STEP_SUMMARY
- echo "::group::Failed Test List"
- grep -A 20 "Failing tests:" xcodebuild.log | \
- grep -E '^\s+[A-Za-z0-9]+\..+\(\)' | \
- sed 's/^/ - /'
- echo "::endgroup::"
- else
- echo "::notice title=Unit Tests Passed::✅ All tests passed"
- echo "✅ All tests passed" >> $GITHUB_STEP_SUMMARY
- fi
- else
- echo "::warning::Test log (xcodebuild.log) not found"
- fi
|