Skip to content

Commit bcde127

Browse files
authored
Check Project level dependencies for release (#4739)
* update code * add head dependencies * fix * add head dependencies * update * update head dependency * update
1 parent 46e5549 commit bcde127

File tree

4 files changed

+106
-7
lines changed

4 files changed

+106
-7
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Check Head Dependencies
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- 'releases/**'
8+
9+
jobs:
10+
build-artifacts:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Perform gradle build
16+
run: |
17+
./gradlew checkHeadDependencies -PpublishConfigFilePath=release.cfg -PpublishMode=RELEASE -PincludeFireEscapeArtifacts=true
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.gradle.plugins
16+
17+
import org.gradle.api.DefaultTask
18+
import org.gradle.api.GradleException
19+
import org.gradle.api.artifacts.ProjectDependency
20+
import org.gradle.api.provider.ListProperty
21+
import org.gradle.api.tasks.Input
22+
import org.gradle.api.tasks.TaskAction
23+
24+
abstract class CheckHeadDependencies : DefaultTask() {
25+
@get:Input abstract val projectsToPublish: ListProperty<FirebaseLibraryExtension>
26+
27+
@get:Input abstract val allFirebaseProjects: ListProperty<String>
28+
29+
@TaskAction
30+
fun run() {
31+
val projectsReleasing: Set<String> = projectsToPublish.get().map { it.artifactId.get() }.toSet()
32+
val projectsToRelease =
33+
projectsToPublish
34+
.get()
35+
.flatMap {
36+
it.project.configurations
37+
.getByName(it.runtimeClasspath)
38+
.allDependencies
39+
.filter { it is ProjectDependency }
40+
.map { it.name }
41+
.toSet()
42+
}
43+
.intersect(allFirebaseProjects.get())
44+
.subtract(projectsReleasing)
45+
46+
if (projectsToRelease.isNotEmpty()) {
47+
throw GradleException(
48+
"Following Sdks have to release as well. Please update the release config.\n${projectsToRelease.joinToString("\n")}"
49+
)
50+
}
51+
}
52+
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.firebase.gradle.plugins
1616

17+
import java.io.FileNotFoundException
1718
import java.net.URL
1819
import javax.xml.parsers.DocumentBuilder
1920
import javax.xml.parsers.DocumentBuilderFactory
@@ -29,12 +30,16 @@ class GmavenHelper(val groupId: String, val artifactId: String) {
2930
}
3031

3132
fun getLatestReleasedVersion(): String {
32-
val groupIdAsPath = groupId.replace(".", "/")
33-
val mavenMetadataUrl = "${GMAVEN_ROOT}/${groupIdAsPath}/${artifactId}/maven-metadata.xml"
34-
val factory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance()
35-
val builder: DocumentBuilder = factory.newDocumentBuilder()
36-
val doc: Document = builder.parse(URL(mavenMetadataUrl).openStream())
37-
doc.documentElement.normalize()
38-
return doc.getElementsByTagName("latest").item(0).getTextContent()
33+
try {
34+
val groupIdAsPath = groupId.replace(".", "/")
35+
val mavenMetadataUrl = "${GMAVEN_ROOT}/${groupIdAsPath}/${artifactId}/maven-metadata.xml"
36+
val factory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance()
37+
val builder: DocumentBuilder = factory.newDocumentBuilder()
38+
val doc: Document = builder.parse(URL(mavenMetadataUrl).openStream())
39+
doc.documentElement.normalize()
40+
return doc.getElementsByTagName("latest").item(0).getTextContent()
41+
} catch (e: FileNotFoundException) {
42+
return ""
43+
}
3944
}
4045
}

buildSrc/src/main/java/com/google/firebase/gradle/plugins/publish/PublishingPlugin.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.firebase.gradle.plugins.publish;
1616

17+
import com.google.firebase.gradle.plugins.CheckHeadDependencies;
1718
import com.google.firebase.gradle.plugins.FirebaseLibraryExtension;
1819
import java.io.File;
1920
import java.io.IOException;
@@ -117,6 +118,20 @@ public void apply(Project project) {
117118
List.of(projectNamesToPublish.split(projectsToPublishSeparator, -1));
118119
}
119120

121+
Set<String> allFirebaseProjects =
122+
project.getSubprojects().stream()
123+
.filter(
124+
sub ->
125+
sub.getExtensions().findByType(FirebaseLibraryExtension.class)
126+
!= null)
127+
.map(
128+
sub ->
129+
sub.getExtensions()
130+
.findByType(FirebaseLibraryExtension.class)
131+
.artifactId
132+
.get())
133+
.collect(Collectors.toSet());
134+
120135
Set<FirebaseLibraryExtension> projectsToPublish =
121136
projectsNames.stream()
122137
.filter(name -> !name.isEmpty())
@@ -181,6 +196,16 @@ public void apply(Project project) {
181196
t.dependsOn(getPublishTask(toPublish, "MavenLocal"));
182197
}
183198
});
199+
project
200+
.getTasks()
201+
.create(
202+
"checkHeadDependencies",
203+
CheckHeadDependencies.class,
204+
t -> {
205+
t.getProjectsToPublish().set(projectsToPublish);
206+
t.getAllFirebaseProjects().set(allFirebaseProjects);
207+
});
208+
184209
Task publishProjectsToBuildDir =
185210
project
186211
.getTasks()

0 commit comments

Comments
 (0)