Testing Code Coverage Workflows and Plugins #46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Run Unit Tests | |
| on: | |
| pull_request: | |
| jobs: | |
| test: | |
| runs-on: macos-15 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Select Xcode and show Swift version | |
| run: | | |
| sudo xcode-select -s /Applications/Xcode_16.1.app/Contents/Developer | |
| swift --version | |
| - name: Install CocoaPods dependencies | |
| run: pod install | |
| - name: Run Tests | |
| run: | | |
| xcodebuild test \ | |
| -workspace CleverTapSDK.xcworkspace \ | |
| -scheme CleverTapSDKTests \ | |
| -configuration Debug \ | |
| -destination 'platform=iOS Simulator,name=iPhone 16 Pro,OS=18.0' \ | |
| -enableCodeCoverage YES \ | |
| -quiet | |
| - name: Install Slather | |
| run: gem install slather | |
| if: success() || failure() | |
| - name: Generate Coverage Report with Slather | |
| run: | | |
| mkdir -p coverage | |
| slather coverage \ | |
| --cobertura-xml \ | |
| --scheme CleverTapSDK \ | |
| --workspace CleverTapSDK.xcworkspace \ | |
| --output-directory coverage \ | |
| CleverTapSDK.xcodeproj | |
| if: success() || failure() | |
| - name: Debug - Check coverage files | |
| run: | | |
| echo "Contents of coverage directory:" | |
| ls -la coverage/ | |
| if: success() || failure() | |
| - name: Upload Coverage XML Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-xml | |
| path: coverage/cobertura.xml | |
| if: success() || failure() | |
| summary: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: success() || failure() | |
| permissions: | |
| pull-requests: write | |
| checks: write | |
| contents: read | |
| actions: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download Coverage Artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: coverage-xml | |
| - name: Generate Markdown Coverage Summary | |
| uses: irongut/[email protected] | |
| with: | |
| filename: 'cobertura.xml' | |
| badge: true | |
| fail_below_min: false | |
| hide_complexity: true | |
| indicators: false | |
| format: markdown | |
| output: both | |
| - name: PR Coverage Report (Changed Files) | |
| uses: 5monkeys/cobertura-action@master | |
| if: github.event_name == 'pull_request' | |
| with: | |
| path: cobertura.xml | |
| minimum_coverage: 50 | |
| show_missing: true | |
| only_changed_files: true | |
| fail_below_threshold: false | |
| - name: Add PR Comment | |
| uses: marocchino/sticky-pull-request-comment@v2 | |
| if: github.event_name == 'pull_request' | |
| with: | |
| hide_and_recreate: true | |
| path: code-coverage-results.md | |
| header: overall-coverage |