From 06b0ae3c7a36c2b70b206abd1f743f5953b48e98 Mon Sep 17 00:00:00 2001 From: Alexey Alter-Pesotskiy Date: Mon, 25 Nov 2024 16:54:13 +0000 Subject: [PATCH] [CI] Make snapshot tests great again --- .github/workflows/e2e-build.yml | 1 + .github/workflows/e2e-test-cron.yml | 1 + .github/workflows/e2e-test.yml | 3 +- .github/workflows/snapshot-record.yaml | 39 -------------- .github/workflows/snapshot-test.yaml | 54 +++++++++++++++++++ .github/workflows/snapshot-tests.yaml | 36 ------------- .../io/getstream/chat/android/Dependencies.kt | 2 +- fastlane/Fastfile | 16 +++++- 8 files changed, 74 insertions(+), 78 deletions(-) delete mode 100644 .github/workflows/snapshot-record.yaml create mode 100644 .github/workflows/snapshot-test.yaml delete mode 100644 .github/workflows/snapshot-tests.yaml diff --git a/.github/workflows/e2e-build.yml b/.github/workflows/e2e-build.yml index f4bdc657d01..235b92113f3 100644 --- a/.github/workflows/e2e-build.yml +++ b/.github/workflows/e2e-build.yml @@ -21,6 +21,7 @@ jobs: key-prefix: gradle-test - name: Build apks run: bundle exec fastlane build_e2e_test + timeout-minutes: 30 - name: Upload apks uses: actions/upload-artifact@v4.4.3 with: diff --git a/.github/workflows/e2e-test-cron.yml b/.github/workflows/e2e-test-cron.yml index 76be02538e6..852bd909b79 100644 --- a/.github/workflows/e2e-test-cron.yml +++ b/.github/workflows/e2e-test-cron.yml @@ -57,6 +57,7 @@ jobs: cron: true - name: Run tests uses: reactivecircus/android-emulator-runner@v2 + timeout-minutes: 120 with: api-level: ${{ env.ANDROID_API_LEVEL }} disable-animations: true diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 07ff7722dc3..9b508514c1b 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -30,7 +30,7 @@ jobs: - batch: 0 - batch: 1 env: - ANDROID_API_LEVEL: 35 + ANDROID_API_LEVEL: 34 steps: - name: Connect Bot uses: webfactory/ssh-agent@v0.9.0 @@ -49,6 +49,7 @@ jobs: allure-token: ${{ secrets.ALLURE_TOKEN }} - name: Run tests uses: reactivecircus/android-emulator-runner@v2 + timeout-minutes: 45 with: api-level: ${{ env.ANDROID_API_LEVEL }} disable-animations: true diff --git a/.github/workflows/snapshot-record.yaml b/.github/workflows/snapshot-record.yaml deleted file mode 100644 index 5d3f2aa24ea..00000000000 --- a/.github/workflows/snapshot-record.yaml +++ /dev/null @@ -1,39 +0,0 @@ -name: Snapshot-Record - -on: workflow_dispatch - -jobs: - record_snapshots: - name: Record snapshots - runs-on: macos-latest - steps: - - name: Check out code - uses: actions/checkout@v3.1.0 - with: - ref: develop - - uses: ./.github/actions/setup-java - - uses: ./.github/actions/gradle-cache - with: - key-prefix: gradle-test - - name: Snapshot tests - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: 26 - disable-animations: true - profile: pixel - arch : x86_64 - emulator-options: ${{ vars.EMULATOR_OPTIONS }} - script: ./gradlew stream-chat-android-ui-uitests:executeScreenshotTests -Precord -Pandroid.testInstrumentationRunnerArguments.filter=io.getstream.chat.android.uitests.util.SnapshotTestFilter - - name: Upload screnshots - uses: actions/upload-artifact@v3.1.0 - with: - name: screenshots - path: ${{ github.workspace }}/stream-chat-android-ui-uitests/screenshots/ - - name: Create Pull Request - uses: peter-evans/create-pull-request@v4 - with: - commit-message: "Update screenshots" - title: "Update screenshots" - delete-branch: true - reviewers: GetStream/android-developers-ui - branch: update-screenshots diff --git a/.github/workflows/snapshot-test.yaml b/.github/workflows/snapshot-test.yaml new file mode 100644 index 00000000000..ae712b88caa --- /dev/null +++ b/.github/workflows/snapshot-test.yaml @@ -0,0 +1,54 @@ +name: Snapshot Tests + +on: + # pull_request: # FIXME: https://github.com/pedrovgs/Shot/issues/326 + + workflow_dispatch: + inputs: + record: + description: 'Should Snapshots be recorded on CI?' + type: boolean + required: false + default: false + +jobs: + run_snapshot_tests: + name: Run + runs-on: ubuntu-24.04 + steps: + - name: Check out code + uses: actions/checkout@v4.2.2 + - uses: ./.github/actions/setup-java + - uses: ./.github/actions/setup-ruby + - uses: ./.github/actions/gradle-cache + with: + key-prefix: gradle-test + + - name: Snapshot tests + uses: reactivecircus/android-emulator-runner@v2 + timeout-minutes: 60 + with: + api-level: 27 + disable-animations: true + profile: pixel + arch : x86_64 + emulator-options: ${{ vars.EMULATOR_OPTIONS }} + script: bundle exec fastlane run_snapshot_test record:${{ github.event.inputs.record }} + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v4.4.3 + continue-on-error: true + with: + name: report + path: ./**/build/reports/* + + - name: Create Pull Request + if: ${{ github.event.inputs.record == 'true' }} + uses: peter-evans/create-pull-request@v4 + with: + commit-message: "Update screenshots" + title: "Update screenshots" + delete-branch: true + reviewers: GetStream/android-developers-ui + branch: update-screenshots diff --git a/.github/workflows/snapshot-tests.yaml b/.github/workflows/snapshot-tests.yaml deleted file mode 100644 index baf1f4bd079..00000000000 --- a/.github/workflows/snapshot-tests.yaml +++ /dev/null @@ -1,36 +0,0 @@ -name: Snapshot-Test - -on: - workflow_dispatch: - schedule: - # Every midnight - - cron: '0 0 * * *' - -jobs: - run_snapshot_tests: - name: Verify snapshots - runs-on: macos-latest - steps: - - name: Check out code - uses: actions/checkout@v3.1.0 - with: - ref: develop - - uses: ./.github/actions/setup-java - - uses: ./.github/actions/gradle-cache - with: - key-prefix: gradle-test - - name: Snapshot tests - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: 26 - disable-animations: true - profile: pixel - arch : x86_64 - emulator-options: ${{ vars.EMULATOR_OPTIONS }} - script: ./gradlew stream-chat-android-ui-uitests:executeScreenshotTests -Pandroid.testInstrumentationRunnerArguments.filter=io.getstream.chat.android.uitests.util.SnapshotTestFilter - - name: Upload screnshot results - if: always() - uses: actions/upload-artifact@v3.1.0 - with: - name: screenshots_reports - path: ${{ github.workspace }}/stream-chat-android-ui-uitests/build/reports/* diff --git a/buildSrc/src/main/kotlin/io/getstream/chat/android/Dependencies.kt b/buildSrc/src/main/kotlin/io/getstream/chat/android/Dependencies.kt index 2b9c099c2f8..0cb34a89d13 100644 --- a/buildSrc/src/main/kotlin/io/getstream/chat/android/Dependencies.kt +++ b/buildSrc/src/main/kotlin/io/getstream/chat/android/Dependencies.kt @@ -76,7 +76,7 @@ object Versions { internal const val REORDERABLE = "2.4.0" internal const val ROOM = "2.6.1" internal const val SHIMMER = "0.5.0" - internal const val SHOT = "5.14.1" + internal const val SHOT = "6.1.0" internal const val SPOTLESS = "6.20.0" internal const val STREAM_LOG = "1.3.1" internal const val STREAM_PUSH = "1.1.9" diff --git a/fastlane/Fastfile b/fastlane/Fastfile index cb24f018640..7a99578df1f 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -34,6 +34,19 @@ lane :stop_mock_server do Net::HTTP.get_response(URI("http://localhost:#{mock_server_driver_port}/stop")) rescue nil end +lane :run_snapshot_test do |options| + next unless is_check_required(sources: sources_matrix[:ui], force_check: @force_check) + + cmd = [ + './gradlew', + 'stream-chat-android-ui-uitests:executeScreenshotTests', + '-Pandroid.testInstrumentationRunnerArguments.filter=io.getstream.chat.android.uitests.util.SnapshotTestFilter', + '-Dorg.gradle.jvmargs="--add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/java.nio.channels=ALL-UNNAMED --add-exports java.base/sun.nio.ch=ALL-UNNAMED"' + ] + cmd << '-Precord' unless options[:record].to_s.empty? + Dir.chdir('..') { sh(cmd.join(' ')) } +end + lane :build_and_run_e2e_test do |options| build_e2e_test run_e2e_test(batch: options[:batch], batch_count: options[:batch_count]) @@ -115,7 +128,8 @@ end private_lane :sources_matrix do { - e2e: ['buildSrc', 'stream-chat-android', '.github/workflows/e2e-tests'], + ui: ['stream-chat-android-ui', '.github/workflows/snapshot-test'], + e2e: ['buildSrc', 'stream-chat-android', '.github/workflows/e2e-test'], ruby: ['fastlane', 'Gemfile', 'Gemfile.lock'] } end