Skip to content

Commit 298f3ce

Browse files
Merge branch 'android:main' into main
2 parents 4e6cda1 + b989d3a commit 298f3ce

File tree

52 files changed

+772
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+772
-125
lines changed

.github/workflows/Build.yaml

Lines changed: 79 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ concurrency:
1313
jobs:
1414
build:
1515
runs-on: ubuntu-latest
16-
timeout-minutes: 60
16+
timeout-minutes: 90
1717

1818
steps:
1919
- name: Checkout
@@ -37,27 +37,76 @@ jobs:
3737
- name: Check spotless
3838
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache
3939

40-
- name: Check lint
41-
run: ./gradlew lintDemoDebug
42-
4340
- name: Build all build type and flavor permutations
4441
run: ./gradlew assemble
4542

46-
- name: Run local tests
47-
run: ./gradlew testDemoDebug testProdDebug
48-
4943
- name: Upload build outputs (APKs)
5044
uses: actions/upload-artifact@v3
5145
with:
5246
name: APKs
5347
path: '**/build/outputs/apk/**/*.apk'
5448

55-
- name: Upload lint reports (HTML)
56-
if: always()
57-
uses: actions/upload-artifact@v3
49+
- name: Run local tests
50+
run: ./gradlew testDemoDebug testProdDebug
51+
52+
test:
53+
runs-on: ubuntu-latest
54+
55+
permissions:
56+
contents: write
57+
58+
timeout-minutes: 60
59+
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v3
63+
64+
- name: Validate Gradle Wrapper
65+
uses: gradle/wrapper-validation-action@v1
66+
67+
- name: Copy CI gradle.properties
68+
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
69+
70+
- name: Set up JDK 17
71+
uses: actions/setup-java@v3
5872
with:
59-
name: lint-reports
60-
path: '**/build/reports/lint-results-*.html'
73+
distribution: 'zulu'
74+
java-version: 17
75+
76+
- name: Setup Gradle
77+
uses: gradle/gradle-build-action@v2
78+
79+
- name: Run all local screenshot tests (Roborazzi)
80+
id: screenshotsverify
81+
continue-on-error: true
82+
run: ./gradlew verifyRoborazziDemoDebug
83+
84+
- name: Prevent pushing new screenshots if this is a fork
85+
id: checkfork
86+
continue-on-error: false
87+
if: steps.screenshotsverify.outcome == 'failure' && github.event.pull_request.head.repo.full_name != github.repository
88+
run: |
89+
echo "::error::Screenshot tests failed, please create a PR in your fork first." && exit 1
90+
91+
# Runs if previous job failed
92+
- name: Generate new screenshots if verification failed and it's a PR
93+
id: screenshotsrecord
94+
if: steps.screenshotsverify.outcome == 'failure' && github.event_name == 'pull_request'
95+
run: |
96+
./gradlew recordRoborazziDemoDebug
97+
98+
- name: Push new screenshots if available
99+
uses: stefanzweifel/git-auto-commit-action@v4
100+
if: steps.screenshotsrecord.outcome == 'success'
101+
with:
102+
file_pattern: '*/*.png'
103+
disable_globbing: true
104+
commit_message: "🤖 Updates screenshots"
105+
106+
# Run local tests after screenshot tests to avoid wrong UP-TO-DATE. TODO: Ignore screenshots.
107+
- name: Run local tests
108+
if: always()
109+
run: ./gradlew testDemoDebug testProdDebug
61110

62111
- name: Upload test results (XML)
63112
if: always()
@@ -66,6 +115,16 @@ jobs:
66115
name: test-results
67116
path: '**/build/test-results/test*UnitTest/**.xml'
68117

118+
- name: Check lint
119+
run: ./gradlew :app:lintProdRelease :app-nia-catalog:lintRelease :lint:lint
120+
121+
- name: Upload lint reports (HTML)
122+
if: always()
123+
uses: actions/upload-artifact@v3
124+
with:
125+
name: lint-reports
126+
path: '**/build/reports/lint-results-*.html'
127+
69128
androidTest:
70129
needs: build
71130
runs-on: macOS-latest # enables hardware acceleration in the virtual machine
@@ -77,7 +136,7 @@ jobs:
77136
steps:
78137
- name: Checkout
79138
uses: actions/checkout@v3
80-
139+
81140
- name: Copy CI gradle.properties
82141
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
83142

