Skip to content

Commit 00a2ef0

Browse files
authored
Merge pull request #1025 from square/rick/connected_check_shards
use delegating shard tasks for `connectedCheck`
2 parents 934949d + 0c0cbb3 commit 00a2ef0

File tree

11 files changed

+730
-206
lines changed

11 files changed

+730
-206
lines changed

.github/actions/gradle-task/action.yml

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ runs :
4141
cache-read-only : false
4242
gradle-home-cache-cleanup : true
4343

44+
# Calculate all the hashes for keys just one time.
45+
# These should only be referenced before the actual task action, since that action
46+
# may generate changes and we want the final cache key to reflect its current state.
47+
- name : Calculate hashes
48+
id : hashes
49+
shell: bash
50+
run : |
51+
echo "lib_versions=${{ hashFiles('**/libs.versions.toml') }}" >> $GITHUB_OUTPUT
52+
echo "gradle_props=${{ hashFiles('**/gradle.properties') }}" >> $GITHUB_OUTPUT
53+
echo "gradle_kts=${{ hashFiles('**/*.gradle.kts') }}" >> $GITHUB_OUTPUT
54+
echo "src_kt=${{ hashFiles('**/src/**/*.kt') }}" >> $GITHUB_OUTPUT
55+
4456
# Attempt to restore from the write-cache-key, or fall back to a partial match for the write key.
4557
# Skipped if the write-cache-key wasn't set.
4658
# This step's "cache_hit" output will only be true if an exact match was found.
@@ -51,9 +63,15 @@ runs :
5163
with :
5264
path : |
5365
~/.gradle/caches/build-cache-1
54-
./**/build/**
55-
key : ${{runner.os}}-${{inputs.write-cache-key}}-${{hashFiles('**/*.gradle.kt*')}}-${{hashFiles('**/libs.versions.toml')}}-${{hashFiles('**/gradle.properties')}}
56-
restore-keys : ${{runner.os}}-${{inputs.write-cache-key}}
66+
~/.konan
67+
./**/build
68+
./**/.gradle
69+
key : ${{runner.os}}-${{inputs.write-cache-key}}-${{steps.hashes.outputs.lib_versions}}-${{steps.hashes.outputs.gradle_props}}-${{steps.hashes.outputs.gradle_kts}}-${{steps.hashes.outputs.src_kt}}
70+
restore-keys : |
71+
${{runner.os}}-${{inputs.write-cache-key}}-${{steps.hashes.outputs.lib_versions}}-${{steps.hashes.outputs.gradle_props}}-${{steps.hashes.outputs.gradle_kts}}
72+
${{runner.os}}-${{inputs.write-cache-key}}-${{steps.hashes.outputs.lib_versions}}-${{steps.hashes.outputs.gradle_props}}
73+
${{runner.os}}-${{inputs.write-cache-key}}-${{steps.hashes.outputs.lib_versions}}
74+
${{runner.os}}-${{inputs.write-cache-key}}
5775
5876
# Attempt to restore from the restore-cache-key, or fall back to a partial match for the restore key.
5977
# Skipped if the restore-cache-key wasn't set, or if the write-cache-key restore had an exact match.
@@ -63,9 +81,15 @@ runs :
6381
with :
6482
path : |
6583
~/.gradle/caches/build-cache-1
66-
./**/build/**
67-
key : ${{runner.os}}-${{inputs.restore-cache-key}}-${{hashFiles('**/*.gradle.kt*')}}-${{hashFiles('**/libs.versions.toml')}}-${{hashFiles('**/gradle.properties')}}
68-
restore-keys : ${{runner.os}}-${{inputs.restore-cache-key}}
84+
~/.konan
85+
./**/build
86+
./**/.gradle
87+
key : ${{runner.os}}-${{inputs.restore-cache-key}}-${{steps.hashes.outputs.lib_versions}}-${{steps.hashes.outputs.gradle_props}}-${{steps.hashes.outputs.gradle_kts}}-${{steps.hashes.outputs.src_kt}}
88+
restore-keys : |
89+
${{runner.os}}-${{inputs.restore-cache-key}}-${{steps.hashes.outputs.lib_versions}}-${{steps.hashes.outputs.gradle_props}}-${{steps.hashes.outputs.gradle_kts}}
90+
${{runner.os}}-${{inputs.restore-cache-key}}-${{steps.hashes.outputs.lib_versions}}-${{steps.hashes.outputs.gradle_props}}
91+
${{runner.os}}-${{inputs.restore-cache-key}}-${{steps.hashes.outputs.lib_versions}}
92+
${{runner.os}}-${{inputs.restore-cache-key}}
6993
7094
- uses : gradle/wrapper-validation-action@v1
7195

