Skip to content

Commit 6d45825

Browse files
Revert 4923 daymon migrate publishingplugin (#4945)
* Implement Android Executors for Storage (#4830) * Revert "Refactor PublishingPlugin (#4923)" (#4937) This reverts commit 0efc6c7. * Revert "Refactor PublishingPlugin (#4923)" This reverts commit 0efc6c7. --------- Co-authored-by: Maneesh Tewani <[email protected]>
1 parent f47a0dd commit 6d45825

29 files changed

+538
-661
lines changed

.github/workflows/build-release-artifacts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
- name: Perform gradle build
2626
run: |
27-
./gradlew firebasePublish
27+
./gradlew firebasePublish -PpublishConfigFilePath=release.cfg -PpublishMode=RELEASE
2828
2929
- name: Generate release notes
3030
run: |

.github/workflows/check-head-dependencies.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ jobs:
1414

1515
- name: Perform gradle build
1616
run: |
17-
./gradlew checkHeadDependencies
17+
./gradlew checkHeadDependencies -PpublishConfigFilePath=release.cfg -PpublishMode=RELEASE

.github/workflows/create_releases.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
with:
4040
base: 'releases/${{ inputs.name }}'
4141
branch: 'releases/${{ inputs.name }}.release'
42-
add-paths: release.json,release_report.md
42+
add-paths: release.cfg,release_report.md
4343
title: '${{ inputs.name}} release'
4444
body: 'Auto-generated PR for release ${{ inputs.name}}'
4545
commit-message: 'Create release config for ${{ inputs.name }}'

.github/workflows/semver-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ jobs:
1414

1515
- name: Perform gradle build
1616
run: |
17-
./gradlew semverCheckForRelease
17+
./gradlew semverCheckForRelease -PpublishConfigFilePath=release.cfg -PpublishMode=RELEASE

.github/workflows/validate-dependencies.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ jobs:
1414

1515
- name: Perform gradle build
1616
run: |
17-
./gradlew validatePomForRelease
17+
./gradlew validatePomForRelease -PpublishConfigFilePath=release.cfg -PpublishMode=RELEASE

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import com.google.firebase.gradle.plugins.license.LicenseResolverPlugin
16+
import com.google.firebase.gradle.MultiProjectReleasePlugin
17+
1518
buildscript {
1619
// TODO: remove once all sdks have migrated to version catalog
1720
ext.kotlinVersion = libs.versions.kotlin.get()
@@ -55,10 +58,11 @@ ext {
5558
protobufJavaUtilVersion = libs.versions.protobufjavautil.get()
5659
}
5760

61+
apply plugin: com.google.firebase.gradle.plugins.publish.PublishingPlugin
5862
apply plugin: com.google.firebase.gradle.plugins.ci.ContinuousIntegrationPlugin
5963
apply plugin: com.google.firebase.gradle.plugins.ci.SmokeTestsPlugin
6064

61-
apply plugin: com.google.firebase.gradle.plugins.PublishingPlugin
65+
apply plugin: MultiProjectReleasePlugin
6266

6367
firebaseContinuousIntegration {
6468
ignorePaths = [

buildSrc/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
plugins {
1616
id("com.ncorti.ktfmt.gradle") version "0.11.0"
1717
id("com.github.sherter.google-java-format") version "0.9"
18-
kotlin("plugin.serialization") version "1.7.10"
1918
`kotlin-dsl`
2019
}
2120

@@ -68,7 +67,6 @@ dependencies {
6867

6968
implementation("org.eclipse.jgit:org.eclipse.jgit:6.3.0.202209071007-r")
7069

71-
implementation(libs.kotlinx.serialization.json)
7270
implementation("com.google.code.gson:gson:2.8.9")
7371
implementation("com.android.tools.build:gradle:7.2.2")
7472
implementation("com.android.tools.build:builder-test-api:7.2.2")
@@ -92,7 +90,7 @@ gradlePlugin {
9290
}
9391
register("publishingPlugin") {
9492
id = "PublishingPlugin"
95-
implementationClass = "com.google.firebase.gradle.plugins.PublishingPlugin"
93+
implementationClass = "com.google.firebase.gradle.plugins.publish.PublishingPlugin"
9694
}
9795
register("firebaseLibraryPlugin") {
9896
id = "firebase-library"
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Copyright 2021 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+
package com.google.firebase.gradle;
15+
16+
import com.google.common.collect.ImmutableMap;
17+
import com.google.firebase.gradle.bomgenerator.BomGeneratorTask;
18+
import com.google.firebase.gradle.plugins.FirebaseLibraryExtension;
19+
import com.google.firebase.gradle.plugins.publish.PublishingPlugin;
20+
import java.util.Set;
21+
import java.util.stream.Collectors;
22+
import org.gradle.api.GradleException;
23+
import org.gradle.api.Plugin;
24+
import org.gradle.api.Project;
25+
import org.gradle.api.Task;
26+
import org.gradle.api.tasks.Copy;
27+
import org.gradle.api.tasks.TaskProvider;
28+
import org.gradle.api.tasks.bundling.Zip;
29+
30+
/**
31+
* Orchestrates the release process by automating validations, documentation and prebuilts
32+
* generation.
33+
*
34+
* <ul>
35+
* <li>Pre-release validations:
36+
* <ul>
37+
* <li>Build maven artifacts.
38+
* </ul>
39+
* <li>Documentation:
40+
* <ul>
41+
* <li>Generates javadoc for all SDKs being released.
42+
* </ul>
43+
* <li>Artifact generation:
44+
* <ul>
45+
* <li>Releases artifacts into a maven repo in build/m2repository.
46+
* <li>Bundles all artifacts into a distributable .zip file.
47+
* </ul>
48+
* </ul>
49+
*/
50+
public class MultiProjectReleasePlugin implements Plugin<Project> {
51+
52+
// TODO() - Will be removed once migrated to Kotlin
53+
private static String findStringProperty(Project p, String property) {
54+
Object value = p.findProperty(property);
55+
return value != null ? value.toString() : null;
56+
}
57+
58+
@Override
59+
public void apply(Project project) {
60+
project.apply(ImmutableMap.of("plugin", PublishingPlugin.class));
61+
62+
project
63+
.getTasks()
64+
.create(
65+
"buildBomZip",
66+
Zip.class,
67+
task -> {
68+
task.dependsOn(project.getTasks().create("generateBom", BomGeneratorTask.class));
69+
task.from("bom");
70+
task.getArchiveFileName().set("bom.zip");
71+
task.getDestinationDirectory().set(project.getRootDir());
72+
});
73+
74+
TaskProvider<ReleaseGenerator> generatorTask =
75+
project
76+
.getTasks()
77+
.register(
78+
"makeReleaseConfigFiles",
79+
ReleaseGenerator.class,
80+
task -> {
81+
task.getCurrentRelease()
82+
.convention(findStringProperty(project, "currentRelease"));
83+
task.getPastRelease().convention(findStringProperty(project, "pastRelease"));
84+
task.getPrintReleaseConfig()
85+
.convention(findStringProperty(project, "printOutput"));
86+
task.getReleaseConfigFile()
87+
.convention(project.getLayout().getBuildDirectory().file("release.cfg"));
88+
task.getReleaseReportFile()
89+
.convention(
90+
project.getLayout().getBuildDirectory().file("release_report.md"));
91+
});
92+
93+
project
94+
.getTasks()
95+
.register(
96+
"generateReleaseConfig",
97+
Copy.class,
98+
task -> {
99+
task.from(generatorTask);
100+
task.into(project.getRootDir());
101+
});
102+
103+
project
104+
.getGradle()
105+
.projectsEvaluated(
106+
gradle -> {
107+
Set<FirebaseLibraryExtension> librariesToPublish =
108+
(Set<FirebaseLibraryExtension>)
109+
project.getExtensions().getExtraProperties().get("projectsToPublish");
110+
111+
Set<Project> projectsToPublish =
112+
librariesToPublish.stream().map(lib -> lib.project).collect(Collectors.toSet());
113+
114+
Task validateProjectsToPublish =
115+
project.task(
116+
"validateProjectsToPublish",
117+
task ->
118+
task.doLast(
119+
t -> {
120+
if (projectsToPublish.isEmpty()) {
121+
throw new GradleException(
122+
"Required projectsToPublish parameter missing.");
123+
}
124+
}));
125+
project.getTasks().findByName("firebasePublish").dependsOn(validateProjectsToPublish);
126+
});
127+
}
128+
}

buildSrc/src/main/java/com/google/firebase/gradle/plugins/ReleaseGenerator.kt renamed to buildSrc/src/main/java/com/google/firebase/gradle/ReleaseGenerator.kt

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
package com.google.firebase.gradle.plugins
14+
package com.google.firebase.gradle
1515

1616
import com.google.common.collect.ImmutableList
17+
import com.google.firebase.gradle.plugins.FirebaseLibraryExtension
1718
import java.io.File
1819
import org.eclipse.jgit.api.Git
1920
import org.eclipse.jgit.api.ListBranchCommand
@@ -26,11 +27,12 @@ import org.gradle.api.Project
2627
import org.gradle.api.file.RegularFileProperty
2728
import org.gradle.api.provider.Property
2829
import org.gradle.api.tasks.Input
29-
import org.gradle.api.tasks.Optional
3030
import org.gradle.api.tasks.OutputFile
3131
import org.gradle.api.tasks.TaskAction
3232
import org.gradle.kotlin.dsl.findByType
3333

34+
data class FirebaseLibrary(val moduleNames: List<String>, val directories: List<String>)
35+
3436
data class CommitDiff(
3537
val commitId: String,
3638
val author: String,
@@ -55,7 +57,7 @@ abstract class ReleaseGenerator : DefaultTask() {
5557

5658
@get:Input abstract val pastRelease: Property<String>
5759

58-
@get:Optional @get:Input abstract val printReleaseConfig: Property<String>
60+
@get:Input abstract val printReleaseConfig: Property<String>
5961

6062
@get:OutputFile abstract val releaseConfigFile: RegularFileProperty
6163

@@ -77,12 +79,12 @@ abstract class ReleaseGenerator : DefaultTask() {
7779
libsToRelease.map { it.path }.toSet()
7880

7981
val changes = getChangesForLibraries(repo, branchRef, headRef, libsToRelease)
80-
81-
val releaseConfig = ReleaseConfig(currentRelease.get(), libsToRelease.map { it.path })
82-
releaseConfig.toFile(releaseConfigFile.get().asFile)
83-
82+
writeReleaseConfig(
83+
releaseConfigFile.get().asFile,
84+
ReleaseConfig(currentRelease.get(), libsToRelease.map { it.path }.toSet())
85+
)
8486
val releaseReport = generateReleaseReport(changes, changedLibsWithNoChangelog)
85-
if (printReleaseConfig.orNull.toBoolean()) {
87+
if (printReleaseConfig.get().toBoolean()) {
8688
project.logger.info(releaseReport)
8789
}
8890
writeReleaseReport(releaseReportFile.get().asFile, releaseReport)
@@ -200,5 +202,30 @@ abstract class ReleaseGenerator : DefaultTask() {
200202

201203
private fun writeReleaseReport(file: File, report: String) = file.writeText(report)
202204

205+
private fun writeReleaseConfig(file: File, config: ReleaseConfig) =
206+
file.writeText(config.toFile())
207+
203208
private fun getRelativeDir(project: Project) = project.path.substring(1).replace(':', '/')
204209
}
210+
211+
data class ReleaseConfig(val releaseName: String, val libs: Set<String>) {
212+
companion object {
213+
fun fromFile(file: File): ReleaseConfig {
214+
val contents = file.readLines()
215+
val libs = contents.filter { it.startsWith(":") }.toSet()
216+
val releaseName = contents.first { it.startsWith("name") }.substringAfter("=").trim()
217+
return ReleaseConfig(releaseName, libs)
218+
}
219+
}
220+
221+
fun toFile() =
222+
"""
223+
|[release]
224+
|name = $releaseName
225+
|mode = RELEASE
226+
227+
|[modules]
228+
|${libs.sorted().joinToString("\n")}
229+
"""
230+
.trimMargin()
231+
}

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,43 @@ import org.gradle.api.provider.ListProperty
2020
import org.gradle.api.tasks.Input
2121
import org.gradle.api.tasks.TaskAction
2222

23-
/**
24-
* Validates that all project level dependencies are in the release.
25-
*
26-
* Any releasing library that has a project level dependency on another library invokes the release
27-
* of said dependent libary. This is checked via the [artifactId]
28-
* [FirebaseLibraryExtension.artifactId], so that the check is version agnostic.
29-
*
30-
* @throws GradleException if any project level dependencies are found that are not included in the
31-
* release
32-
*/
3323
abstract class CheckHeadDependencies : DefaultTask() {
3424
@get:Input abstract val projectsToPublish: ListProperty<FirebaseLibraryExtension>
3525

26+
@get:Input abstract val allFirebaseProjects: ListProperty<String>
27+
3628
@TaskAction
3729
fun run() {
38-
val projectsReleasing = computeProjectsReleasing()
39-
30+
val projectsReleasing: Set<String> = projectsToPublish.get().map { it.artifactId.get() }.toSet()
4031
val errors =
4132
projectsToPublish
4233
.get()
43-
.associate { it.artifactId.get() to it.projectLevelDepsAsArtifactIds() - projectsReleasing }
34+
.associate {
35+
it.artifactId.get() to
36+
it
37+
.projectDependenciesByName()
38+
.intersect(allFirebaseProjects.get())
39+
.subtract(projectsReleasing)
40+
.subtract(DEPENDENCIES_TO_IGNORE)
41+
}
4442
.filterValues { it.isNotEmpty() }
4543
.map { "${it.key} requires: ${it.value.joinToString(", ") }" }
4644

4745
if (errors.isNotEmpty()) {
4846
throw GradleException(
49-
"Project-level dependency errors found. Please update the release config.\n" +
50-
"${errors.joinToString("\n")}"
47+
"Project-level dependency errors found. Please update the release config.\n${
48+
errors.joinToString(
49+
"\n"
50+
)
51+
}"
5152
)
5253
}
5354
}
5455

55-
private fun FirebaseLibraryExtension.projectLevelDepsAsArtifactIds() =
56+
private fun FirebaseLibraryExtension.projectDependenciesByName() =
5657
resolveProjectLevelDependencies().map { it.artifactId.get() }
5758

58-
private fun computeProjectsReleasing() =
59-
projectsToPublish.get().map { it.artifactId.get() } + DEPENDENCIES_TO_IGNORE
60-
6159
companion object {
62-
val DEPENDENCIES_TO_IGNORE = listOf("protolite-well-known-types")
60+
val DEPENDENCIES_TO_IGNORE: List<String> = listOf("protolite-well-known-types")
6361
}
6462
}

0 commit comments

Comments
 (0)