Skip to content

Commit

Permalink
Fix CI emulator tests (#1176)
Browse files Browse the repository at this point in the history
- The recent change to `macos-14` means that we can't use x64 emulator
(as currently set). Ideally we would just use ARM64 emulators, but that
is blocked by
ReactiveCircus/android-emulator-runner#350
though.

- Instead I've refactored the CI setup:
- Moved most things to run `ubuntu-latest`. We can use the new
nested-virt KVM support to make the emulator fast there.
- We still use `macos-14` but only for iOS builds in a separate job.
This is similar to what I do in Tivi.
- Add some hierarchy to the jobs, so that `publish` only happens when
all of the other jobs pass.

- Benchmark tests do not work (by default) on emulators, which is why
they've been failing for a while. We can suppress that error and get
them to run but there's little benefit, so it's better to just disable
them when running on an emulator.
  • Loading branch information
chrisbanes authored Feb 2, 2024
1 parent fa114cc commit 045bd6b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 24 deletions.
101 changes: 77 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ concurrency:

jobs:
build:
# Necessary to run full tests to cover iOS too
runs-on: macos-14
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -32,15 +31,6 @@ jobs:
distribution: 'zulu'
java-version: '21'

- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: '3.2.2'

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '15.2'

- name: Setup Gradle cache
uses: gradle/gradle-build-action@v2
with:
Expand All @@ -53,7 +43,6 @@ jobs:
./gradlew --continue --no-configuration-cache \
check \
:samples:star:apk:assembleDebug \
:samples:counter:linkReleaseFrameworkIosX64 \
detektMain \
detektTest \
assembleAndroidTest
Expand All @@ -63,14 +52,6 @@ jobs:
run: |
./gradlew :samples:star:jvmJar -Pcircuit.buildDesktop
- run: brew install swiftlint

- name: Run lint on iOS samples
run: bundle exec fastlane ios lint

- name: Build iOS samples
run: bundle exec fastlane ios build

# Defer these until after the above run, no need to waste resources running them if there are other failures first
- name: Run instrumentation tests via emulator.wtf (main repo only)
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
Expand All @@ -79,6 +60,12 @@ jobs:
EW_API_TOKEN: ${{ secrets.EMULATOR_WTF_TOKEN }}
run: ./gradlew testReleaseWithEmulatorWtf

- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
# Forks cannot run emulator.wtf tests due to not being able to use repo secrets, so for them
# we run the tests via the android-emulator-runner action instead
- name: Run instrumentation tests via local emulator (from forks only)
Expand All @@ -92,7 +79,9 @@ jobs:
disable-animations: true
disk-size: 6000M
heap-size: 600M
script: ./gradlew ciConnectedCheck --daemon
script: |
# Disable benchmark tests as they do not work on emulators
./gradlew ciConnectedCheck -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=none
- name: (Fail-only) Upload reports
if: failure()
Expand All @@ -102,9 +91,49 @@ jobs:
path: |
**/build/reports/**
- name: Publish snapshot (main branch only)
if: github.repository == 'slackhq/circuit' && github.ref == 'refs/heads/main'
run: ./gradlew publish -PmavenCentralUsername=${{ secrets.SONATYPEUSERNAME }} -PmavenCentralPassword=${{ secrets.SONATYPEPASSWORD }} --no-configuration-cache
build-ios:
runs-on: macos-14

steps:
- name: Checkout
uses: actions/checkout@v4
with:
lfs: 'true'

- name: Install JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '21'

- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: '3.2.2'

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '15.2'

- name: Setup Gradle cache
uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true
cache-read-only: false

- run: brew install swiftlint

- name: Run lint on iOS samples
run: bundle exec fastlane ios lint

- name: Run iOS Simulator tests
id: gradle-ios-tests
run: |
./gradlew --continue --no-configuration-cache \
iosSimulatorArm64Test
- name: Build iOS samples
run: bundle exec fastlane ios build

snapshots:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -139,3 +168,27 @@ jobs:
path: |
**/build/reports/**
**/src/test/snapshots/**/*_compare.png
publish:
runs-on: ubuntu-latest
needs: [build, build-ios, snapshots]
if: github.repository == 'slackhq/circuit' && github.ref == 'refs/heads/main'

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '21'

- name: Setup Gradle cache
uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true
cache-read-only: false

- name: Publish snapshot (main branch only)
run: ./gradlew publish -PmavenCentralUsername=${{ secrets.SONATYPEUSERNAME }} -PmavenCentralPassword=${{ secrets.SONATYPEPASSWORD }} --no-configuration-cache
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ dependency.analysis.compatibility=NONE
kotlin.mpp.stability.nowarn=true
kotlin.mpp.androidSourceSetLayoutVersion=2
kotlin.mpp.androidGradlePluginCompatibility.nowarn=true
# Ignore disabled targets (i.e iOS on Linux)
kotlin.native.ignoreDisabledTargets=true

# https://kotlinlang.org/docs/ksp-multiplatform.html#avoid-the-ksp-configuration-on-ksp-1-0-1
systemProp.allowAllTargetConfiguration=false
Expand Down

0 comments on commit 045bd6b

Please sign in to comment.