Skip to content

Commit 68abe55

Browse files
authored
Merge branch 'master' into ehsann/update-or-query-tests
2 parents fd48900 + d08e208 commit 68abe55

File tree

134 files changed

+5205
-1153
lines changed

Some content is hidden

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

134 files changed

+5205
-1153
lines changed

.github/workflows/ci_tests.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,47 @@ jobs:
130130
run: |
131131
./gradlew ${{matrix.module}}:deviceCheck withErrorProne -PtargetBackend="prod"
132132
133+
firestore_custom_integ_tests:
134+
name: "Firestore Custom Instrumentation Tests Against Named DB"
135+
runs-on: ubuntu-22.04
136+
needs:
137+
- determine_changed
138+
# only run on post submit or PRs not originating from forks.
139+
if: ((github.repository == 'Firebase/firebase-android-sdk' && github.event_name == 'push') || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)) && contains(fromJSON(needs.determine_changed.outputs.modules), ':firebase-firestore')
140+
strategy:
141+
fail-fast: false
142+
143+
steps:
144+
- uses: actions/[email protected]
145+
with:
146+
fetch-depth: 2
147+
submodules: true
148+
149+
- name: Set up JDK 11
150+
uses: actions/setup-java@v3
151+
with:
152+
java-version: 11
153+
distribution: temurin
154+
cache: gradle
155+
156+
- name: Add google-services.json
157+
env:
158+
INTEG_TESTS_GOOGLE_SERVICES: ${{ secrets.INTEG_TESTS_GOOGLE_SERVICES }}
159+
run: |
160+
echo $INTEG_TESTS_GOOGLE_SERVICES | base64 -d > google-services.json
161+
- uses: google-github-actions/auth@v0
162+
with:
163+
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT }}
164+
- uses: google-github-actions/setup-gcloud@v0
165+
- name: Firestore Named DB Integ Tests
166+
env:
167+
FIREBASE_CI: 1
168+
FTL_RESULTS_BUCKET: android-ci
169+
FTL_RESULTS_DIR: ${{ github.event_name == 'pull_request' && format('pr-logs/pull/{0}/{1}/{2}/{3}_{4}/artifacts/', github.repository, github.event.pull_request.number, github.job, github.run_id, github.run_attempt) || format('logs/{0}/{1}_{2}/artifacts/', github.workflow, github.run_id, github.run_attempt)}}
170+
FIREBASE_APP_CHECK_DEBUG_SECRET: ${{ secrets.FIREBASE_APP_CHECK_DEBUG_SECRET }}
171+
run: |
172+
./gradlew firebase-firestore:deviceCheck withErrorProne -PtargetBackend="prod" -PtargetDatabaseId="test-db"
173+
133174
publish-test-results:
134175
name: "Publish Tests Results"
135176
needs:

.github/workflows/version-check.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Version Check
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- 'releases/**'
8+
9+
jobs:
10+
version-check:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/[email protected]
14+
15+
- name: Build
16+
run: |
17+
./gradlew gmavenVersionCheck

README.md

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ https://firebase.google.com.
6565
* Import the firebase-android-sdk gradle project into Android Studio using the
6666
**Import project(Gradle, Eclipse ADT, etc.)** option.
6767
* `firebase-crashlytics-ndk` must be built with NDK 21. See
68-
[firebase-crashlytics-ndk](firebase-crashlytics-ndk/README.md) for more
68+
[firebase-crashlytics-ndk](firebase-crashlytics-ndk/README.md) for more
6969
details.
7070

