Skip to content
Merged
144 changes: 82 additions & 62 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,26 @@ references:
working_directory: ~/work
docker:
- image: cimg/android:2025.09
resource_class: medium+
resource_class: large

android_config_large: &android_config_large
working_directory: ~/work
docker:
- image: cimg/android:2025.09
resource_class: large
resource_class: xlarge

jobs:
compile:
<<: *android_config
steps:
- checkout
- run:
name: Generate combined build.gradle file for cache key
command: cat build.gradle */build.gradle */build.gradle.kts .circleci/config.yml gradle/libs.versions.toml > deps.txt
- restore_cache:
keys:
- compile-deps-{{ checksum "deps.txt" }}
- compile-deps-
- restore_cache:
keys:
- gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- compile-{{ checksum "gradle/libs.versions.toml" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- compile-
- run:
name: Copy gradle config
command: mkdir -p ~/.gradle && cp .circleci/gradle-compile.properties ~/.gradle/gradle.properties

command: mkdir -p ~/.gradle && cp .circleci/gradle.properties ~/.gradle/gradle.properties
- run:
name: Download Robolectric deps
command: ./download-robolectric-deps.sh
Expand All @@ -51,29 +44,30 @@ jobs:

- save_cache:
paths:
- ~/.gradle/caches
- ~/.gradle/wrapper
key: gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
key: compile-{{ checksum "gradle/libs.versions.toml" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- save_cache:
paths:
- ~/.gradle/caches/modules-2/files-2.1
key: compile-deps-{{ checksum "deps.txt" }}
- ~/work
Copy link
Copy Markdown
Member Author

@seadowg seadowg Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, saving to cache is much faster than persisting to workspace for large sets of files. Caching makes more sense here as well as we don't need the files we're saving here: they just help speed subsequent jobs in the worklow up.

key: workflow-{{ .Environment.CIRCLE_WORKFLOW_ID }}

- persist_to_workspace:
root: ~/work
paths:
- .
- collect_app/build/outputs/apk
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to save the APK so that it can be definitely available to the Test Lab jobs.


create_dependency_backup:
<<: *android_config
<<: *android_config_small
steps:
- attach_workspace:
at: ~/work
- checkout
- restore_cache:
keys:
- compile-deps-{{ checksum "deps.txt" }}
- compile-deps-
- workflow-{{ .Environment.CIRCLE_WORKFLOW_ID }}
- restore_cache:
keys:
- gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- compile-{{ checksum "gradle/libs.versions.toml" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- compile-

- run:
name: Create Maven repo from dependencies
Expand All @@ -85,21 +79,20 @@ jobs:
path: maven.tar

check_quality:
<<: *android_config_large
<<: *android_config
steps:
- attach_workspace:
at: ~/work
- checkout
- restore_cache:
keys:
- compile-deps-{{ checksum "deps.txt" }}
- compile-deps-
- workflow-{{ .Environment.CIRCLE_WORKFLOW_ID }}
- restore_cache:
keys:
- gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- compile-{{ checksum "gradle/libs.versions.toml" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- compile-

- run:
name: Copy gradle config
command: mkdir -p ~/.gradle && cp .circleci/gradle-large.properties ~/.gradle/gradle.properties
command: mkdir -p ~/.gradle && cp .circleci/gradle.properties ~/.gradle/gradle.properties

- run:
name: Run code quality checks
Expand All @@ -113,16 +106,16 @@ jobs:
<<: *android_config
parallelism: 4
steps:
- attach_workspace:
at: ~/work
- checkout
- restore_cache:
keys:
- test-modules-deps-{{ checksum "deps.txt" }}
- test-modules-deps-
- compile-deps-
- workflow-{{ .Environment.CIRCLE_WORKFLOW_ID }}
- restore_cache:
keys:
- gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- test_modules-{{ checksum "gradle/libs.versions.toml" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- test_modules
- compile-{{ checksum "gradle/libs.versions.toml" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- compile-

- run:
name: Copy gradle config
Expand All @@ -145,23 +138,24 @@ jobs:

- save_cache:
paths:
- ~/.gradle/caches/modules-2/files-2.1
key: test-modules-deps-{{ checksum "deps.txt" }}
- ~/.gradle/caches
- ~/.gradle/wrapper
key: test_modules-{{ checksum "gradle/libs.versions.toml" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}

test_app:
<<: *android_config
parallelism: 4
steps:
- attach_workspace:
at: ~/work
- checkout
- restore_cache:
keys:
- test-app-deps-{{ checksum "deps.txt" }}
- test-app-deps-
- compile-deps-
- workflow-{{ .Environment.CIRCLE_WORKFLOW_ID }}
- restore_cache:
keys:
- gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- test_app-{{ checksum "gradle/libs.versions.toml" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- test_app-
- compile-{{ checksum "gradle/libs.versions.toml" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- compile-

- run:
name: Copy gradle config
Expand Down Expand Up @@ -194,53 +188,54 @@ jobs:

- save_cache:
paths:
- ~/.gradle/caches/modules-2/files-2.1
key: test-app-deps-{{ checksum "deps.txt" }}
- ~/.gradle/caches
- ~/.gradle/wrapper
key: test_app-{{ checksum "gradle/libs.versions.toml" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}

build_instrumented:
<<: *android_config_large
steps:
- attach_workspace:
at: ~/work
- checkout
- restore_cache:
keys:
- intrumented-deps-{{ checksum "deps.txt" }}
- intrumented-deps-
- compile-deps-
- workflow-{{ .Environment.CIRCLE_WORKFLOW_ID }}
- restore_cache:
keys:
- gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- build_instrumented-{{ checksum "gradle/libs.versions.toml" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- build_instrumented-
- compile-{{ checksum "gradle/libs.versions.toml" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- compile-

- run:
name: Copy gradle config
command: mkdir -p ~/.gradle && cp .circleci/gradle-large.properties ~/.gradle/gradle.properties

- run:
name: Assemble connected test build
command: ./gradlew assembleDebug assembleDebugAndroidTest
command: ./gradlew assembleDebugAndroidTest

- save_cache:
paths:
- ~/.gradle/caches/modules-2/files-2.1
key: intrumented-deps-{{ checksum "deps.txt" }}
- ~/.gradle/caches
- ~/.gradle/wrapper
key: build_instrumented-{{ checksum "gradle/libs.versions.toml" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}

- persist_to_workspace:
root: ~/work
paths:
- .
- collect_app/build/outputs/apk

build_release:
<<: *android_config
steps:
- attach_workspace:
at: ~/work
- checkout
- restore_cache:
keys:
- compile-deps-{{ checksum "deps.txt" }}
- compile-deps
- workflow-{{ .Environment.CIRCLE_WORKFLOW_ID }}
- restore_cache:
keys:
- gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- compile-{{ checksum "gradle/libs.versions.toml" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- compile-

- run:
name: Copy gradle config
Expand All @@ -265,7 +260,7 @@ jobs:
if [[ -n "$GOOGLE_MAPS_API_KEY" ]]; then \
./check-size.sh 23117869
else
./check-size.sh 13785543
./check-size.sh 13841204
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this increase? It's a very small bump though.

fi

- run:
Expand All @@ -277,6 +272,10 @@ jobs:
test_smoke_instrumented:
<<: *android_config_small
steps:
- checkout
- restore_cache:
keys:
- workflow-{{ .Environment.CIRCLE_WORKFLOW_ID }}
- attach_workspace:
at: ~/work

Expand Down Expand Up @@ -306,6 +305,10 @@ jobs:
test_instrumented:
<<: *android_config_small
steps:
- checkout
- restore_cache:
keys:
- workflow-{{ .Environment.CIRCLE_WORKFLOW_ID }}
- attach_workspace:
at: ~/work

Expand Down Expand Up @@ -336,7 +339,24 @@ workflows:
version: 2
commit:
jobs:
- compile
- hold_pr:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I often find that I might be committing/pushing quickly and that context, CI will be constantly starting and cancelling workflow runs. Add a manual approval step means we only end up running jobs when we actually care about the result. I'd like to try this, but definitely let me know if you feel like it's getting annoying @grzesiek2010.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your rationale, but isn’t it possible to differentiate between draft and ready-for-review PRs and trigger jobs only for those that are ready for review?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! It looks like this might be possible with the new Github triggers, but I'm not sure that we'd be able to have it always run for non-drafts and optionally for drafts (you still probably want CI on request for drafts). We could always just use the GitHub API (probably through gh).

I think that's probably a future improvement though: I think we either go with the basic version as-is or remove the hold_pr check for now.

type: approval
filters:
branches:
ignore:
- master
- compile:
filters:
branches:
only:
- master
- compile:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have two jobs with the same name (compile)? Does it work or one replaces the other?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They both reference the compile job definition - this isn't declaring the job. One runs on master only and the other only on non-master.

requires:
- hold_pr
filters:
branches:
ignore:
- master
- check_quality:
requires:
- compile
Expand Down
5 changes: 0 additions & 5 deletions .circleci/gradle-compile.properties

This file was deleted.

7 changes: 4 additions & 3 deletions .circleci/gradle-large.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g
# Gradle config for "X-Large" Circle CI resource (https://circleci.com/pricing/price-list/)

org.gradle.jvmargs=-Xmx6g -XX:MaxMetaspaceSize=1g
org.gradle.daemon=false
org.gradle.parallel=true
org.gradle.workers.max=4
org.gradle.workers.max=8
test.heap.max=1g
kotlin.compiler.execution.strategy=in-process
5 changes: 3 additions & 2 deletions .circleci/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Gradle config for "Large" Circle CI resource (https://circleci.com/pricing/price-list/)

org.gradle.jvmargs=-Xmx2560m -XX:MaxMetaspaceSize=1g
org.gradle.daemon=false
org.gradle.parallel=true
org.gradle.workers.max=2
org.gradle.workers.max=4
test.heap.max=1g
kotlin.compiler.execution.strategy=in-process
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ android.useAndroidX=true
android.enableJetifier=true
#https://issuetracker.google.com/issues/283715193
android.jetifier.ignorelist = jackson-core
org.gradle.jvmargs=-Xmx1536m
org.gradle.jvmargs=-Xmx2560m -XX:MaxMetaspaceSize=1g
org.gradle.parallel=true
test.heap.max=1g
android.nonTransitiveRClass=true
Expand Down