|
6 | 6 | description: "Swift package location"
|
7 | 7 | required: true
|
8 | 8 | type: string
|
| 9 | + TEST_SCHEME: |
| 10 | + description: "Test scheme of the swift package" |
| 11 | + required: true |
| 12 | + type: string |
9 | 13 | SONAR_URL:
|
10 | 14 | required: false
|
11 | 15 | type: string
|
@@ -67,24 +71,34 @@ jobs:
|
67 | 71 | run: |
|
68 | 72 | cd ${{ inputs.SERVICE_LOCATION }}
|
69 | 73 |
|
70 |
| - # Check if Tests directory exists and is not empty |
71 |
| - if [ -d "Tests" ] && [ "$(ls -A Tests)" ]; then |
72 |
| - swift test --enable-code-coverage |
73 |
| -
|
74 |
| - # Verify coverage data exists before merging |
75 |
| - if [ ! -f .build/debug/codecov/default.profdata ]; then |
76 |
| - echo "Error: Coverage data file (.profdata) not found!" |
77 |
| - exit 1 |
| 74 | + # Ensure Tests directory exists (to prevent SonarQube errors) |
| 75 | + if [ ! -d "Tests" ]; then |
| 76 | + echo "Tests directory is missing. Creating an empty Tests directory." |
| 77 | + mkdir Tests |
78 | 78 | fi
|
79 | 79 |
|
80 |
| - # Merging coverage data |
81 |
| - xcrun llvm-profdata merge -sparse .build/debug/codecov/default.profdata -o .build/debug/codecov/profdata.profdata |
| 80 | + # Check if Tests directory exists and is not empty |
| 81 | + if [ -d "Tests" ] && [ "$(ls -A Tests)" ]; then |
| 82 | + |
| 83 | + # Run tests |
| 84 | + xcodebuild test \ |
| 85 | + -scheme "${{ inputs.TEST_SCHEME }}" \ |
| 86 | + -destination 'platform=iOS Simulator,OS=latest,name=iPhone 15' \ |
| 87 | + -enableCodeCoverage YES |
| 88 | +
|
| 89 | + # Find test bundle and executable |
| 90 | + TEST_BUNDLE=$(find ~/Library/Developer/Xcode/DerivedData -type d -name "*.xctest" | head -n 1) |
| 91 | + TEST_EXECUTABLE=$(find "$TEST_BUNDLE" -type f -perm -111 | head -n 1) |
| 92 | + COVERAGE_PATH=$(find ~/Library/Developer/Xcode/DerivedData -name "Coverage.profdata" | head -n 1) |
82 | 93 |
|
83 |
| - # Generating coverage report |
84 |
| - xcrun --run llvm-cov show -instr-profile=.build/debug/codecov/profdata.profdata .build/debug/*PackageTests.xctest/Contents/MacOS/*PackageTests > coverage.report |
| 94 | + # Generate coverage report |
| 95 | + xcrun llvm-cov show \ |
| 96 | + -instr-profile="$COVERAGE_PATH" \ |
| 97 | + "$TEST_EXECUTABLE" \ |
| 98 | + -format=text > coverage.report |
85 | 99 | else
|
86 |
| - echo "No tests found. Creating empty coverage report for sonar." |
87 |
| - touch coverage.report |
| 100 | + echo "No tests found. Creating empty coverage report for SonarQube." |
| 101 | + touch coverage.report |
88 | 102 | fi
|
89 | 103 |
|
90 | 104 | - name: Run Sonar Analysis
|
|
0 commit comments