@@ -113,7 +172,7 @@ jobs:
113172
androidTest-GMD:
114173
needs: build
115174
runs-on: macOS-latest # enables hardware acceleration in the virtual machine
116-
timeout-minutes: 55
175+
timeout-minutes: 90
117176

118177
steps:
119178
- name: Checkout
@@ -138,13 +197,16 @@ jobs:
138197
run: ./gradlew packageDemoDebug packageDemoDebugAndroidTest
139198

140199
- name: Run instrumented tests with GMD
141-
run: ./gradlew cleanManagedDevices --unused-only &&
142-
./gradlew ciDemoDebugAndroidTest -Dorg.gradle.workers.max=1
200+
run: ./gradlew ciDemoDebugAndroidTest --no-parallel --max-workers=1
143201
-Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect" -Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true
144202

145203
- name: Upload test reports
146204
if: success() || failure()
147205
uses: actions/upload-artifact@v3
148206
with:
149-
name: test-reports
207+
name: test-reports-GMD
150208
path: '**/build/reports/androidTests'
209+
210+
- name: Print disk space usage
211+
if: failure()
212+
run: df -h

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ Examples:
109109
manipulate the state of the `Test` repository and verify the resulting behavior, instead of
110110
checking that specific repository methods were called.
111111

112+
## Screenshot tests
113+
114+
**Now In Android** uses [Roborazzi](https://github.com/takahirom/roborazzi) to do screenshot tests
115+
of certain screens and components. To run these tests, run the `verifyRoborazziDemoDebug` or
116+
`recordRoborazziDemoDebug` tasks. Note that screenshots are recorded on CI, using Linux, and other
117+
platforms might generate slightly different images, making the tests fail.
118+
112119
# UI
113120
The app was designed using [Material 3 guidelines](https://m3.material.io/). Learn more about the design process and
114121
obtain the design files in the [Now in Android Material 3 Case Study](https://goo.gle/nia-figma) (design assets [also available as a PDF](docs/Now-In-Android-Design-File.pdf)).

app/build.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,16 @@ dependencies {
120120
implementation(libs.androidx.profileinstaller)
121121
implementation(libs.kotlinx.coroutines.guava)
122122
implementation(libs.coil.kt)
123+
124+
// Core functions
125+
testImplementation(project(":core:testing"))
126+
testImplementation(project(":core:datastore-test"))
127+
testImplementation(project(":core:data-test"))
128+
testImplementation(project(":core:network"))
129+
testImplementation(libs.androidx.navigation.testing)
130+
testImplementation(libs.accompanist.testharness)
131+
testImplementation(kotlin("test"))
132+
implementation(libs.work.testing)
133+
kaptTest(libs.hilt.compiler)
134+
123135
}

app/src/main/java/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ fun NiaNavHost(
4949
startDestination = startDestination,
5050
modifier = modifier,
5151
) {
52-
// TODO: handle topic clicks from each top level destination
53-
forYouScreen(onTopicClick = {})
52+
forYouScreen(onTopicClick = navController::navigateToTopic)
5453
bookmarksScreen(
5554
onTopicClick = navController::navigateToTopic,
5655
onShowSnackbar = onShowSnackbar,
@@ -61,13 +60,11 @@ fun NiaNavHost(
6160
onTopicClick = navController::navigateToTopic,
6261
)
6362
interestsGraph(
64-
onTopicClick = { topicId ->
65-
navController.navigateToTopic(topicId)
66-
},
63+
onTopicClick = navController::navigateToTopic,
6764
nestedGraphs = {
6865
topicScreen(
6966
onBackClick = navController::popBackStack,
70-
onTopicClick = {},
67+
onTopicClick = navController::navigateToTopic,
7168
)
7269
},
7370
)

0 commit comments

Comments
 (0)