Skip to content

Commit 0df27ef

Browse files
authored
[All] Add a method to easily test a snapshot locally and on CI (android#990)
1 parent 10498f1 commit 0df27ef

12 files changed

+258
-32
lines changed

.github/workflows/test-snapshot.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Build and Test a Compose snapshot
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
snapshotID:
7+
required: true
8+
type: string
9+
composeVersion:
10+
required: true
11+
type: string
12+
13+
concurrency:
14+
group: ${{ inputs.name }}-build-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 60
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
25+
- name: Copy CI gradle.properties
26+
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
27+
28+
- name: Set up JDK 11
29+
uses: actions/setup-java@v1
30+
with:
31+
java-version: 11
32+
33+
- name: Generate cache key
34+
run: ./scripts/checksum.sh ${{ inputs.path }} checksum.txt
35+
36+
- uses: actions/cache@v3
37+
with:
38+
path: |
39+
~/.gradle/caches/modules-*
40+
~/.gradle/caches/jars-*
41+
~/.gradle/caches/build-cache-*
42+
key: gradle-${{ hashFiles('checksum.txt') }}
43+
44+
- name: Check snapshot
45+
working-directory: ${{ inputs.path }}
46+
run: ./scripts/test_snapshot.sh $CI_COMPOSE_VERSION $CI_COMPOSE_SNAPSHOT
47+
env:
48+
CI_COMPOSE_VERSION: ${{ inputs.composeVersion }}
49+
CI_COMPOSE_SNAPSHOT: ${{ inputs.snapshotID }}
50+
51+
- name: Run local tests
52+
working-directory: ${{ inputs.path }}
53+
run: ./gradlew testDebug --stacktrace
54+
55+
- name: Upload build reports
56+
if: always()
57+
uses: actions/upload-artifact@v3
58+
with:
59+
name: build-reports
60+
path: ${{ inputs.path }}/app/build/reports

Crane/settings.gradle.kts

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
val snapshotVersion : String? = System.getenv("COMPOSE_SNAPSHOT_ID")
17+
1618
pluginManagement {
1719
repositories {
1820
gradlePluginPortal()
@@ -23,6 +25,11 @@ pluginManagement {
2325
dependencyResolutionManagement {
2426
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
2527
repositories {
28+
snapshotVersion?.let {
29+
println("https://androidx.dev/snapshots/builds/$it/artifacts/repository/")
30+
maven { url = uri("https://androidx.dev/snapshots/builds/$it/artifacts/repository/") }
31+
}
32+
2633
google()
2734
mavenCentral()
2835
}

JetNews/settings.gradle.kts

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Copyright 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
val snapshotVersion : String? = System.getenv("COMPOSE_SNAPSHOT_ID")
17+
118
pluginManagement {
219
repositories {
320
gradlePluginPortal()
@@ -8,6 +25,11 @@ pluginManagement {
825
dependencyResolutionManagement {
926
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
1027
repositories {
28+
snapshotVersion?.let {
29+
println("https://androidx.dev/snapshots/builds/$it/artifacts/repository/")
30+
maven { url = uri("https://androidx.dev/snapshots/builds/$it/artifacts/repository/") }
31+
}
32+
1133
google()
1234
mavenCentral()
1335
}

Jetcaster/settings.gradle.kts

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
val snapshotVersion : String? = System.getenv("COMPOSE_SNAPSHOT_ID")
17+
1618
pluginManagement {
1719
repositories {
1820
gradlePluginPortal()
@@ -23,6 +25,11 @@ pluginManagement {
2325
dependencyResolutionManagement {
2426
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
2527
repositories {
28+
snapshotVersion?.let {
29+
println("https://androidx.dev/snapshots/builds/$it/artifacts/repository/")
30+
maven { url = uri("https://androidx.dev/snapshots/builds/$it/artifacts/repository/") }
31+
}
32+
2633
google()
2734
mavenCentral()
2835
}

Jetchat/settings.gradle.kts

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
val snapshotVersion : String? = System.getenv("COMPOSE_SNAPSHOT_ID")
17+
1618
pluginManagement {
1719
repositories {
1820
gradlePluginPortal()
@@ -23,6 +25,11 @@ pluginManagement {
2325
dependencyResolutionManagement {
2426
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
2527
repositories {
28+
snapshotVersion?.let {
29+
println("https://androidx.dev/snapshots/builds/$it/artifacts/repository/")
30+
maven { url = uri("https://androidx.dev/snapshots/builds/$it/artifacts/repository/") }
31+
}
32+
2633
google()
2734
mavenCentral()
2835
}

Jetsnack/settings.gradle.kts

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Copyright 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
val snapshotVersion : String? = System.getenv("COMPOSE_SNAPSHOT_ID")
17+
118
pluginManagement {
219
repositories {
320
gradlePluginPortal()
@@ -8,6 +25,11 @@ pluginManagement {
825
dependencyResolutionManagement {
926
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
1027
repositories {
28+
snapshotVersion?.let {
29+
println("https://androidx.dev/snapshots/builds/$it/artifacts/repository/")
30+
maven { url = uri("https://androidx.dev/snapshots/builds/$it/artifacts/repository/") }
31+
}
32+
1133
google()
1234
mavenCentral()
1335
}

Jetsurvey/settings.gradle

-16
This file was deleted.

Jetsurvey/settings.gradle.kts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
val snapshotVersion : String? = System.getenv("COMPOSE_SNAPSHOT_ID")
17+
18+
pluginManagement {
19+
repositories {
20+
gradlePluginPortal()
21+
google()
22+
mavenCentral()
23+
}
24+
}
25+
dependencyResolutionManagement {
26+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
27+
repositories {
28+
snapshotVersion?.let {
29+
println("https://androidx.dev/snapshots/builds/$it/artifacts/repository/")
30+
maven { url = uri("https://androidx.dev/snapshots/builds/$it/artifacts/repository/") }
31+
}
32+
33+
google()
34+
mavenCentral()
35+
}
36+
}
37+
include(":app")
38+
rootProject.name = "Jetsurvey"

Owl/settings.gradle

-15
This file was deleted.

Owl/settings.gradle.kts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
val snapshotVersion : String? = System.getenv("COMPOSE_SNAPSHOT_ID")
17+
18+
pluginManagement {
19+
repositories {
20+
gradlePluginPortal()
21+
google()
22+
mavenCentral()
23+
}
24+
}
25+
dependencyResolutionManagement {
26+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
27+
repositories {
28+
snapshotVersion?.let {
29+
println("https://androidx.dev/snapshots/builds/$it/artifacts/repository/")
30+
maven { url = uri("https://androidx.dev/snapshots/builds/$it/artifacts/repository/") }
31+
}
32+
33+
google()
34+
mavenCentral()
35+
}
36+
}
37+
rootProject.name = "Owl"
38+
include(":app")

Reply/settings.gradle.kts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Google LLC
2+
* Copyright 2022 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
val snapshotVersion : String? = System.getenv("COMPOSE_SNAPSHOT_ID")
1617

1718
pluginManagement {
1819
repositories {
@@ -24,6 +25,11 @@ pluginManagement {
2425
dependencyResolutionManagement {
2526
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
2627
repositories {
28+
snapshotVersion?.let {
29+
println("https://androidx.dev/snapshots/builds/$it/artifacts/repository/")
30+
maven { url = uri("https://androidx.dev/snapshots/builds/$it/artifacts/repository/") }
31+
}
32+
2733
google()
2834
mavenCentral()
2935
}

scripts/test_snapshot.sh

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
# Copyright (C) 2022 The Android Open Source Project
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
########################################################################
18+
#
19+
# Allows testing a snapshot version across all samples
20+
#
21+
# Example: To run build over all projects run:
22+
# ./scripts/test_snapshot.sh
23+
#
24+
########################################################################
25+
26+
if [ -z "$1" ]; then
27+
read -p "Enter compose version e.g. 1.3.0: " compose_ver
28+
else
29+
echo "Using compose version: $1"
30+
compose_ver=$1
31+
fi
32+
if [ -z "$2" ]; then
33+
read -p "Enter snapshot ID: " snapshot
34+
else
35+
echo "Using compose snapshot: $2"
36+
snapshot=$2
37+
fi
38+
export COMPOSE_SNAPSHOT_ID=$snapshot
39+
40+
# Switch version to SNAPSHOT
41+
cp ./scripts/libs.versions.toml ./scripts/libs.versions.toml.tmp
42+
sed -i '' -e 's/^compose = ".*"/compose = "'$compose_ver'-SNAPSHOT"/g' ./scripts/libs.versions.toml
43+
44+
# Copy to all samples and verify
45+
./scripts/duplicate_version_config.sh
46+
./scripts/verify_samples.sh
47+
48+
# Undo all changes
49+
mv ./scripts/libs.versions.toml.tmp ./scripts/libs.versions.toml
50+
./scripts/duplicate_version_config.sh

0 commit comments

Comments
 (0)