Skip to content

Commit

Permalink
Release v1.0.0-alpha02 (#18)
Browse files Browse the repository at this point in the history
* Plugin configuration change

- Remove firebase Project ID config and add service account credential

* Setup GitHub action for profile verification (#17)

* CI setup to automate baseline profile

- Add Github action workflow to trigger profile verification

* Update dependency

- Update macro-benchmark dependency

* Update github workflow

- Replace Java 11 setup with java 17

* Plugin config changes

- Replace firebase project ID config with service account JSON config to support profile verification on CI

* Plugin upgrade

- Update AGP from 8.0.0 to 8.2.0
- Update compile SDK version from 33 to 34

* Workflow changes

- Remove decoding json file and writing

* Workflow changes

- Inline the directory creation

* Workflow changes

- Change the run script within step

* Workflow changes

- Replace access of encoded service account from env to vars

* Plugin config changes

- Fix the service account JSON file path

* Workflow changes

- Add log for home path in GCloud authentication

* Workflow changes

- Update the service account JSON path for GCloud authentication

* Plugin configuration change

- Rename step to setup service account JSON

* Workflow changes

- Trigger workflow only on tag push

* Workflow changes and version upgrade

- Trigger profile verification workflow on pull request against release branch
- Upgrade plugin version from 1.0.0-alpha01 to 1.0.0-alpha02
- Add CI setup details in the README
  • Loading branch information
sagar-viradiya authored Dec 7, 2023
1 parent 2d7daf1 commit 24c2a09
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 33 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/profile_verification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Verify Baseline Profile

on:
pull_request:
branches:
- release

jobs:
build-benchmark-apks:
name: Build APKs and Run profile verification
runs-on: macos-latest
timeout-minutes: 20

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- name: Build benchmark apk
run: ./gradlew :benchmark:assembleBenchmark

- name: Build app apk
run: ./gradlew :sample:assembleBenchmark

- name: Setup GCloud Credentials for Flank
run: |
GCLOUD_DIR="$HOME/.config/gcloud/"
mkdir -p "$GCLOUD_DIR"
echo "${{ vars.GCLOUD_KEY }}" | base64 --decode > "$GCLOUD_DIR/application_default_credentials.json"
- name: Verify baseline profile
run: ./gradlew :sample:runBenchmarkAndVerifyProfile
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ For more information on benchmarking baseline profile visit official [Android gu
Apply plugin to app module `build.gradle.kts` file.
```kotlin
plugins {
id("io.github.sagar-viradiya.autobenchmark") version "1.0.0.alpha01"
id("io.github.sagar-viradiya.autobenchmark") version "1.0.0.alpha02"
}
```

Expand All @@ -30,7 +30,7 @@ buildscript {
}
}
dependencies {
classpath("io.github.sagar-viradiya:autobenchmark:1.0.0.alpha01")
classpath("io.github.sagar-viradiya:autobenchmark:1.0.0.alpha02")
}
}
```
Expand All @@ -51,8 +51,8 @@ autoBenchmark {
appApkFilePath.set("/sample/build/outputs/apk/benchmark/sample-benchmark.apk")
// A relative file path from the root to benchmark apk
benchmarkApkFilePath.set("/benchmark/build/outputs/apk/benchmark/benchmark-benchmark.apk")
// Firebase project ID to access firebase test lab
firebaseProjectId.set("firebaseProjectId")
// Service account JSON file path to authenticate GCloud
serviceAccountJsonFilePath.set("../../.config/gcloud/application_default_credentials.json")
// Physical device configuration map to run benchmark
physicalDevices.set(mapOf(
"model" to "redfin", "version" to "30"
Expand All @@ -64,7 +64,7 @@ autoBenchmark {

### 🔐 Authenticate G-Cloud to run tests on Firebase test lab

To run tests on Firebase test lab you need to authenticate to G-Cloud.
To run tests on Firebase test lab and download JSON result of profile verification, you need to authenticate to G-Cloud.

#### Authenticating on local machine

Expand All @@ -76,19 +76,20 @@ This will store credentials in ~/.flank directory
#### Authenticating on CI

You will need service account JSON file to setup authentication on CI. Follow the [test lab docs](https://firebase.google.com/docs/test-lab/android/continuous) to create a service account.
Base64 encode this file on CI as GCLOUD_KEY using shell script.
Base64 encode this file on your local machine and set this as environment variable on CI as GCLOUD_KEY.

```shell
base64 -i "$HOME/.config/gcloud/application_default_credentials.json" | pbcopy
```

Then in CI decode the JSON.
Then on CI decode the JSON.

```shell
GCLOUD_DIR="$HOME/.config/gcloud/"
mkdir -p "$GCLOUD_DIR"
echo "$GCLOUD_KEY" | base64 --decode > "$GCLOUD_DIR/application_default_credentials.json"
```
Please refer to GitHub action setup to know how this is being done.

For more info refer [this](https://flank.github.io/flank/#authenticate-with-a-service-account) flank guide for authentication as this plugin internally uses Fladle and Flank

Expand Down Expand Up @@ -137,10 +138,9 @@ Run following commands to build apks
./gradlew :benchmark:assembleBenchmark
```

You will need your firebase test lab project ID in local.properties file. Also, you need to authenticate
G-cloud to run tests on Firebase test lab.
Also make sure to have service account JSON file in the configured path (`serviceAccountJsonFilePath`)

Sample CI setup using github action is coming soon!
For verifying profile on CI, please refer to GitHub action setup.

## Contribution
Unfortunately it is not ready to accept any contribution
Expand Down
2 changes: 1 addition & 1 deletion auto-benchmark-plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#

ID=io.github.sagar-viradiya.autobenchmark
VERSION=1.0.0-alpha01
VERSION=1.0.0-alpha02
GROUP=io.github.sagar-viradiya
DISPLAY_NAME=Auto Benchmark
DESCRIPTION=Automate baseline profile on CI by running benchmark instrumentation tests on Firebase test lab and verifying benchmark result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import org.gradle.api.Project
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.getByType

interface AutoBenchmarkExtension {

Expand All @@ -43,9 +42,9 @@ interface AutoBenchmarkExtension {
val benchmarkApkFilePath: Property<String>

/**
* Firebase project ID to access firebase test lab
* Service account JSON file path to authenticate GCloud
*/
val firebaseProjectId: Property<String>
val serviceAccountJsonFilePath: Property<String>

/**
* Physical device configuration map to run benchmark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.android.build.api.variant.AndroidComponentsExtension
import com.osacky.flank.gradle.FlankGradleExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import java.io.File

class AutoBenchmarkPlugin : Plugin<Project> {
companion object {
Expand Down Expand Up @@ -80,7 +81,7 @@ class AutoBenchmarkPlugin : Plugin<Project> {
extension.physicalDevices.get()
)
)
projectId.set(extension.firebaseProjectId.get())
serviceAccountCredentials.set(File(extension.serviceAccountJsonFilePath.get()))
}

apply {
Expand Down
2 changes: 1 addition & 1 deletion baseline-profile/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies {
implementation("androidx.test.ext:junit:1.1.5")
implementation("androidx.test.espresso:espresso-core:3.5.1")
implementation("androidx.test.uiautomator:uiautomator:2.2.0")
implementation("androidx.benchmark:benchmark-macro-junit4:1.1.1")
implementation("androidx.benchmark:benchmark-macro-junit4:1.2.0")
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@

package io.github.sagar.baseline_profile

import androidx.benchmark.macro.ExperimentalBaselineProfilesApi
import androidx.benchmark.macro.junit4.BaselineProfileRule
import org.junit.Rule
import org.junit.Test

@OptIn(ExperimentalBaselineProfilesApi::class)
class AutoBenchmarkSampleBaselineProfileGenerator {

@get:Rule
val baselineProfileRule = BaselineProfileRule()

@Test
fun startup() = baselineProfileRule.collectBaselineProfile(
fun startup(): Unit = baselineProfileRule.collect(
packageName = "io.github.sagar.auto_benchmark",
profileBlock = {
startActivityAndWait()
Expand Down
6 changes: 3 additions & 3 deletions benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ plugins {

android {
namespace = "io.github.sagar.benchmark"
compileSdk = 33
compileSdk = 34

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
Expand All @@ -42,7 +42,7 @@ android {

defaultConfig {
minSdk = 24
targetSdk = 33
targetSdk = 34

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -64,7 +64,7 @@ dependencies {
implementation("androidx.test.ext:junit:1.1.5")
implementation("androidx.test.espresso:espresso-core:3.5.1")
implementation("androidx.test.uiautomator:uiautomator:2.2.0")
implementation("androidx.benchmark:benchmark-macro-junit4:1.1.1")
implementation("androidx.benchmark:benchmark-macro-junit4:1.2.0")
}

androidComponents {
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/

plugins {
id("com.android.application") version "8.0.0" apply false
id("com.android.application") version "8.2.0" apply false
id("org.jetbrains.kotlin.android") version "1.8.10" apply false
id("com.android.test") version "8.0.0" apply false
id("com.android.test") version "8.2.0" apply false
id("androidx.baselineprofile") version "1.2.0-alpha16" apply false
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
#Sat Jul 15 19:58:19 CEST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 4 additions & 8 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,21 @@

@file:Suppress("UnstableApiUsage")

import java.util.Properties

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("androidx.baselineprofile")
id("io.github.sagar-viradiya.autobenchmark")
}

val properties = Properties().apply { load(project.rootProject.file("local.properties").inputStream()) }

android {
namespace = "io.github.sagar.auto_benchmark"
compileSdk = 33
compileSdk = 34

defaultConfig {
applicationId = "io.github.sagar.auto_benchmark"
minSdk = 24
targetSdk = 33
targetSdk = 34
versionCode = 1
versionName = "1.0"

Expand Down Expand Up @@ -98,9 +94,9 @@ dependencies {
autoBenchmark {
appApkFilePath.set("/sample/build/outputs/apk/benchmark/sample-benchmark.apk")
benchmarkApkFilePath.set("/benchmark/build/outputs/apk/benchmark/benchmark-benchmark.apk")
firebaseProjectId.set(properties.getProperty("firebaseProjectId"))
serviceAccountJsonFilePath.set("../../../../.config/gcloud/application_default_credentials.json")
physicalDevices.set(mapOf(
"model" to "redfin", "version" to "30"
))
tolerancePercentage.set(10f)
tolerancePercentage.set(5f)
}

0 comments on commit 24c2a09

Please sign in to comment.