unit_tests.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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-15
  24. if: github.repository_owner == 'nightscout'
  25. steps:
  26. - name: Select Xcode version
  27. run: sudo xcode-select -s /Applications/Xcode_16.3.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: Build for testing
  51. run: |
  52. set -o pipefail && \
  53. time xcodebuild build-for-testing \
  54. -workspace Trio.xcworkspace \
  55. -scheme "Trio Tests" \
  56. -destination 'platform=iOS Simulator,name=iPhone 16,OS=18.4' \
  57. - name: Check for uncommitted changes
  58. run: |
  59. CHANGES=$(git status --porcelain)
  60. if [ -n "$CHANGES" ]; then
  61. echo "Uncommitted changes detected:"
  62. echo "$CHANGES"
  63. echo "$CHANGES" | while read -r line; do
  64. FILE=$(echo $line | cut -c4-)
  65. echo "::warning file=$FILE::Uncommitted change detected"
  66. done
  67. exit 0
  68. else
  69. echo "No uncommitted changes detected."
  70. fi
  71. shell: bash
  72. - name: Show cache contents after build
  73. run: |
  74. echo "📂 Updated DerivedData contents:"
  75. du -sh /Users/runner/Library/Developer/Xcode/DerivedData || echo "Directory not found"
  76. ls -lah /Users/runner/Library/Developer/Xcode/DerivedData || echo "Directory not found"
  77. echo ""
  78. echo "📂 Updated .build contents:"
  79. du -sh .build || echo ".build directory not found"
  80. ls -lah .build || echo ".build directory not found"
  81. - name: Save cache
  82. if: steps.cache-restore.outputs.cache-hit != 'true'
  83. uses: actions/cache/save@v4
  84. with:
  85. path: |
  86. /Users/runner/Library/Developer/Xcode/DerivedData
  87. .build
  88. key: ${{ runner.os }}-trio-${{ hashFiles('**/*.swift', '**/*.xcodeproj', '**/*.xcworkspace') }}
  89. - name: Run tests
  90. run: |
  91. set -o pipefail
  92. time xcodebuild test-without-building \
  93. -workspace Trio.xcworkspace \
  94. -scheme "Trio Tests" \
  95. -destination 'platform=iOS Simulator,name=iPhone 16,OS=18.4' \
  96. $([ "$ENABLE_PARALLEL_TESTING" = "true" ] && echo "-parallel-testing-enabled YES") \
  97. 2>&1 | tee xcodebuild.log
  98. - name: Annotate test results
  99. if: always()
  100. run: |
  101. if [ -f xcodebuild.log ]; then
  102. if grep -q "Failing tests:" xcodebuild.log; then
  103. echo "::error title=Unit Tests Failed::Some tests failed"
  104. echo "## ❌ Some tests failed:" >> $GITHUB_STEP_SUMMARY
  105. grep -A 20 "Failing tests:" xcodebuild.log | \
  106. grep -E '^\s+[A-Za-z0-9]+\..+\(\)' | \
  107. sed 's/^/ - /' >> $GITHUB_STEP_SUMMARY
  108. echo "::group::Failed Test List"
  109. grep -A 20 "Failing tests:" xcodebuild.log | \
  110. grep -E '^\s+[A-Za-z0-9]+\..+\(\)' | \
  111. sed 's/^/ - /'
  112. echo "::endgroup::"
  113. else
  114. echo "::notice title=Unit Tests Passed::✅ All tests passed"
  115. echo "✅ All tests passed" >> $GITHUB_STEP_SUMMARY
  116. fi
  117. else
  118. echo "::warning::Test log (xcodebuild.log) not found"
  119. fi