Skip to content

Commit e459274

Browse files
committed
dataconnect: replace missingversions.py with the :firebase-dataconnet:updateJson gradle task
1 parent 5c7a993 commit e459274

File tree

10 files changed

+334
-298
lines changed

10 files changed

+334
-298
lines changed

.github/workflows/dataconnect.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,53 @@ jobs:
347347
working-directory: firebase-dataconnect/ci
348348
run: pyright --warnings --stats
349349

350+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
351+
with:
352+
show-progress: false
353+
354+
emulator-versions-outdated-check:
355+
continue-on-error: false
356+
runs-on: ubuntu-latest
357+
steps:
358+
- uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
359+
with:
360+
java-version: ${{ env.FDC_JAVA_VERSION }}
361+
distribution: temurin
362+
- uses: google-github-actions/auth@71f986410dfbc7added4569d411d040a91dc6935 # v2.1.8
363+
with:
364+
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT }}
365+
- uses: google-github-actions/setup-gcloud@77e7a554d41e2ee56fc945c52dfd3f33d12def9a # v2.1.4
366+
- name: Gradle updateJson
367+
run: |
368+
set -euo pipefail
369+
set -v
370+
371+
# Speed up build times and also avoid configuring firebase-crashlytics-ndk
372+
# which is finicky integrating with the Android NDK.
373+
echo >> gradle.properties
374+
echo "org.gradle.configureondemand=true" >> gradle.properties
375+
376+
readonly json_file='firebase-dataconnect/gradleplugin/plugin/src/main/resources/com/google/firebase/dataconnect/gradle/plugin/DataConnectExecutableVersions.json'
377+
cp "${json_file}" '${{ runner.temp }}/DataConnectExecutableVersions.before.json'
378+
379+
./gradlew \
380+
--warning-mode all \
381+
${{ (inputs.gradleInfoLog && '--info') || '' }} \
382+
:firebase-dataconnect:updateJson
383+
384+
cp "${json_file}" '${{ runner.temp }}/DataConnectExecutableVersions.after.json'
385+
386+
if diff DataConnectExecutableVersions.before.json DataConnectExecutableVersions.after.json ; then
387+
echo "${json_file} is up-to-date"
388+
else
389+
echo "${json_file} is NOT up-to-date"
390+
echo "To update it, run: ./gradlew :firebase-dataconnect:updateJson"
391+
if [[ '${{ github.event_name }}' == 'schedule' ]] ; then
392+
echo "FAILING STEP BECAUSE github.event_name==schedule and JSON file is not up-to-date" >&2
393+
exit 1
394+
fi
395+
fi
396+
350397
# The "send-notifications" job adds a comment to GitHub Issue
351398
# https://github.com/firebase/firebase-android-sdk/issues/6857 with the results of the scheduled
352399
# nightly runs. Interested parties can then subscribe to that issue to be aprised of the outcome
@@ -364,6 +411,7 @@ jobs:
364411
- 'python-ci-lint'
365412
- 'python-ci-format'
366413
- 'python-ci-type-check'
414+
- 'emulator-versions-outdated-check'
367415
if: always()
368416
permissions:
369417
issues: write
@@ -389,6 +437,7 @@ jobs:
389437
python-ci-lint:${{ needs.python-ci-lint.result }}
390438
python-ci-format:${{ needs.python-ci-format.result }}
391439
python-ci-type-check:${{ needs.python-ci-type-check.result }}
440+
emulator-versions-outdated-check:${{ needs.emulator-versions-outdated-check.result }}
392441
EOF
393442
394443
- uses: ./.github/actions/dataconnect-send-notifications

