Skip to content

Connect PostReleasePlugin with PublishingPlugin #5165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class FirebaseLibraryPlugin : BaseFirebaseLibraryPlugin() {

project.apply<DackkaPlugin>()
project.apply<GitSubmodulePlugin>()
project.apply<PostReleasePlugin>()
project.tasks.getByName("preBuild").dependsOn("updateGitSubmodules")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,38 @@ fun Provider<File>.childFile(path: String) = map { File("${it.path}/$path") }
*/
fun File.childFile(childPath: String) = File("$path/$childPath")

/**
* Rewrites the lines of a file.
*
* The lines of the file are first read and then transformed by the provided `block` function. The
* transformed lines are then joined together with a newline character and written back to the file.
*
* If the `terminateWithNewline` parameter is set to `false`, the file will not be terminated with a
* newline character.
*
* @param terminateWithNewline Whether to terminate the file with a newline character. Defaults to
* `true`.
* @param block A function that takes a string as input and returns a new string. This function is
* used to transform the lines of the file before they are rewritten.
*
* ```
* val file = File("my-file.txt")
*
* // Rewrite the lines of the file, replacing all spaces with tabs.
* file.rewriteLines { it.replace(" ", "\t") }
*
* // Rewrite the lines of the file, capitalizing the first letter of each word.
* file.rewriteLines { it.capitalizeWords() }
* ```
*
* @see [readLines]
* @see [writeText]
*/
fun File.rewriteLines(terminateWithNewline: Boolean = true, block: (String) -> String) {
val newLines = readLines().map(block)
writeText(newLines.joinToString("\n").let { if (terminateWithNewline) it + "\n" else it })
}

/**
* Provides a temporary file for use during the task.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.gradle.api.Project
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.bundling.Zip
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register

Expand Down Expand Up @@ -60,6 +61,9 @@ import org.gradle.kotlin.dsl.register
* - [PUBLISH_RELEASING_LIBS_TO_LOCAL_TASK][registerPublishReleasingLibrariesToMavenLocalTask]
* - [SEMVER_CHECK_TASK][registerSemverCheckForReleaseTask]
* - [PUBLISH_ALL_TO_BUILD_TASK][registerPublishAllToBuildDir]
*
* Additionally, this plugin registers the [PostReleasePlugin] via [registerPostReleasePlugin] for
* each releasing library.
*/
abstract class PublishingPlugin : Plugin<Project> {
override fun apply(project: Project) {
Expand Down Expand Up @@ -91,6 +95,7 @@ abstract class PublishingPlugin : Plugin<Project> {
registerPublishReleasingLibrariesToMavenLocalTask(project, releasingProjects)
registerSemverCheckForReleaseTask(project, releasingProjects)
registerPublishAllToBuildDir(project, allFirebaseLibraries)
registerPostReleasePlugin(releasingProjects)

val buildMavenZip =
project.tasks.register<Zip>(BUILD_MAVEN_ZIP_TASK) {
Expand Down Expand Up @@ -444,6 +449,13 @@ abstract class PublishingPlugin : Plugin<Project> {
}
}

/** Registers the [PostReleasePlugin] to each releaing project. */
private fun registerPostReleasePlugin(releasingProjects: List<Project>) {
for (releasingProject in releasingProjects) {
releasingProject.apply<PostReleasePlugin>()
}
}

companion object {
const val RELEASE_CONFIG_FILE = "release.json"
const val RELEASE_REPORT_MD_FILE = "release_report.md"
Expand Down Expand Up @@ -476,7 +488,6 @@ abstract class PublishingPlugin : Plugin<Project> {
*
* @property releasingLibraries A list of libraries that should be released
* @property name The name of the release (such as `m123`)
*
* @see computeReleaseMetadata
*/
data class ReleaseMetadata(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ abstract class VersionBumpTask : DefaultTask() {

@TaskAction
fun build() {
with(versionFile.get()) {
readLines()
.map { it.takeUnless { it.startsWith("version=") } ?: "version=${newVersion.get()}" }
.also { writeText(it.joinToString("\n") + '\n') }
versionFile.get().rewriteLines {
if (it.startsWith("version=")) "version=${newVersion.get()}" else it
}
}

Expand Down