Skip to content

Commit

Permalink
add plugin id usage in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Tosca committed Feb 9, 2024
1 parent dea1147 commit 93243c5
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ It runs as part of the build process, so the generated files are always up to da

## Usage

Add the plugin to your build script:

Kotlin DSL:

```kts
plugins {
id("io.github.aleris.plugins.tscfg") version "0.4.0"
}
```

Groovy DSL:

```groovy
plugins {
id 'io.github.aleris.plugins.tscfg' version '0.4.0'
}
```

Basic configuration:

Kotlin DSL:
Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ plugins {

group = "io.github.aleris.plugins"

apply(plugin = "io.github.aleris.plugins.update-readme-version")

plugins.withType<JavaPlugin> {
configure<JavaPluginExtension> {
withSourcesJar()
Expand Down
18 changes: 18 additions & 0 deletions buildSrc/build.gradle.kts
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"
}
}
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)
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=io.github.aleris.tscfg-plugin-gradle
version=0.3.0
version=0.4.0

github.url=https://github.com/aleris/tscfg-plugin-gradle

Expand Down

0 comments on commit 93243c5

Please sign in to comment.