firebase-dataconnect/connectors/connectors.gradle.kts

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import com.google.firebase.dataconnect.gradle.plugin.UpdateDataConnectExecutableVersionsTask
1817
import org.gradle.kotlin.dsl.withType
1918
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2019
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
@@ -113,98 +112,3 @@ tasks.withType<KotlinJvmCompile>().configureEach {
113112
compilerOptions.freeCompilerArgs.add("-Xexplicit-api=strict")
114113
}
115114
}
116-
117-
// Adds a Gradle task that updates the JSON file that stores the list of Data Connect
118-
// executable versions.
119-
//
120-
// Example 1: Add versions 1.4.3 and 1.4.4 to the JSON file, and set 1.4.4 as the default:
121-
// ../../gradlew -Pversions=1.4.3,1.4.4 -PdefaultVersion=1.4.4 updateJson --info
122-
//
123-
// Example 2: Add version 1.2.3 to the JSON file, but do not change the default version:
124-
// ../../gradlew -Pversion=1.2.3 updateJson --info
125-
//
126-
// The `--info` argument can be omitted; it merely controls the level of log output.
127-
tasks.register<UpdateDataConnectExecutableVersionsTask>("updateJson") {
128-
outputs.upToDateWhen { false }
129-
jsonFile.set(
130-
project.layout.projectDirectory.file(
131-
"../gradleplugin/plugin/src/main/resources/com/google/firebase/dataconnect/gradle/" +
132-
"plugin/DataConnectExecutableVersions.json"
133-
)
134-
)
135-
workDirectory.set(project.layout.buildDirectory.dir("updateJson"))
136-
137-
val propertyNames =
138-
object {
139-
val version = "version"
140-
val versions = "versions"
141-
val updateMode = "updateMode"
142-
val defaultVersion = "defaultVersion"
143-
}
144-
145-
val singleVersion: String? = project.providers.gradleProperty(propertyNames.version).orNull
146-
val multipleVersions: List<String>? =
147-
project.providers.gradleProperty(propertyNames.versions).orNull?.split(',')
148-
versions.set(
149-
buildList {
150-
singleVersion?.let { add(it) }
151-
multipleVersions?.let { addAll(it) }
152-
}
153-
)
154-
155-
doFirst {
156-
if (versions.get().isEmpty()) {
157-
logger.warn(
158-
"WARNING: no '${propertyNames.version}' or '${propertyNames.versions}' specified " +
159-
"for task '$name'; no versions will be added to ${jsonFile.get()}. " +
160-
"Try specifying something like '-P${propertyNames.version}=1.2.3' or " +
161-
"'-P${propertyNames.versions}=1.2.3,4.5.6' on the gradle command line " +
162-
"if you want to add versions (warning code bm6d5ezxzd)"
163-
)
164-
}
165-
}
166-
167-
updateMode.set(
168-
project.providers.gradleProperty(propertyNames.updateMode).map {
169-
when (it) {
170-
"overwrite" -> UpdateDataConnectExecutableVersionsTask.UpdateMode.Overwrite
171-
"update" -> UpdateDataConnectExecutableVersionsTask.UpdateMode.Update
172-
else ->
173-
throw Exception(
174-
"Invalid '${propertyNames.updateMode}' specified for task '$name': $it. " +
175-
"Valid values are 'update' and 'overwrite'. " +
176-
"Try specifying '-P${propertyNames.updateMode}=update' or " +
177-
"'-P${propertyNames.updateMode}=overwrite' on the gradle command line. " +
178-
"(error code v2e3cfqbnf)"
179-
)
180-
}
181-
}
182-
)
183-
184-
doFirst {
185-
if (!updateMode.isPresent) {
186-
logger.warn(
187-
"WARNING: no '${propertyNames.updateMode}' specified for task '$name'; " +
188-
"the default update mode of 'update' will be used when updating ${jsonFile.get()}. " +
189-
"Try specifying '-P${propertyNames.updateMode}=update' or " +
190-
"'-P${propertyNames.updateMode}=overwrite' on the gradle command line " +
191-
"if you want a different update mode, or just want to be explicit about " +
192-
"which update mode is in effect (warning code tjyscqmdne)"
193-
)
194-
}
195-
}
196-
197-
defaultVersion.set(project.providers.gradleProperty(propertyNames.defaultVersion))
198-
199-
doFirst {
200-
if (!defaultVersion.isPresent) {
201-
logger.warn(
202-
"WARNING: no '${propertyNames.defaultVersion}' specified for task '$name'; " +
203-
"the default version will not be updated in ${jsonFile.get()}. " +
204-
"Try specifying something like '-P${propertyNames.defaultVersion}=1.2.3' " +
205-
"on the gradle command line if you want to update the default version " +
206-
"(warning code vqrbrktx9f)"
207-
)
208-
}
209-
}
210-
}

firebase-dataconnect/firebase-dataconnect.gradle.kts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import com.google.firebase.dataconnect.gradle.plugin.UpdateDataConnectExecutableVersionsTask
1718
import org.gradle.kotlin.dsl.withType
1819
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
1920
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
@@ -24,6 +25,7 @@ plugins {
2425
id("com.google.protobuf")
2526
id("copy-google-services")
2627
alias(libs.plugins.kotlinx.serialization)
28+
id("com.google.firebase.dataconnect.gradle.plugin") apply false
2729
}
2830

2931
firebaseLibrary {
@@ -163,3 +165,16 @@ tasks.withType<KotlinJvmCompile>().configureEach {
163165
compilerOptions.freeCompilerArgs.add("-Xexplicit-api=strict")
164166
}
165167
}
168+
169+
// Registers a Gradle task that updates the JSON file that stores the list of Data Connect
170+
// executable versions. The task gets the list of all versions from the Internet and then
171+
// updates the JSON file with their sizes and hashes.
172+
tasks.register<UpdateDataConnectExecutableVersionsTask>("updateJson") {
173+
jsonFile.set(
174+
file(
175+
"gradleplugin/plugin/src/main/resources/com/google/firebase/dataconnect/gradle/" +
176+
"plugin/DataConnectExecutableVersions.json"
177+
)
178+
)
179+
workDirectory.set(project.layout.buildDirectory.dir("updateJson"))
180+
}

