Add coverage reports for UNIT tests #462
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: CI/CD | |
| env: | |
| NODE_JS_VERSION: 20.19.5 | |
| on: | |
| pull_request: | |
| branches: | |
| - master | |
| workflow_dispatch: | |
| jobs: | |
| test-rn: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v1 | |
| - name: Use Node.js "$NODE_JS_VERSION" | |
| uses: actions/setup-node@v2 | |
| with: | |
| node-version: ${{ env.NODE_JS_VERSION }} | |
| - name: Install Dependencies | |
| run: yarn install --frozen-lockfile | |
| - name: Install TypeScript | |
| run: yarn add --dev typescript@^5.6.3 | |
| - name: Compile TypeScript | |
| run: yarn compile | |
| - name: Run Tests | |
| run: yarn test | |
| - name: Upload coverage reports | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: coverage/ | |
| - name: Assert that every file that should be public has been exported | |
| run: ./scripts/assert_export.sh | |
| test-ios: | |
| needs: test-rn | |
| runs-on: macos-14 | |
| env: | |
| RCT_NEW_ARCH_ENABLED: 0 | |
| RCT_NO_LAUNCH_PACKAGER: 1 | |
| USE_METRO_BUNDLER: 0 | |
| FORCE_BUNDLING: 1 | |
| steps: | |
| - uses: maxim-lobanov/setup-xcode@v1 | |
| with: | |
| xcode-version: '16.1' | |
| - name: Checkout | |
| uses: actions/checkout@v2 | |
| - name: Setup Node | |
| uses: actions/setup-node@v2 | |
| with: | |
| node-version: ${{ env.NODE_JS_VERSION }} | |
| - name: Setup Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: '3.2' | |
| bundler-cache: true # Caches gems | |
| - name: Install SDK Dependencies | |
| run: yarn install --frozen-lockfile | |
| - name: Compile SDK | |
| run: yarn compile | |
| - name: Install Sample Dependencies | |
| working-directory: ./sample | |
| run: npm ci --legacy-peer-deps | |
| - name: Bundle install (Ruby gems) | |
| working-directory: ./sample | |
| run: | | |
| bundle config set path 'vendor/bundle' | |
| bundle install --jobs 4 --retry 3 | |
| - name: Install pods (via bundler) | |
| working-directory: ./sample/ios | |
| run: | | |
| pod deintegrate | |
| pod cache clean --all | |
| bundle exec pod install --repo-update | |
| - name: Clean Xcode Build Artifacts | |
| run: | | |
| rm -rf ~/Library/Developer/Xcode/DerivedData/* | |
| - name: Run tests | |
| working-directory: ./sample/ios | |
| run: | | |
| set -o pipefail && \ | |
| xcodebuild \ | |
| -workspace sample.xcworkspace \ | |
| -scheme "sample" \ | |
| -sdk iphonesimulator \ | |
| -destination 'platform=iOS Simulator,OS=latest,name=iPhone 16 Pro' \ | |
| -enableCodeCoverage YES \ | |
| -resultBundlePath TestResults.xcresult \ | |
| -only-testing:sampleTests \ | |
| test | bundle exec xcpretty && exit ${PIPESTATUS[0]} | |
| - name: Install Slather | |
| run: gem install slather | |
| - name: Generate iOS HTML Report | |
| working-directory: ./sample/ios | |
| run: | | |
| slather coverage --html --output-directory html-report --scheme sample --workspace sample.xcworkspace sample.xcodeproj | |
| - name: Upload iOS coverage | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ios-coverage | |
| path: | | |
| sample/ios/TestResults.xcresult | |
| sample/ios/html-report/ | |
| test-android: | |
| needs: test-rn | |
| runs-on: macOS-13 | |
| env: | |
| GRADLE_VERSION: 8.13 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v2 | |
| with: | |
| node-version: ${{ env.NODE_JS_VERSION }} | |
| - name: Java 17 | |
| uses: actions/setup-java@v1 | |
| with: | |
| java-version: 17 | |
| - name: Install SDK Dependencies | |
| run: yarn install --frozen-lockfile | |
| - name: Compile SDK | |
| run: yarn compile | |
| - name: Install Sample Dependencies (needed for Gradle build) | |
| working-directory: ./sample | |
| run: npm ci --legacy-peer-deps | |
| - name: Run SDK Unit Tests | |
| working-directory: ./sample/android | |
| run: ./gradlew :react-native-usercentrics:koverXmlReport :react-native-usercentrics:koverHtmlReport | |
| - name: Upload Android coverage | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: android-coverage | |
| path: android/build/reports/kover/ |