Skip to content

Baseline profile generation #57

Baseline profile generation

Baseline profile generation #57

# Credits: https://github.com/chrisbanes/tivi/blob/main/.github/workflows/baseline-profile.yml
name: Baseline profile generation
on:
# Every Sunday at 00:30 UTC
schedule:
- cron: '30 0 * * 0'
workflow_dispatch:
pull_request:
paths:
- 'kanalytics-viewer-base-profile/**'
- '.github/workflows/baseline-profile.yml'
jobs:
baseline-profile:
runs-on: ubuntu-latest
timeout-minutes: 45
concurrency:
group: baseline-profile-update-baseline-profile
cancel-in-progress: true
steps:
- name: Set ANDROID_USER_HOME
run: echo "ANDROID_USER_HOME=$HOME/.android" >> $GITHUB_ENV
- 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
ls /dev/kvm
- name: Download emulator package
run: $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager emulator
- name: Checkout
uses: actions/checkout@v5
with:
# We need to use a Personal Access Token from an admin to be able to commit to main,
# as it is a protected branch.
# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#creating-a-fine-grained-personal-access-token
token: ${{ secrets.OWNER_PAT_TOKEN }}
- name: Setup
uses: ./.github/actions/setup
- name: Cache AVD
if: false
uses: actions/cache@v4
with:
path: |
${{ env.ANDROID_USER_HOME }}/avd/gradle-managed/*
${{ env.ANDROID_USER_HOME }}/adb*
key: v7-${{ runner.os }}-baseline-profile
- name: Accept licenses
run: yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses
# This allows us to build most of what we need without the emulator running
# and using resources
- name: Build app and benchmark
run: ./gradlew assembleNonMinifiedRelease
- name: Clear Gradle Managed Devices
run: ./gradlew cleanManagedDevices --unused-only
- name: Run benchmark on Gradle Managed Device
run: |
generate_profile () { ./gradlew generateBaselineProfile \
-Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect" \
-Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=BaselineProfile \
-Pandroid.experimental.testOptions.managedDevices.setupTimeoutMinutes=20 \
--no-configuration-cache \
-Dorg.gradle.workers.max=4; }
(echo "==== Attempt 1 ====" && generate_profile) || (echo "==== Attempt 2 ====" && generate_profile) || (echo "==== Both attempts failed ====" && exit 1)
# If we're on main branch, copy over the baseline profile and
# commit it to the repository (if changed)
- name: Commit baseline profile into main
if: github.ref == 'refs/heads/main'
run: |
# If the baseline profile has changed, commit it
if [[ $(git diff --stat kanalytics-viewer-base-profile/src) != '' ]]; then
git config user.name github-actions
git config user.email [email protected]
git add kanalytics-viewer-base-profile/src
git commit -m "Update app baseline profile"
git pull --rebase
git push
fi
- name: Upload reports
if: always()
uses: actions/upload-artifact@v4
with:
name: reports
path: |
**/build/reports/*