Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/dataconnect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,63 @@
working-directory: firebase-dataconnect/ci
run: pyright --warnings --stats

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
show-progress: false

emulator-versions-outdated-check:
continue-on-error: false
runs-on: ubuntu-latest
steps:
- uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
with:
java-version: ${{ env.FDC_JAVA_VERSION }}
distribution: temurin
- uses: google-github-actions/auth@71f986410dfbc7added4569d411d040a91dc6935 # v2.1.8
with:
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT }}
- uses: google-github-actions/setup-gcloud@77e7a554d41e2ee56fc945c52dfd3f33d12def9a # v2.1.4
- name: Gradle updateJson
run: |
set -euo pipefail
set -v

# Speed up build times and also avoid configuring firebase-crashlytics-ndk
# which is finicky integrating with the Android NDK.
echo >> gradle.properties
echo "org.gradle.configureondemand=true" >> gradle.properties

readonly json_file='firebase-dataconnect/gradleplugin/plugin/src/main/resources/com/google/firebase/dataconnect/gradle/plugin/DataConnectExecutableVersions.json'
cp "${json_file}" '${{ runner.temp }}/DataConnectExecutableVersions.before.json'

./gradlew \
--warning-mode all \
${{ (inputs.gradleInfoLog && '--info') || '' }} \
:firebase-dataconnect:updateJson

cp "${json_file}" '${{ runner.temp }}/DataConnectExecutableVersions.after.json'

if diff DataConnectExecutableVersions.before.json DataConnectExecutableVersions.after.json ; then
echo "${json_file} is up-to-date"
else
echo "${json_file} is NOT up-to-date"
echo "To update it, run: ./gradlew :firebase-dataconnect:updateJson"
if [[ '${{ github.event_name }}' == 'schedule' ]] ; then
echo "FAILING STEP BECAUSE github.event_name==schedule and JSON file is not up-to-date" >&2
exit 1
fi
fi

# The "send-notifications" job adds a comment to GitHub Issue
# https://github.com/firebase/firebase-android-sdk/issues/6857 with the results of the scheduled
# nightly runs. Interested parties can then subscribe to that issue to be aprised of the outcome
# of the nightly runs.
#
# When testing the comment-adding logic itself, you can add the line
# trksmnkncd_notification_issue=6863
# into the PR's description to instead post a comment to issue #6863, an issue specifically
# created for testing, avoiding spamming the main issue to which others are subscribed.
send-notifications:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
needs:
- 'integration-test'
- 'actionlint-dataconnect-yml'
Expand All @@ -364,6 +411,7 @@
- 'python-ci-lint'
- 'python-ci-format'
- 'python-ci-type-check'
- 'emulator-versions-outdated-check'
if: always()
permissions:
issues: write
Expand All @@ -389,6 +437,7 @@
python-ci-lint:${{ needs.python-ci-lint.result }}
python-ci-format:${{ needs.python-ci-format.result }}
python-ci-type-check:${{ needs.python-ci-type-check.result }}
emulator-versions-outdated-check:${{ needs.emulator-versions-outdated-check.result }}
EOF

- uses: ./.github/actions/dataconnect-send-notifications
Expand Down
96 changes: 0 additions & 96 deletions firebase-dataconnect/connectors/connectors.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import com.google.firebase.dataconnect.gradle.plugin.UpdateDataConnectExecutableVersionsTask
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
Expand Down Expand Up @@ -113,98 +112,3 @@ tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions.freeCompilerArgs.add("-Xexplicit-api=strict")
}
}

