unit_tests.yml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. name: zzz [DO NOT RUN] Automated unit tests
  2. on:
  3. workflow_dispatch: # Allow manual trigger for debugging
  4. pull_request:
  5. branches:
  6. - dev
  7. types: [opened, synchronize]
  8. paths-ignore:
  9. - '**.md'
  10. - '**/README'
  11. - '**.yml'
  12. - '**.txt'
  13. push:
  14. branches:
  15. - dev
  16. paths-ignore:
  17. - '**.md'
  18. - '**/README'
  19. - '**.yml'
  20. - '**.txt'
  21. jobs:
  22. test:
  23. name: Run Unit Tests
  24. runs-on: macos-26
  25. if: github.repository_owner == 'nightscout'
  26. steps:
  27. - name: Select Xcode version
  28. run: sudo xcode-select -s /Applications/Xcode_26.2.app/Contents/Developer
  29. - name: Checkout code
  30. uses: actions/checkout@v4
  31. with:
  32. fetch-depth: 1
  33. submodules: recursive
  34. - name: Restore cache
  35. id: cache-restore
  36. uses: actions/cache/restore@v4
  37. with:
  38. path: |
  39. /Users/runner/Library/Developer/Xcode/DerivedData
  40. .build
  41. key: ${{ runner.os }}-trio-${{ hashFiles('**/*.swift', '**/*.xcodeproj', '**/*.xcworkspace') }}
  42. restore-keys: |
  43. ${{ runner.os }}-trio-
  44. - name: Show cache contents before build
  45. run: |
  46. echo "📂 Contents of DerivedData:"
  47. ls -lah /Users/runner/Library/Developer/Xcode/DerivedData || echo "Directory not found"
  48. echo ""
  49. echo "📂 Contents of .build:"
  50. ls -lah .build || echo ".build directory not found"
  51. - name: List available simulators
  52. run: xcrun simctl list devices available
  53. - name: Build for testing
  54. run: |
  55. set -o pipefail && \
  56. time xcodebuild build-for-testing \
  57. -workspace Trio.xcworkspace \
  58. -scheme "Trio Tests" \
  59. -destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' \
  60. - name: Check for uncommitted changes
  61. run: |
  62. CHANGES=$(git status --porcelain)
  63. if [ -n "$CHANGES" ]; then
  64. echo "Uncommitted changes detected:"
  65. echo "$CHANGES"
  66. echo "$CHANGES" | while read -r line; do
  67. FILE=$(echo $line | cut -c4-)
  68. echo "::warning file=$FILE::Uncommitted change detected"
  69. done
  70. exit 0
  71. else
  72. echo "No uncommitted changes detected."
  73. fi
  74. shell: bash
  75. - name: Show cache contents after build
  76. run: |
  77. echo "📂 Updated DerivedData contents:"
  78. du -sh /Users/runner/Library/Developer/Xcode/DerivedData || echo "Directory not found"
  79. ls -lah /Users/runner/Library/Developer/Xcode/DerivedData || echo "Directory not found"
  80. echo ""
  81. echo "📂 Updated .build contents:"
  82. du -sh .build || echo ".build directory not found"
  83. ls -lah .build || echo ".build directory not found"
  84. - name: Save cache
  85. if: steps.cache-restore.outputs.cache-hit != 'true'
  86. uses: actions/cache/save@v4
  87. with:
  88. path: |
  89. /Users/runner/Library/Developer/Xcode/DerivedData
  90. .build
  91. key: ${{ runner.os }}-trio-${{ hashFiles('**/*.swift', '**/*.xcodeproj', '**/*.xcworkspace') }}
  92. - name: Run tests
  93. run: |
  94. set -o pipefail
  95. time xcodebuild test-without-building \
  96. -workspace Trio.xcworkspace \
  97. -scheme "Trio Tests" \
  98. -destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' \
  99. $([ "$ENABLE_PARALLEL_TESTING" = "true" ] && echo "-parallel-testing-enabled YES") \
  100. 2>&1 | tee xcodebuild.log
  101. - name: Annotate test results
  102. if: always()
  103. run: |
  104. if [ -f xcodebuild.log ]; then
  105. if grep -q "Failing tests:" xcodebuild.log; then
  106. echo "::error title=Unit Tests Failed::Some tests failed"
  107. echo "## ❌ Some tests failed:" >> $GITHUB_STEP_SUMMARY
  108. grep -A 20 "Failing tests:" xcodebuild.log | \
  109. grep -E '^\s+[A-Za-z0-9]+\..+\(\)' | \
  110. sed 's/^/ - /' >> $GITHUB_STEP_SUMMARY
  111. echo "::group::Failed Test List"
  112. grep -A 20 "Failing tests:" xcodebuild.log | \
  113. grep -E '^\s+[A-Za-z0-9]+\..+\(\)' | \
  114. sed 's/^/ - /'
  115. echo "::endgroup::"
  116. else
  117. echo "::notice title=Unit Tests Passed::✅ All tests passed"
  118. echo "✅ All tests passed" >> $GITHUB_STEP_SUMMARY
  119. fi
  120. else
  121. echo "::warning::Test log (xcodebuild.log) not found"
  122. fi