Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions .github/actions/gradle-task/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ runs :
cache-read-only : false
gradle-home-cache-cleanup : true

# Calculate all the hashes for keys just one time.
# These should only be referenced before the actual task action, since that action
# may generate changes and we want the final cache key to reflect its current state.
- name : Calculate hashes
id : hashes
shell: bash
run : |
echo "lib_versions=${{ hashFiles('**/libs.versions.toml') }}" >> $GITHUB_OUTPUT
echo "gradle_props=${{ hashFiles('**/gradle.properties') }}" >> $GITHUB_OUTPUT
echo "gradle_kts=${{ hashFiles('**/*.gradle.kts') }}" >> $GITHUB_OUTPUT
echo "src_kt=${{ hashFiles('**/src/**/*.kt') }}" >> $GITHUB_OUTPUT

# Attempt to restore from the write-cache-key, or fall back to a partial match for the write key.
# Skipped if the write-cache-key wasn't set.
# This step's "cache_hit" output will only be true if an exact match was found.
Expand All @@ -51,9 +63,15 @@ runs :
with :
path : |
~/.gradle/caches/build-cache-1
./**/build/**
key : ${{runner.os}}-${{inputs.write-cache-key}}-${{hashFiles('**/*.gradle.kt*')}}-${{hashFiles('**/libs.versions.toml')}}-${{hashFiles('**/gradle.properties')}}
restore-keys : ${{runner.os}}-${{inputs.write-cache-key}}
~/.konan
./**/build
./**/.gradle
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}}
restore-keys : |
${{runner.os}}-${{inputs.write-cache-key}}-${{steps.hashes.outputs.lib_versions}}-${{steps.hashes.outputs.gradle_props}}-${{steps.hashes.outputs.gradle_kts}}
${{runner.os}}-${{inputs.write-cache-key}}-${{steps.hashes.outputs.lib_versions}}-${{steps.hashes.outputs.gradle_props}}
${{runner.os}}-${{inputs.write-cache-key}}-${{steps.hashes.outputs.lib_versions}}
${{runner.os}}-${{inputs.write-cache-key}}

# Attempt to restore from the restore-cache-key, or fall back to a partial match for the restore key.
# Skipped if the restore-cache-key wasn't set, or if the write-cache-key restore had an exact match.
Expand All @@ -63,9 +81,15 @@ runs :
with :
path : |
~/.gradle/caches/build-cache-1
./**/build/**
key : ${{runner.os}}-${{inputs.restore-cache-key}}-${{hashFiles('**/*.gradle.kt*')}}-${{hashFiles('**/libs.versions.toml')}}-${{hashFiles('**/gradle.properties')}}
restore-keys : ${{runner.os}}-${{inputs.restore-cache-key}}
~/.konan
./**/build
./**/.gradle
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}}
restore-keys : |
${{runner.os}}-${{inputs.restore-cache-key}}-${{steps.hashes.outputs.lib_versions}}-${{steps.hashes.outputs.gradle_props}}-${{steps.hashes.outputs.gradle_kts}}
${{runner.os}}-${{inputs.restore-cache-key}}-${{steps.hashes.outputs.lib_versions}}-${{steps.hashes.outputs.gradle_props}}
${{runner.os}}-${{inputs.restore-cache-key}}-${{steps.hashes.outputs.lib_versions}}
${{runner.os}}-${{inputs.restore-cache-key}}

- uses : gradle/wrapper-validation-action@v1

Expand All @@ -92,8 +116,10 @@ runs :
with :
path : |
~/.gradle/caches/build-cache-1
./**/build/**
key : ${{runner.os}}-${{inputs.write-cache-key}}-${{hashFiles('**/*.gradle.kt*')}}-${{hashFiles('**/libs.versions.toml')}}-${{hashFiles('**/gradle.properties')}}
~/.konan
./**/build
./**/.gradle
key : ${{runner.os}}-${{inputs.write-cache-key}}-${{hashFiles('**/libs.versions.toml')}}-${{hashFiles('**/gradle.properties')}}-${{hashFiles('**/*.gradle.kts')}}-${{hashFiles('**/src/**/*.kt')}}

- name : Upload heap dump
if : failure()
Expand Down
88 changes: 88 additions & 0 deletions .github/actions/gradle-tasks-with-emulator/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name : Run Android Instrumentation Tests with Artifact and AVD Caching
description: This action sets up Gradle, runs a preparatory task, runs Android tests on an emulator, and uploads test results.

inputs:
prepare-task:
description: 'Gradle task for preparing necessary artifacts. Supports multi-line input.'
required: true
test-task:
description: 'Gradle task for running instrumentation tests. Supports multi-line input.'
required: true
api-level :
description : 'The Android SDK api level, like `29`'
required : true
build-root-directory :
description : 'Path to the root directory of the build'
required : false
java-version :
description : 'The Java version to set up.'
default : '11'
distribution :
description : 'The JDK distribution to use.'
default : 'zulu'
restore-cache-key :
description : 'The unique identifier for the associated cache. Any other consumers or producers for this cache must use the same name.'
default : 'null'
write-cache-key :
description : 'The unique identifier for the associated cache. Any other consumers or producers for this cache must use the same name.'
default : 'null'

runs :
using : 'composite'
steps :

# Create or fetch the artifacts used for these tests.
- name : Run ${{ inputs.prepare-task }}
uses : ./.github/actions/gradle-task
with :
build-root-directory : ${{ inputs.build-root-directory }}
distribution : ${{ inputs.distribution }}
java-version : ${{ inputs.java-version }}
restore-cache-key : ${{ inputs.restore-cache-key }}
task : ${{ inputs.prepare-task }}
write-cache-key : ${{ inputs.write-cache-key }}

# Get the AVD if it's already cached.
- name: AVD cache
uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}

# If the AVD cache didn't exist, create an AVD and cache it.
- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ inputs.api-level }}
arch : x86_64
disable-animations: false
emulator-boot-timeout: 12000
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
force-avd-creation: false
profile : Galaxy Nexus
ram-size: 4096M
script: echo "Generated AVD snapshot."

# Run the actual emulator tests.
# At this point every task should be up-to-date and the AVD should be ready to go.
- name: run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ inputs.api-level }}
arch : x86_64
disable-animations: true
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
force-avd-creation: false
profile : Galaxy Nexus
script : ./gradlew ${{ inputs.test-task }}

- name : Upload results
if : ${{ always() }}
uses : actions/upload-artifact@v3
with :
name : instrumentation-test-results
path : ./**/build/reports/androidTests/connected/**
Loading