firebase-dataconnect/gradleplugin/plugin/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ dependencies {
2828
implementation(gradleKotlinDsl())
2929
implementation(firebaseLibs.kotlinx.serialization.core)
3030
implementation(firebaseLibs.kotlinx.serialization.json)
31+
implementation("com.google.cloud:google-cloud-storage:2.56.0")
32+
implementation("io.github.z4kn4fein:semver:3.0.0")
3133
}
3234

3335
gradlePlugin {

firebase-dataconnect/gradleplugin/plugin/src/main/kotlin/com/google/firebase/dataconnect/gradle/plugin/DataConnectExecutableDownloadTask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ abstract class DataConnectExecutableDownloadTask : DefaultTask() {
110110
.sorted()
111111
.joinToString(", ")
112112
val applicableVersions =
113-
allVersions.filter { it.version == version && it.os == operatingSystem }
113+
allVersions.filter { it.version.toString() == version && it.os == operatingSystem }
114114

115115
if (applicableVersions.isEmpty()) {
116116
val message =

firebase-dataconnect/gradleplugin/plugin/src/main/kotlin/com/google/firebase/dataconnect/gradle/plugin/DataConnectExecutableVersionRegistry.kt

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.google.firebase.dataconnect.gradle.plugin
1717

18+
import io.github.z4kn4fein.semver.LooseVersionSerializer
19+
import io.github.z4kn4fein.semver.Version
1820
import java.io.InputStream
1921
import java.io.OutputStream
2022
import kotlinx.serialization.ExperimentalSerializationApi
@@ -38,6 +40,7 @@ object DataConnectExecutableVersionsRegistry {
3840
Json {
3941
prettyPrint = true
4042
prettyPrintIndent = " "
43+
allowTrailingComma = true
4144
}
4245
}
4346

@@ -59,13 +62,13 @@ object DataConnectExecutableVersionsRegistry {
5962

6063
@Serializable
6164
data class Root(
62-
val defaultVersion: String,
65+
@Serializable(with = LooseVersionSerializer::class) val defaultVersion: Version,
6366
val versions: List<VersionInfo>,
6467
)
6568

6669
@Serializable
6770
data class VersionInfo(
68-
val version: String,
71+
@Serializable(with = LooseVersionSerializer::class) val version: Version,
6972
@Serializable(with = OperatingSystemSerializer::class) val os: OperatingSystem,
7073
val size: Long,
7174
val sha512DigestHex: String,
@@ -79,24 +82,24 @@ object DataConnectExecutableVersionsRegistry {
7982
)
8083

8184
override fun deserialize(decoder: Decoder): OperatingSystem =
82-
when (val name = decoder.decodeString()) {
83-
"windows" -> OperatingSystem.Windows
84-
"macos" -> OperatingSystem.MacOS
85-
"linux" -> OperatingSystem.Linux
86-
else ->
87-
throw DataConnectGradleException(
85+
decoder.decodeString().let { serializedValue ->
86+
OperatingSystem.entries.singleOrNull { it.serializedValue == serializedValue }
87+
?: throw DataConnectGradleException(
8888
"nd5z2jk4hr",
89-
"Unknown operating system: $name (must be windows, macos, or linux)"
89+
"Unknown operating system: $serializedValue " +
90+
"(must be one of ${OperatingSystem.entries.joinToString { it.serializedValue }})"
9091
)
9192
}
9293

9394
override fun serialize(encoder: Encoder, value: OperatingSystem) =
94-
encoder.encodeString(
95-
when (value) {
96-
OperatingSystem.Windows -> "windows"
97-
OperatingSystem.MacOS -> "macos"
98-
OperatingSystem.Linux -> "linux"
99-
}
100-
)
95+
encoder.encodeString(value.serializedValue)
10196
}
97+
98+
val OperatingSystem.serializedValue: String
99+
get() =
100+
when (this) {
101+
OperatingSystem.Windows -> "windows"
102+
OperatingSystem.MacOS -> "macos"
103+
OperatingSystem.Linux -> "linux"
104+
}
102105
}

firebase-dataconnect/gradleplugin/plugin/src/main/kotlin/com/google/firebase/dataconnect/gradle/plugin/DataConnectProviders.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class DataConnectProviders(
4949
val defaultVersion: Provider<DataConnectExecutable> =
5050
project.provider {
5151
val root = DataConnectExecutableVersionsRegistry.load()
52-
DataConnectExecutable.Version(root.defaultVersion)
52+
DataConnectExecutable.Version(root.defaultVersion.toString())
5353
}
5454

5555
valueFromLocalSettings

0 commit comments

Comments
 (0)