7171
## Testing
@@ -143,7 +143,7 @@ Integration tests can be executed on the command line by running
143143
```
144144

145145
This will execute tests on devices that are configured per project, if nothing is configured for the
146-
project, the tests will run on `model=Pixel2,version=27,locale=en,orientation=portrait`.
146+
project, the tests will run on `model=panther,version=33,locale=en,orientation=portrait`.
147147

148148
Projects can be configured in the following way:
149149

@@ -225,30 +225,21 @@ strategy](https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.Resolutio
225225

226226
### Commands
227227

228-
The simplest way to publish a project and all its associated dependencies is to
229-
just publish all projects. The following command builds SNAPSHOT dependencies of
230-
all projects. All pom level dependencies within the published artifacts will
231-
also point to SNAPSHOT versions that are co-published.
228+
For more advanced use cases where developers wish to make changes to a project,
229+
but have transitive dependencies point to publicly released versions, individual
230+
projects may be published as follows.
232231

233232
```bash
234-
./gradlew publishAllToLocal
233+
# e.g. to publish Firestore and Functions
234+
./gradlew -PprojectsToPublish="firebase-firestore,firebase-functions" \
235+
publishReleasingLibrariesToMavenLocal
235236
```
236237

237238
Developers may take a dependency on these locally published versions by adding
238239
the `mavenLocal()` repository to your [repositories
239240
block](https://docs.gradle.org/current/userguide/declaring_repositories.html) in
240241
your app module's build.gradle.
241242

242-
For more advanced use cases where developers wish to make changes to a project,
243-
but have transitive dependencies point to publicly released versions, individual
244-
projects may be published as follows.
245-
246-
```bash
247-
# e.g. to publish Firestore and Functions
248-
./gradlew -PprojectsToPublish=":firebase-firestore,:firebase-functions" \
249-
publishProjectsToMavenLocal
250-
```
251-
252243
### Code Formatting
253244

254245
#### Java

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ ext {
5858
protobufJavaUtilVersion = libs.versions.protobufjavautil.get()
5959
}
6060

61+
apply plugin: com.google.firebase.gradle.plugins.PublishingPlugin
62+
6163
apply plugin: com.google.firebase.gradle.plugins.ci.ContinuousIntegrationPlugin
6264
apply plugin: com.google.firebase.gradle.plugins.ci.SmokeTestsPlugin
6365

64-
apply plugin: com.google.firebase.gradle.plugins.PublishingPlugin
65-
6666
firebaseContinuousIntegration {
6767
ignorePaths = [
6868
/.*\.gitignore$/,

buildSrc/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Build Source
22

3+
> [!NOTE]
4+
> Eventually, this will be merged with our [contributor documentation](https://firebase.github.io/firebase-android-sdk/).
5+
36
This file will be more organized as time progresses. Because a lot of our
47
plugins and systems require a moderate amount of cognitive overhead to understand,
58
I thought it best to provide documentation for such systems. You can find the

buildSrc/src/main/java/com/google/firebase/gradle/bomgenerator/RecipeVersionWriter.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,6 @@ public String generateVersionUpdate() {
173173
"Firebase Functions KTX",
174174
"functions-ktx-dependency",
175175
"com.google.firebase:firebase-functions-ktx"));
176-
outputBuilder.append(
177-
generateVersionVariable(
178-
depsByArtifactId,
179-
"Firebase Dynamic Links",
180-
"fdl-dependency",
181-
"com.google.firebase:firebase-dynamic-links"));
182-
outputBuilder.append(
183-
generateVersionVariable(
184-
depsByArtifactId,
185-
"Firebase Dynamic Links KTX",
186-
"fdl-ktx-dependency",
187-
"com.google.firebase:firebase-dynamic-links-ktx"));
188176
outputBuilder.append(
189177
generateVersionVariable(
190178
depsByArtifactId,

buildSrc/src/main/java/com/google/firebase/gradle/plugins/BaseFirebaseLibraryPlugin.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,18 @@ fun FirebaseLibraryExtension.resolveExternalAndroidLibraries() =
276276
*/
277277
val FirebaseLibraryExtension.artifactName: String
278278
get() = "$mavenName:$version"
279+
280+
/**
281+
* Fetches the latest version for this SDK from GMaven.
282+
*
283+
* Uses [GmavenHelper] to make the request.
284+
*/
285+
val FirebaseLibraryExtension.latestVersion: ModuleVersion
286+
get() {
287+
val latestVersion = GmavenHelper(groupId.get(), artifactId.get()).getLatestReleasedVersion()
288+
289+
return ModuleVersion.fromStringOrNull(latestVersion)
290+
?: throw RuntimeException(
291+
"Invalid format for ModuleVersion for module '$artifactName':\n $latestVersion"
292+
)
293+
}

buildSrc/src/main/java/com/google/firebase/gradle/plugins/FirebaseJavaLibraryPlugin.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,17 @@ class FirebaseJavaLibraryPlugin : BaseFirebaseLibraryPlugin() {
5656
setupStaticAnalysis(project, firebaseLibrary)
5757
setupApiInformationAnalysis(project)
5858
getIsPomValidTask(project, firebaseLibrary)
59-
getSemverTaskJar(project, firebaseLibrary)
59+
setupVersionCheckTasks(project, firebaseLibrary)
6060
configurePublishing(project, firebaseLibrary)
6161
}
6262

63-
private fun getSemverTaskJar(project: Project, firebaseLibrary: FirebaseLibraryExtension) {
63+
private fun setupVersionCheckTasks(project: Project, firebaseLibrary: FirebaseLibraryExtension) {
64+
project.tasks.register<GmavenVersionChecker>("gmavenVersionCheck") {
65+
groupId.value(firebaseLibrary.groupId.get())
66+
artifactId.value(firebaseLibrary.artifactId.get())
67+
version.value(firebaseLibrary.version)
68+
latestReleasedVersion.value(firebaseLibrary.latestReleasedVersion.orElseGet { "" })
69+
}
6470
project.mkdir("semver")
6571
project.tasks.register<GmavenCopier>("copyPreviousArtifacts") {
6672
dependsOn("jar")

buildSrc/src/main/java/com/google/firebase/gradle/plugins/FirebaseLibraryExtension.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Collections;
2222
import java.util.Optional;
2323
import java.util.Set;
24-
import java.util.stream.Collectors;
2524
import javax.inject.Inject;
2625
import org.gradle.api.Action;
2726
import org.gradle.api.Project;
@@ -50,8 +49,7 @@ public class FirebaseLibraryExtension {
5049
public Property<String> groupId;
5150
public Property<String> artifactId;
5251

53-
private String libraryGroupName;
54-
private LibraryGroupRegistrar libraryGroupRegistrar;
52+
String libraryGroupName;
5553

5654
private Action<MavenPom> customizePomAction =
5755
pom -> {
@@ -86,8 +84,7 @@ public FirebaseLibraryExtension(Project project, LibraryType type) {
8684
groupId.set(new DefaultProvider<>(() -> project.getGroup().toString()));
8785
}
8886
this.staticAnalysis = initializeStaticAnalysis(project);
89-
this.libraryGroupRegistrar = LibraryGroupRegistrar.getInstance();
90-
libraryGroupName = "";
87+
libraryGroupName = this.artifactId.get();
9188
}
9289

9390
private FirebaseStaticAnalysis initializeStaticAnalysis(Project project) {
@@ -115,18 +112,6 @@ public void testLab(Action<FirebaseTestLabExtension> action) {
115112
*/
116113
public void libraryGroup(String libraryGroupName) {
117114
this.libraryGroupName = libraryGroupName;
118-
libraryGroupRegistrar.registerLibrary(libraryGroupName, this);
119-
}
120-
121-
public Set<Project> getProjectsToRelease() {
122-
return getLibrariesToRelease().stream().map(l -> l.project).collect(Collectors.toSet());
123-
}
124-
125-
public Set<FirebaseLibraryExtension> getLibrariesToRelease() {
126-
return ImmutableSet.<FirebaseLibraryExtension>builder()
127-
.addAll(libraryGroupRegistrar.getLibrariesForGroup(libraryGroupName))
128-
.add(this)
129-
.build();
130115
}
131116

132117
/** Provides a hook to customize pom generation. */

buildSrc/src/main/java/com/google/firebase/gradle/plugins/FirebaseLibraryPlugin.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,19 @@ class FirebaseLibraryPlugin : BaseFirebaseLibraryPlugin() {
8585
android.testServer(FirebaseTestServer(project, firebaseLibrary.testLab, android))
8686
setupStaticAnalysis(project, firebaseLibrary)
8787
getIsPomValidTask(project, firebaseLibrary)
88-
getSemverTaskAar(project, firebaseLibrary)
88+
setupVersionCheckTasks(project, firebaseLibrary)
8989
configurePublishing(project, firebaseLibrary, android)
9090
}
9191

92-
private fun getSemverTaskAar(project: Project, firebaseLibrary: FirebaseLibraryExtension) {
92+
private fun setupVersionCheckTasks(project: Project, firebaseLibrary: FirebaseLibraryExtension) {
93+
project.tasks.register<GmavenVersionChecker>("gmavenVersionCheck") {
94+
groupId.value(firebaseLibrary.groupId.get())
95+
artifactId.value(firebaseLibrary.artifactId.get())
96+
version.value(firebaseLibrary.version)
97+
latestReleasedVersion.value(firebaseLibrary.latestReleasedVersion.orElseGet { "" })
98+
}
9399
project.mkdir("semver")
100+
project.mkdir("semver/previous-version")
94101
project.tasks.register<GmavenCopier>("copyPreviousArtifacts") {
95102
dependsOn("bundleReleaseAar")
96103
project.file("semver/previous.aar").delete()
@@ -111,7 +118,10 @@ class FirebaseLibraryPlugin : BaseFirebaseLibraryPlugin() {
111118

112119
project.tasks.register<Copy>("extractPreviousClasses") {
113120
dependsOn("copyPreviousArtifacts")
114-
if (project.file("semver/previous.aar").exists()) {
121+
if (
122+
GmavenHelper(firebaseLibrary.groupId.get(), firebaseLibrary.artifactId.get())
123+
.isPresentInGmaven()
124+
) {
115125
from(project.zipTree("semver/previous.aar"))
116126
into(project.file("semver/previous-version"))
117127
}
@@ -121,15 +131,15 @@ class FirebaseLibraryPlugin : BaseFirebaseLibraryPlugin() {
121131

122132
val previousJarFile = project.file("semver/previous-version/classes.jar").absolutePath
123133
project.tasks.register<ApiDiffer>("semverCheck") {
134+
dependsOn("extractCurrentClasses")
135+
dependsOn("extractPreviousClasses")
124136
currentJar.value(currentJarFile)
125137
previousJar.value(previousJarFile)
126138
version.value(firebaseLibrary.version)
127139
previousVersionString.value(
128140
GmavenHelper(firebaseLibrary.groupId.get(), firebaseLibrary.artifactId.get())
129141
.getLatestReleasedVersion()
130142
)
131-
dependsOn("extractCurrentClasses")
132-
dependsOn("extractPreviousClasses")
133143
}
134144
}
135145

buildSrc/src/main/java/com/google/firebase/gradle/plugins/GmavenHelper.kt

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.google.firebase.gradle.plugins
1616

1717
import java.io.FileNotFoundException
18+
import java.net.HttpURLConnection
1819
import java.net.URL
1920
import javax.xml.parsers.DocumentBuilder
2021
import javax.xml.parsers.DocumentBuilderFactory
@@ -30,24 +31,52 @@ class GmavenHelper(val groupId: String, val artifactId: String) {
3031
return "${GMAVEN_ROOT}/${groupIdAsPath}/${artifactId}/${version}/${pomFileName}"
3132
}
3233

34+
fun isPresentInGmaven(): Boolean {
35+
val groupIdAsPath = groupId.replace(".", "/")
36+
val u = URL("${GMAVEN_ROOT}/${groupIdAsPath}/${artifactId}/maven-metadata.xml")
37+
val huc: HttpURLConnection = u.openConnection() as HttpURLConnection
38+
huc.setRequestMethod("GET") // OR huc.setRequestMethod ("HEAD");
39+
huc.connect()
40+
val code: Int = huc.getResponseCode()
41+
return code == HttpURLConnection.HTTP_OK
42+
}
43+
3344
fun getArtifactForVersion(version: String, isJar: Boolean): String {
3445
val fileName =
3546
if (isJar == true) "${artifactId}-${version}.jar" else "${artifactId}-${version}.aar"
3647
val groupIdAsPath = groupId.replace(".", "/")
3748
return "${GMAVEN_ROOT}/${groupIdAsPath}/${artifactId}/${version}/${fileName}"
3849
}
3950

51+
fun hasReleasedVersion(version: String): Boolean {
52+
val doc: Document? = getMavenMetadata()
53+
if (doc != null) {
54+
val versions = doc.getElementsByTagName("version")
55+
for (i in 0..versions.length - 1) {
56+
if (versions.item(i).textContent == version) {
57+
return true
58+
}
59+
}
60+
}
61+
return false
62+
}
63+
4064
fun getLatestReleasedVersion(): String {
65+
val doc: Document? = getMavenMetadata()
66+
return doc?.getElementsByTagName("latest")?.item(0)?.getTextContent() ?: ""
67+
}
68+
69+
fun getMavenMetadata(): Document? {
70+
val groupIdAsPath = groupId.replace(".", "/")
71+
val mavenMetadataUrl = "${GMAVEN_ROOT}/${groupIdAsPath}/${artifactId}/maven-metadata.xml"
72+
val factory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance()
73+
val builder: DocumentBuilder = factory.newDocumentBuilder()
4174
try {
42-
val groupIdAsPath = groupId.replace(".", "/")
43-
val mavenMetadataUrl = "${GMAVEN_ROOT}/${groupIdAsPath}/${artifactId}/maven-metadata.xml"
44-
val factory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance()
45-
val builder: DocumentBuilder = factory.newDocumentBuilder()
4675
val doc: Document = builder.parse(URL(mavenMetadataUrl).openStream())
4776
doc.documentElement.normalize()
48-
return doc.getElementsByTagName("latest").item(0).getTextContent()
77+
return doc
4978
} catch (e: FileNotFoundException) {
50-
return ""
79+
return null
5180
}
5281
}
5382
}

0 commit comments

Comments
 (0)