Skip to content

Commit 0a7e52b

Browse files
authored
Add a build and test workflow for the repo (#50)
1 parent 5e6e1d2 commit 0a7e52b

File tree

5 files changed

+156
-46
lines changed

5 files changed

+156
-46
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
name: Build and Test
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
workflow_dispatch:
9+
10+
# Ensure that only the latest commit is tested for PRs
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
build_test_lint:
17+
name: "Build, Test, and Lint"
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 60
20+
permissions:
21+
contents: write # Needed for git-auto-commit-action
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
project-dir: [ai-catalog, gemini-nano]
26+
defaults:
27+
run:
28+
working-directory: ${{ matrix.project-dir }}
29+
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Set up JDK 17
35+
uses: actions/setup-java@v4
36+
with:
37+
java-version: '17'
38+
distribution: 'temurin'
39+
40+
- name: Setup Gradle
41+
uses: gradle/actions/setup-gradle@v4
42+
# Add cache-encryption-key if you set up the GRADLE_ENCRYPTION_KEY secret
43+
# with:
44+
# cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
45+
46+
- name: Grant execute permission for gradlew
47+
run: chmod +x gradlew
48+
49+
- name: Apply Spotless
50+
if: matrix.project-dir != 'gemini-nano'
51+
run: ./gradlew spotlessApply
52+
53+
- name: Commit Spotless changes
54+
if: matrix.project-dir != 'gemini-nano'
55+
uses: stefanzweifel/git-auto-commit-action@v5
56+
with:
57+
commit_message: 🤖 Apply Spotless formatting
58+
file_pattern: '**/*.kt **/*.kts **/*.java **/*.xml'
59+
60+
- name: Build debug APK
61+
run: ./gradlew assembleDebug --no-configuration-cache
62+
63+
- name: Run local unit tests
64+
run: ./gradlew testDebugUnitTest
65+
66+
- name: Check lint
67+
run: ./gradlew lintDebug
68+
69+
- name: Upload build outputs (APKs)
70+
if: ${{ !cancelled() }}
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: APKs-${{ matrix.project-dir }}
74+
path: '**/build/outputs/apk/debug/*.apk'
75+
76+
- name: Upload JVM local test results (XML)
77+
if: ${{ !cancelled() }}
78+
uses: actions/upload-artifact@v4
79+
with:
80+
name: local-test-results-${{ matrix.project-dir }}
81+
path: '**/build/test-results/test*UnitTest/TEST-*.xml'
82+
83+
- name: Upload lint reports (HTML)
84+
if: ${{ !cancelled() }}
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: lint-reports-html-${{ matrix.project-dir }}
88+
path: '**/build/reports/lint-results-debug.html'
89+
90+
androidTest:
91+
name: "Instrumentation Tests (emulator)"
92+
runs-on: ubuntu-latest
93+
timeout-minutes: 60
94+
strategy:
95+
fail-fast: false
96+
matrix:
97+
project-dir: [ai-catalog, gemini-nano]
98+
api-level: [26]
99+
100+
steps:
101+
- name: Delete unnecessary tools 🔧
102+
uses: jlumbroso/[email protected]
103+
with:
104+
android: false # Don't remove Android tools
105+
tool-cache: true # Remove image tool cache
106+
dotnet: true
107+
haskell: true
108+
swap-storage: true
109+
110+
- name: Enable KVM group perms
111+
run: |
112+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
113+
sudo udevadm control --reload-rules
114+
sudo udevadm trigger --name-match=kvm
115+
116+
- name: Checkout code
117+
uses: actions/checkout@v4
118+
119+
- name: Set up JDK 17
120+
uses: actions/setup-java@v4
121+
with:
122+
java-version: '17'
123+
distribution: 'temurin'
124+
125+
- name: Setup Gradle
126+
uses: gradle/actions/setup-gradle@v4
127+
128+
- name: Grant execute permission for gradlew
129+
working-directory: ${{ matrix.project-dir }}
130+
run: chmod +x gradlew
131+
132+
- name: Build projects and run instrumentation tests
133+
uses: reactivecircus/android-emulator-runner@v2
134+
with:
135+
api-level: ${{ matrix.api-level }}
136+
arch: x86
137+
disable-animations: true
138+
disk-size: 6000M
139+
heap-size: 600M
140+
working-directory: ${{ matrix.project-dir }}
141+
script: ./gradlew connectedDebugAndroidTest
142+
143+
144+
- name: Upload test reports
145+
if: ${{ !cancelled() }}
146+
uses: actions/upload-artifact@v4
147+
with:
148+
name: test-reports-${{ matrix.project-dir }}-${{ matrix.api-level }}
149+
path: '**/build/reports/androidTests'

.github/workflows/build-gemini-nano.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

ai-catalog/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# http://www.gradle.org/docs/current/userguide/build_environment.html
77
# Specifies the JVM arguments used for the daemon process.
88
# The setting is particularly useful for tweaking memory settings.
9-
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
9+
org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8
1010
org.gradle.caching=true
1111
org.gradle.parallel=true
1212
org.gradle.unsafe.configuration-cache=true

ai-catalog/samples/gemini-video-summarization/build.gradle.kts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ android {
4949
buildFeatures {
5050
compose = true
5151
}
52-
composeOptions {
53-
kotlinCompilerExtensionVersion = "1.5.15"
54-
}
5552
}
5653

5754
dependencies {
@@ -73,4 +70,9 @@ dependencies {
7370
// Media3 ExoPlayer
7471
implementation(libs.androidx.media3.exoplayer)
7572
implementation(libs.androidx.media3.ui)
73+
74+
androidTestImplementation(libs.androidx.junit)
75+
androidTestImplementation(libs.androidx.espresso.core)
76+
androidTestImplementation(platform(libs.androidx.compose.bom))
77+
androidTestImplementation(libs.androidx.ui.test.junit4)
7678
}

ai-catalog/samples/genai-writing-assistance/build.gradle.kts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,13 @@ android {
4949
sourceCompatibility = JavaVersion.VERSION_17
5050
targetCompatibility = JavaVersion.VERSION_17
5151
}
52-
composeOptions {
53-
kotlinCompilerExtensionVersion = "1.5.15"
54-
}
52+
5553
kotlinOptions {
5654
jvmTarget = "17"
5755
}
5856
}
5957

6058
dependencies {
61-
6259
implementation(libs.androidx.core.ktx)
6360
implementation(libs.androidx.appcompat)
6461
implementation(libs.androidx.material3)

0 commit comments

Comments
 (0)