Skip to content

Commit

Permalink
fix: Fix Flank Scripts version verification tasks (#1372)
Browse files Browse the repository at this point in the history
Fixes #1368

## Test Plan
> How do we know the code works?

**Version check should be performed also vs local file changes**
When some `flanks-scripts` are changed `detekt`/`check` or `checkIfVersionUpdated` do not fail if version is updated. No matter if in local files or committed to the branch

**Tasks should run on demand**
Task run only when using `gradlew :flank-scripts:checkIfVersionUpdated` or any other task which depends on `detekt`

## Checklist

- [x] Added comparing version check vs local files
- [x] Run task only on demand
- [x] Make `detekt` depend on `checkIfVersionUpdated`
  • Loading branch information
piotradamczyk5 authored Dec 3, 2020
1 parent 674ca73 commit 550e7db
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release_flank_scripts.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: RELEASE
name: Release Flank Scripts

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion flank-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This repository contains helper scripts for developing flank. For now, it contai

To build flank-scripts:
1. Run script `buildFlankScripts.sh` in `flank-scripts/bash/` directory
2. Run command `./gradlew clean flank-scripts:assemble flank-scripts:shadowJar` and manual copy file from `/flank-scripts/build/libs/flankScripts.jar` to `flank-scripts/bash/`
2. Run command `./gradlew clean flank-scripts:assemble flank-scripts:shadowJar` and manual copy file from `/flank-scripts/build/libs/flank-scripts.jar` to `flank-scripts/bash/`
3. You could always run/build it from Intellij IDEA

### Usage
Expand Down
2 changes: 1 addition & 1 deletion flank-scripts/bash/flankScripts.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SET DIR=%~dp0
SET scriptsJar=%DIR%flankScripts.jar
SET scriptsJar=%DIR%flank-scripts.jar

if not exist %scriptsJar% (
CALL %DIR%\buildFlankScripts.bat
Expand Down
65 changes: 32 additions & 33 deletions flank-scripts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.jfrog.bintray.gradle.BintrayExtension
import java.util.*
import java.nio.file.Paths
import java.io.ByteArrayOutputStream

plugins {
application
Expand All @@ -27,7 +28,7 @@ shadowJar.apply {
}
}
// <breaking change>.<feature added>.<fix/minor change>
version = "1.1.3"
version = "1.1.4"
group = "com.github.flank"

application {
Expand Down Expand Up @@ -156,49 +157,47 @@ tasks.register("download") {
ant.invokeMethod("get", mapOf("src" to sourceUrl, "dest" to destinationFile))
}

tasks.register("checkIfVersionUpdated") {
val checkIfVersionUpdated by tasks.registering(Exec::class) {
group = "verification"
val isVersionChanged = withTempFile {
outputStream().use {
commandLine("git", "fetch", "--no-tags")

project.exec {
commandLine("git", "fetch", "--no-tags", "-v")
}
doLast {
val changedFiles = execAndGetStdout("git", "diff", "origin/master", "HEAD", "--name-only").split("\n") +
execAndGetStdout("git", "diff", "origin/master", "--name-only").split("\n")
val isVersionChanged = changedFiles.any { it.startsWith("flank-scripts") }.not()
|| (changedFiles.contains("flank-scripts/build.gradle.kts") && isVersionChangedInBuildGradle())

project.exec {
commandLine(listOf("git", "diff", "origin/master", "HEAD", "--name-only"))
standardOutput = it
}
}
if (isVersionChanged.not()) {
throw GradleException(
"""
Flank scripts version is not updated, but files changed.
Please update version according to schema: <breaking change>.<feature added>.<fix/minor change>
""".trimIndent()

val changedFiles = readLines()
changedFiles.any { it.startsWith("flank-scripts") }.not()
|| (changedFiles.contains("flank-scripts/build.gradle.kts") && isVersionChangedInBuildGradle())
}
if(isVersionChanged.not()) {
throw GradleException(
"Flank scripts version is not updated, but files changed.\n" +
"Please update version according to schema: <breaking change>.<feature added>.<fix/minor change>"
)
)
}
}
}

fun isVersionChangedInBuildGradle(): Boolean = withTempFile {
outputStream().use {
project.exec {
commandLine(listOf("git", "diff", "origin/master", "HEAD", "--", "build.gradle.kts"))
standardOutput = it
}
}
fun isVersionChangedInBuildGradle(): Boolean {

readLines()
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 = ") }
.size >= 2
}

fun <T> withTempFile(block: File.() -> T): T {
val tempFile = createTempFile("${System.currentTimeMillis()}")
return block(tempFile).also { tempFile.delete() }
fun execAndGetStdout(vararg args: String): String {
val stdout = ByteArrayOutputStream()
exec {
commandLine(*args)
standardOutput = stdout
workingDir = projectDir
}
return stdout.toString().trimEnd()
}

// TODO temporary disabled tasks["check"].dependsOn(tasks["checkIfVersionUpdated"])
tasks["detekt"].dependsOn(tasks["checkIfVersionUpdated"])

0 comments on commit 550e7db

Please sign in to comment.