-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adrian Tosca
committed
Feb 9, 2024
1 parent
dea1147
commit 93243c5
Showing
5 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
} | ||
|
||
gradlePlugin { | ||
plugins.create("updateReadmeVersion") { | ||
isAutomatedPublishing = false | ||
id = "io.github.aleris.plugins.update-readme-version" | ||
displayName = "Update Readme Plugin" | ||
description = "Keep the version in the README.md file up to date with the project version" | ||
tags = listOf("readme", "version") | ||
implementationClass = "io.github.aleris.plugins.readmeversion.ReadmeVersionPlugin" | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
buildSrc/src/main/kotlin/io/github/aleris/plugins/readmeversion/ReadmeVersionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.github.aleris.plugins.readmeversion | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
class ReadmeVersionPlugin : Plugin<Project> { | ||
override fun apply(project: Project) { | ||
project.tasks.register("updateReadmeVersion", ReadmeVersionTask::class.java) { | ||
group = "build" | ||
description = "Keep the version in the README.md file up to date with the project version" | ||
} | ||
|
||
project.tasks.named("build").configure { | ||
dependsOn("updateReadmeVersion") | ||
} | ||
} | ||
} | ||
|
||
open class ReadmeVersionTask : DefaultTask() { | ||
@TaskAction | ||
fun updateReadmeVersion() { | ||
val readmeFile = project.file("README.md") | ||
if (!readmeFile.exists()) { | ||
project.logger.warn("No README.md file found") | ||
return | ||
} | ||
val readmeContent = readmeFile.readText() | ||
val newReadmeContent = readmeContent | ||
.replace(Regex("\"\\d+\\.\\d+\\.\\d+\""), "\"${project.version}\"") | ||
.replace(Regex("'\\d+\\.\\d+\\.\\d+'"), "'${project.version}'") | ||
if (readmeContent != newReadmeContent) { | ||
project.logger.lifecycle("Updating README.md with new version ${project.version}") | ||
readmeFile.writeText(newReadmeContent) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters