Add code coverage #555
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 | |
| on: | |
| push: | |
| branches: | |
| - master | |
| tags: | |
| - '[0-9]+.[0-9]+.[0-9]+*' | |
| pull_request: | |
| workflow_dispatch: | |
| jobs: | |
| format: | |
| name: Format | |
| runs-on: ubuntu-latest | |
| container: ghcr.io/cirruslabs/flutter:3.22.3 | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Check format | |
| run: scripts/check_format.sh | |
| lint: | |
| name: Lint | |
| runs-on: ubuntu-latest | |
| container: ghcr.io/cirruslabs/flutter:3.22.3 | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Get dependencies | |
| run: flutter pub get | |
| - name: Lint using flutter analyze | |
| run: flutter analyze | |
| - name: Assert that every file that should be public has been exported | |
| run: scripts/assert_export.sh | |
| pub-dry-run: | |
| name: Publish Dry Run | |
| runs-on: ubuntu-latest | |
| container: ghcr.io/cirruslabs/flutter:3.22.3 | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Run publish dry run | |
| run: flutter pub publish --dry-run | |
| test-flutter: | |
| name: Test Flutter | |
| needs: [ lint, format, pub-dry-run ] | |
| runs-on: ubuntu-latest | |
| container: ghcr.io/cirruslabs/flutter:3.22.3 | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install lcov | |
| run: sudo apt-get update && sudo apt-get install -y lcov | |
| - name: Get dependencies | |
| run: flutter pub get | |
| - name: Run all tests | |
| run: flutter test --reporter=expanded --coverage | |
| - name: Check coverage | |
| run: dart scripts/check_coverage.dart coverage/lcov.info | |
| - name: Generate HTML report | |
| run: genhtml coverage/lcov.info -o coverage/html | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: flutter-coverage-report | |
| path: coverage/html | |
| test-android: | |
| name: Test Android | |
| needs: [ lint, format, pub-dry-run ] | |
| runs-on: ubuntu-latest | |
| container: ghcr.io/cirruslabs/flutter:3.22.3 | |
| timeout-minutes: 20 | |
| env: | |
| GRADLE_VERSION: 8.7 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Cache Gradle | |
| id: cache-gradle | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ./example/android/ci-cache/gradle | |
| ./example/android/gradle/wrapper/gradle-wrapper.jar | |
| ./example/android/gradlew | |
| key: ${{ runner.os }}-cache-gradle-${{ env.GRADLE_VERSION }} | |
| - name: Get dependencies | |
| run: flutter pub get | |
| - name: Setup Gradle | |
| if: steps.cache-gradle.outputs.cache-hit != 'true' | |
| working-directory: ./example/android | |
| run: ../../scripts/setup_gradle.sh ${{ env.GRADLE_VERSION }} | |
| - name: Validate Gradle | |
| working-directory: ./example/android | |
| run: dart ../../scripts/check_gradle_version.dart | |
| - name: Run all tests and coverage | |
| working-directory: ./example/android | |
| run: ./gradlew :usercentrics_sdk:testDebugUnitTest :usercentrics_sdk:koverHtmlReportDebug | |
| - name: List coverage files | |
| working-directory: ./example | |
| run: find build -name "*.html" -o -name "index.html" | head -20 | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: android-coverage-report | |
| path: example/build/usercentrics_sdk/reports/kover/htmlDebug | |
| test-ios: | |
| name: Test iOS | |
| needs: [ lint, format, pub-dry-run ] | |
| runs-on: macos-13 | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Setup code | |
| uses: maxim-lobanov/setup-xcode@v1 | |
| with: | |
| xcode-version: '14.2' | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install xcov | |
| run: gem install xcov | |
| - name: Setup Flutter | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: '3.22.3' | |
| channel: 'stable' | |
| - name: Get dependencies | |
| run: flutter pub get | |
| - name: Setup Pods | |
| working-directory: ./example/ios | |
| run: pod install | |
| - name: Run all tests | |
| working-directory: ./example/ios | |
| run: ../../scripts/ios_unit_tests.sh | |
| - name: List test results | |
| working-directory: ./example/ios | |
| run: ls -la TestResults.xcresult || echo "No test results found" | |
| - name: Generate HTML report | |
| working-directory: ./example/ios | |
| run: xcov --scheme Runner --workspace Runner.xcworkspace --output_directory html_report --include_targets usercentrics_sdk.framework | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ios-coverage-report | |
| path: example/ios/html_report | |
| build-android: | |
| name: Build Android Example | |
| needs: [ lint, format, pub-dry-run ] | |
| runs-on: ubuntu-latest | |
| container: ghcr.io/cirruslabs/flutter:3.22.3 | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Get dependencies | |
| run: flutter pub get | |
| - name: Build | |
| working-directory: ./example | |
| run: flutter build apk | |
| build-ios: | |
| name: Build iOS Example | |
| needs: [ lint, format, pub-dry-run ] | |
| runs-on: macos-13 | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Setup code | |
| uses: maxim-lobanov/setup-xcode@v1 | |
| with: | |
| xcode-version: '14.2' | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Flutter | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: '3.22.3' | |
| channel: 'stable' | |
| - name: Get dependencies | |
| run: flutter pub get | |
| - name: Build | |
| working-directory: ./example | |
| run: flutter build ios --debug --no-codesign --simulator | |
| # https://dart.dev/tools/pub/automated-publishing | |
| release: | |
| name: Release | |
| permissions: | |
| id-token: write | |
| if: startsWith(github.ref, 'refs/tags/') | |
| needs: [ test-flutter, test-android, test-ios, build-android, build-ios ] | |
| runs-on: ubuntu-latest | |
| container: ghcr.io/cirruslabs/flutter:3.22.3 | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Validate version | |
| run: dart scripts/check_release_version.dart ${{ github.ref }} | |
| - name: Set publishing token | |
| uses: dart-lang/setup-dart@v1 | |
| - name: Get dependencies | |
| run: flutter pub get | |
| - name: Publish | |
| run: flutter pub publish -f |