Android Upload workflow (Picovoice/leopard)
The Android Upload workflow from Picovoice/leopard, explained and optimized by Latchkey.
CI health: D - needs work
Point runs-on at Latchkey and get caching, run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Android Upload workflow from the Picovoice/leopard repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Android Upload
on:
workflow_dispatch:
push:
branches: [ master ]
paths:
- '.github/workflows/android-upload.yml'
- 'demo/android/**/build.gradle'
pull_request:
branches: [ master, 'v[0-9]+.[0-9]+' ]
paths:
- '.github/workflows/android-upload.yml'
- 'demo/android/LeopardDemo/**/build.gradle'
jobs:
upload-demo:
runs-on: ubuntu-latest
defaults:
run:
working-directory: demo/android/LeopardDemo
steps:
- uses: actions/checkout@v3
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
- name: Set up service json
run: echo ${{secrets.GOOGLE_PLAY_SERVICE_JSON}} | base64 -d > ./service-account.json
- name: Override version code
run: |
VC=`fastlane run google_play_track_version_codes \
json_key:"./service-account.json" \
package_name:"ai.picovoice.leoparddemo" \
track:"internal" \
| grep -oP '(?<=Result: \[)\d+(?=\])' \
| awk '{print $1+1}'`
sed -i "s/versionCode [0-9]*/versionCode $VC/g" leopard-demo-app/build.gradle
- name: Inject Android keystore variables
run: |
echo storePassword="${{secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD}}" >> local.properties
echo keyPassword="${{secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD}}" >> local.properties
echo keyAlias=picovoice >> local.properties
echo storeFile=../picovoice.jks >> local.properties
- name: Setup Android keystore file
run: echo "${{secrets.ANDROID_RELEASE_KEYSTORE_FILE_B64}}" | base64 -d > picovoice.jks
- name: Build
run: ./gradlew bundleRelease
- name: Upload to Google Play
run: fastlane supply --json_key ./service-account.json --package_name ai.picovoice.leoparddemo --aab leopard-demo-app/build/outputs/bundle/enRelease/leopard-demo-app-en-release.aab --track internal --skip_upload_metadata --skip_upload_images --skip_upload_screenshots --release_status draft
The same workflow, on Latchkey
Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.
name: Android Upload on: workflow_dispatch: push: branches: [ master ] paths: - '.github/workflows/android-upload.yml' - 'demo/android/**/build.gradle' pull_request: branches: [ master, 'v[0-9]+.[0-9]+' ] paths: - '.github/workflows/android-upload.yml' - 'demo/android/LeopardDemo/**/build.gradle' concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: upload-demo: timeout-minutes: 30 runs-on: latchkey-small defaults: run: working-directory: demo/android/LeopardDemo steps: - uses: actions/checkout@v3 - name: set up JDK 17 uses: actions/setup-java@v3 with: cache: 'maven' java-version: 17 distribution: 'temurin' - name: Set up service json run: echo ${{secrets.GOOGLE_PLAY_SERVICE_JSON}} | base64 -d > ./service-account.json - name: Override version code run: | VC=`fastlane run google_play_track_version_codes \ json_key:"./service-account.json" \ package_name:"ai.picovoice.leoparddemo" \ track:"internal" \ | grep -oP '(?<=Result: \[)\d+(?=\])' \ | awk '{print $1+1}'` sed -i "s/versionCode [0-9]*/versionCode $VC/g" leopard-demo-app/build.gradle - name: Inject Android keystore variables run: | echo storePassword="${{secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD}}" >> local.properties echo keyPassword="${{secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD}}" >> local.properties echo keyAlias=picovoice >> local.properties echo storeFile=../picovoice.jks >> local.properties - name: Setup Android keystore file run: echo "${{secrets.ANDROID_RELEASE_KEYSTORE_FILE_B64}}" | base64 -d > picovoice.jks - name: Build run: ./gradlew bundleRelease - name: Upload to Google Play run: fastlane supply --json_key ./service-account.json --package_name ai.picovoice.leoparddemo --aab leopard-demo-app/build/outputs/bundle/enRelease/leopard-demo-app-en-release.aab --track internal --skip_upload_metadata --skip_upload_images --skip_upload_screenshots --release_status draft
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cancel superseded runs when a branch or PR gets a newer push.
- Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.