-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Gradle Plugin to check if helpers modules version get upd…
…ated (#2108) Fixes #2063 ## Test Plan > How do we know the code works? Version check for `:flank_wrapper` and `:flank_scripts` works same as previously
- Loading branch information
1 parent
2784a32
commit e2a2ef3
Showing
10 changed files
with
112 additions
and
78 deletions.
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 was deleted.
Oops, something went wrong.
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,15 @@ | ||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
plugins { | ||
`kotlin-dsl` | ||
`java-gradle-plugin` | ||
} | ||
|
||
gradlePlugin { | ||
plugins.register("check-version-updated") { | ||
id = "check-version-updated" | ||
implementationClass = "com.github.flank.gradle.CheckVersionUpdated" | ||
} | ||
} |
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 @@ | ||
rootProject.name = "check-version-updated" |
42 changes: 42 additions & 0 deletions
42
check_version_updated/src/main/kotlin/com/github/flank/gradle/CheckVersionUpdated.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,42 @@ | ||
package com.github.flank.gradle | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.get | ||
import java.io.ByteArrayOutputStream | ||
|
||
class CheckVersionUpdated : Plugin<Project> { | ||
|
||
private val taskName = "checkIfVersionUpdated" | ||
|
||
override fun apply(project: Project) { | ||
|
||
project.tasks.register(taskName, CheckVersionUpdatedTask::class.java) | ||
|
||
project.afterEvaluate { | ||
project.tasks["lintKotlin"].dependsOn(taskName) | ||
} | ||
} | ||
|
||
private fun Project.execAndGetStdout(vararg args: String): String { | ||
val stdout = ByteArrayOutputStream() | ||
exec { | ||
commandLine(*args) | ||
standardOutput = stdout | ||
workingDir = projectDir | ||
} | ||
return stdout.toString().trimEnd() | ||
} | ||
|
||
private fun Project.isVersionChangedInBuildGradle(): Boolean { | ||
|
||
val localResultsStream = execAndGetStdout("git", "diff", "origin/master", "HEAD", "--", "build.gradle.kts") | ||
.split("\n") | ||
val commitedResultsStream = execAndGetStdout("git", "diff", "origin/master", "--", "build.gradle.kts") | ||
.split("\n") | ||
return (commitedResultsStream + localResultsStream) | ||
.filter { it.startsWith("-version = ") || it.startsWith("+version = ") } | ||
.isNotEmpty() | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
check_version_updated/src/main/kotlin/com/github/flank/gradle/CheckVersionUpdatedTask.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,47 @@ | ||
package com.github.flank.gradle | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.Project | ||
import org.gradle.api.tasks.TaskAction | ||
import java.io.ByteArrayOutputStream | ||
|
||
open class CheckVersionUpdatedTask : DefaultTask() { | ||
|
||
@TaskAction | ||
fun action() { | ||
project.execAndGetStdout("git", "fetch", "--no-tags") | ||
val changedFiles = project.execAndGetStdout("git", "diff", "origin/master", "HEAD", "--name-only").split("\n") + | ||
project.execAndGetStdout("git", "diff", "origin/master", "--name-only").split("\n") | ||
val isVersionChanged = changedFiles.any { it.startsWith(project.name) }.not() || | ||
(changedFiles.contains("${project.name}/build.gradle.kts") && project.isVersionChangedInBuildGradle()) | ||
|
||
if (isVersionChanged.not()) { | ||
throw GradleException( | ||
""" | ||
${project.path} version is not updated, but files changed. | ||
Please update version according to schema: <breaking change>.<feature added>.<fix/minor change> | ||
""".trimIndent() | ||
) | ||
} | ||
} | ||
|
||
private fun Project.execAndGetStdout(vararg args: String): String { | ||
val stdout = ByteArrayOutputStream() | ||
exec { | ||
commandLine(*args) | ||
standardOutput = stdout | ||
workingDir = projectDir | ||
} | ||
return stdout.toString().trimEnd() | ||
} | ||
|
||
private fun Project.isVersionChangedInBuildGradle(): Boolean { | ||
val localResultsStream = execAndGetStdout("git", "diff", "origin/master", "HEAD", "--", "build.gradle.kts") | ||
.split("\n") | ||
val commitedResultsStream = execAndGetStdout("git", "diff", "origin/master", "--", "build.gradle.kts") | ||
.split("\n") | ||
return (commitedResultsStream + localResultsStream) | ||
.any { it.startsWith("-version = ") || it.startsWith("+version = ") } | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
1.2.0 | ||
1.2.1 |
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