unit_tests.yml 4.4 KB

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