// Adds a Gradle task that updates the JSON file that stores the list of Data Connect
// executable versions.
//
// Example 1: Add versions 1.4.3 and 1.4.4 to the JSON file, and set 1.4.4 as the default:
// ../../gradlew -Pversions=1.4.3,1.4.4 -PdefaultVersion=1.4.4 updateJson --info
//
// Example 2: Add version 1.2.3 to the JSON file, but do not change the default version:
// ../../gradlew -Pversion=1.2.3 updateJson --info
//
// The `--info` argument can be omitted; it merely controls the level of log output.
tasks.register<UpdateDataConnectExecutableVersionsTask>("updateJson") {
outputs.upToDateWhen { false }
jsonFile.set(
project.layout.projectDirectory.file(
"../gradleplugin/plugin/src/main/resources/com/google/firebase/dataconnect/gradle/" +
"plugin/DataConnectExecutableVersions.json"
)
)
workDirectory.set(project.layout.buildDirectory.dir("updateJson"))

val propertyNames =
object {
val version = "version"
val versions = "versions"
val updateMode = "updateMode"
val defaultVersion = "defaultVersion"
}

val singleVersion: String? = project.providers.gradleProperty(propertyNames.version).orNull
val multipleVersions: List<String>? =
project.providers.gradleProperty(propertyNames.versions).orNull?.split(',')
versions.set(
buildList {
singleVersion?.let { add(it) }
multipleVersions?.let { addAll(it) }
}
)

doFirst {
if (versions.get().isEmpty()) {
logger.warn(
"WARNING: no '${propertyNames.version}' or '${propertyNames.versions}' specified " +
"for task '$name'; no versions will be added to ${jsonFile.get()}. " +
"Try specifying something like '-P${propertyNames.version}=1.2.3' or " +
"'-P${propertyNames.versions}=1.2.3,4.5.6' on the gradle command line " +
"if you want to add versions (warning code bm6d5ezxzd)"
)
}
}

updateMode.set(
project.providers.gradleProperty(propertyNames.updateMode).map {
when (it) {
"overwrite" -> UpdateDataConnectExecutableVersionsTask.UpdateMode.Overwrite
"update" -> UpdateDataConnectExecutableVersionsTask.UpdateMode.Update
else ->
throw Exception(
"Invalid '${propertyNames.updateMode}' specified for task '$name': $it. " +
"Valid values are 'update' and 'overwrite'. " +
"Try specifying '-P${propertyNames.updateMode}=update' or " +
"'-P${propertyNames.updateMode}=overwrite' on the gradle command line. " +
"(error code v2e3cfqbnf)"
)
}
}
)

doFirst {
if (!updateMode.isPresent) {
logger.warn(
"WARNING: no '${propertyNames.updateMode}' specified for task '$name'; " +
"the default update mode of 'update' will be used when updating ${jsonFile.get()}. " +
"Try specifying '-P${propertyNames.updateMode}=update' or " +
"'-P${propertyNames.updateMode}=overwrite' on the gradle command line " +
"if you want a different update mode, or just want to be explicit about " +
"which update mode is in effect (warning code tjyscqmdne)"
)
}
}

defaultVersion.set(project.providers.gradleProperty(propertyNames.defaultVersion))

doFirst {
if (!defaultVersion.isPresent) {
logger.warn(
"WARNING: no '${propertyNames.defaultVersion}' specified for task '$name'; " +
"the default version will not be updated in ${jsonFile.get()}. " +
"Try specifying something like '-P${propertyNames.defaultVersion}=1.2.3' " +
"on the gradle command line if you want to update the default version " +
"(warning code vqrbrktx9f)"
)
}
}
}
15 changes: 15 additions & 0 deletions firebase-dataconnect/firebase-dataconnect.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import com.google.firebase.dataconnect.gradle.plugin.UpdateDataConnectExecutableVersionsTask
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
Expand All @@ -24,6 +25,7 @@ plugins {
id("com.google.protobuf")
id("copy-google-services")
alias(libs.plugins.kotlinx.serialization)
id("com.google.firebase.dataconnect.gradle.plugin") apply false
}

firebaseLibrary {
Expand Down Expand Up @@ -163,3 +165,16 @@ tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions.freeCompilerArgs.add("-Xexplicit-api=strict")
}
}

