unit_tests.yml 4.4 KB

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