@@ -92,8 +116,10 @@ runs :
92116
with :
93117
path : |
94118
~/.gradle/caches/build-cache-1
95-
./**/build/**
96-
key : ${{runner.os}}-${{inputs.write-cache-key}}-${{hashFiles('**/*.gradle.kt*')}}-${{hashFiles('**/libs.versions.toml')}}-${{hashFiles('**/gradle.properties')}}
119+
~/.konan
120+
./**/build
121+
./**/.gradle
122+
key : ${{runner.os}}-${{inputs.write-cache-key}}-${{hashFiles('**/libs.versions.toml')}}-${{hashFiles('**/gradle.properties')}}-${{hashFiles('**/*.gradle.kts')}}-${{hashFiles('**/src/**/*.kt')}}
97123

98124
- name : Upload heap dump
99125
if : failure()
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name : Run Android Instrumentation Tests with Artifact and AVD Caching
2+
description: This action sets up Gradle, runs a preparatory task, runs Android tests on an emulator, and uploads test results.
3+
4+
inputs:
5+
prepare-task:
6+
description: 'Gradle task for preparing necessary artifacts. Supports multi-line input.'
7+
required: true
8+
test-task:
9+
description: 'Gradle task for running instrumentation tests. Supports multi-line input.'
10+
required: true
11+
api-level :
12+
description : 'The Android SDK api level, like `29`'
13+
required : true
14+
build-root-directory :
15+
description : 'Path to the root directory of the build'
16+
required : false
17+
java-version :
18+
description : 'The Java version to set up.'
19+
default : '11'
20+
distribution :
21+
description : 'The JDK distribution to use.'
22+
default : 'zulu'
23+
restore-cache-key :
24+
description : 'The unique identifier for the associated cache. Any other consumers or producers for this cache must use the same name.'
25+
default : 'null'
26+
write-cache-key :
27+
description : 'The unique identifier for the associated cache. Any other consumers or producers for this cache must use the same name.'
28+
default : 'null'
29+
30+
runs :
31+
using : 'composite'
32+
steps :
33+
34+
# Create or fetch the artifacts used for these tests.
35+
- name : Run ${{ inputs.prepare-task }}
36+
uses : ./.github/actions/gradle-task
37+
with :
38+
build-root-directory : ${{ inputs.build-root-directory }}
39+
distribution : ${{ inputs.distribution }}
40+
java-version : ${{ inputs.java-version }}
41+
restore-cache-key : ${{ inputs.restore-cache-key }}
42+
task : ${{ inputs.prepare-task }}
43+
write-cache-key : ${{ inputs.write-cache-key }}
44+
45+
# Get the AVD if it's already cached.
46+
- name: AVD cache
47+
uses: actions/cache@v3
48+
id: avd-cache
49+
with:
50+
path: |
51+
~/.android/avd/*
52+
~/.android/adb*
53+
key: avd-${{ matrix.api-level }}
54+
55+
# If the AVD cache didn't exist, create an AVD and cache it.
56+
- name: create AVD and generate snapshot for caching
57+
if: steps.avd-cache.outputs.cache-hit != 'true'
58+
uses: reactivecircus/android-emulator-runner@v2
59+
with:
60+
api-level: ${{ inputs.api-level }}
61+
arch : x86_64
62+
disable-animations: false
63+
emulator-boot-timeout: 12000
64+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
65+
force-avd-creation: false
66+
profile : Galaxy Nexus
67+
ram-size: 4096M
68+
script: echo "Generated AVD snapshot."
69+
70+
# Run the actual emulator tests.
71+
# At this point every task should be up-to-date and the AVD should be ready to go.
72+
- name: run tests
73+
uses: reactivecircus/android-emulator-runner@v2
74+
with:
75+
api-level: ${{ inputs.api-level }}
76+
arch : x86_64
77+
disable-animations: true
78+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
79+
force-avd-creation: false
80+
profile : Galaxy Nexus
81+
script : ./gradlew ${{ inputs.test-task }}
82+
83+
- name : Upload results
84+
if : ${{ always() }}
85+
uses : actions/upload-artifact@v3
86+
with :
87+
name : instrumentation-test-results
88+
path : ./**/build/reports/androidTests/connected/**

0 commit comments

Comments
 (0)