// Registers a Gradle task that updates the JSON file that stores the list of Data Connect
// executable versions. The task gets the list of all versions from the Internet and then
// updates the JSON file with their sizes and hashes.
tasks.register<UpdateDataConnectExecutableVersionsTask>("updateJson") {
jsonFile.set(
file(
"gradleplugin/plugin/src/main/resources/com/google/firebase/dataconnect/gradle/" +
"plugin/DataConnectExecutableVersions.json"
)
)
workDirectory.set(project.layout.buildDirectory.dir("updateJson"))
}
2 changes: 2 additions & 0 deletions firebase-dataconnect/gradleplugin/plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ dependencies {
implementation(gradleKotlinDsl())
implementation(firebaseLibs.kotlinx.serialization.core)
implementation(firebaseLibs.kotlinx.serialization.json)
implementation("com.google.cloud:google-cloud-storage:2.56.0")
implementation("io.github.z4kn4fein:semver:3.0.0")
}

gradlePlugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ abstract class DataConnectExecutableDownloadTask : DefaultTask() {
.sorted()
.joinToString(", ")
val applicableVersions =
allVersions.filter { it.version == version && it.os == operatingSystem }
allVersions.filter { it.version.toString() == version && it.os == operatingSystem }

if (applicableVersions.isEmpty()) {
val message =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.google.firebase.dataconnect.gradle.plugin

import io.github.z4kn4fein.semver.LooseVersionSerializer
import io.github.z4kn4fein.semver.Version
import java.io.InputStream
import java.io.OutputStream
import kotlinx.serialization.ExperimentalSerializationApi
Expand All @@ -38,6 +40,7 @@ object DataConnectExecutableVersionsRegistry {
Json {
prettyPrint = true
prettyPrintIndent = " "
allowTrailingComma = true
}
}

Expand All @@ -59,13 +62,13 @@ object DataConnectExecutableVersionsRegistry {

@Serializable
data class Root(
val defaultVersion: String,
@Serializable(with = LooseVersionSerializer::class) val defaultVersion: Version,
val versions: List<VersionInfo>,
)

@Serializable
data class VersionInfo(
val version: String,
@Serializable(with = LooseVersionSerializer::class) val version: Version,
@Serializable(with = OperatingSystemSerializer::class) val os: OperatingSystem,
val size: Long,
val sha512DigestHex: String,
Expand All @@ -79,24 +82,24 @@ object DataConnectExecutableVersionsRegistry {
)

override fun deserialize(decoder: Decoder): OperatingSystem =
when (val name = decoder.decodeString()) {
"windows" -> OperatingSystem.Windows
"macos" -> OperatingSystem.MacOS
"linux" -> OperatingSystem.Linux
else ->
throw DataConnectGradleException(
decoder.decodeString().let { serializedValue ->
OperatingSystem.entries.singleOrNull { it.serializedValue == serializedValue }
?: throw DataConnectGradleException(
"nd5z2jk4hr",
"Unknown operating system: $name (must be windows, macos, or linux)"
"Unknown operating system: $serializedValue " +
"(must be one of ${OperatingSystem.entries.joinToString { it.serializedValue }})"
)
}

override fun serialize(encoder: Encoder, value: OperatingSystem) =
encoder.encodeString(
when (value) {
OperatingSystem.Windows -> "windows"
OperatingSystem.MacOS -> "macos"
OperatingSystem.Linux -> "linux"
}
)
encoder.encodeString(value.serializedValue)
}

val OperatingSystem.serializedValue: String
get() =
when (this) {
OperatingSystem.Windows -> "windows"
OperatingSystem.MacOS -> "macos"
OperatingSystem.Linux -> "linux"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DataConnectProviders(
val defaultVersion: Provider<DataConnectExecutable> =
project.provider {
val root = DataConnectExecutableVersionsRegistry.load()
DataConnectExecutable.Version(root.defaultVersion)
DataConnectExecutable.Version(root.defaultVersion.toString())
}

valueFromLocalSettings
Expand Down
Loading
Loading