-
Notifications
You must be signed in to change notification settings - Fork 112
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
1 parent
7c36d01
commit 1474048
Showing
22 changed files
with
363 additions
and
26 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 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,24 @@ | ||
name: Release Flank Wrapper | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'flank_wrapper/**' | ||
branches: | ||
- 'master' | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: gradle/wrapper-validation-action@v1 | ||
|
||
- name: Gradle Upload to Github packages and Github release | ||
uses: eskatos/gradle-command-action@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
arguments: "flank_wrapper:releaseFlankWrapper -PGITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" |
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,25 @@ | ||
import org.gradle.api.Project | ||
import java.io.ByteArrayOutputStream | ||
|
||
fun Project.execAndGetStdout(vararg args: String): String { | ||
val stdout = ByteArrayOutputStream() | ||
exec { | ||
commandLine(*args) | ||
standardOutput = stdout | ||
workingDir = projectDir | ||
} | ||
return stdout.toString().trimEnd() | ||
} | ||
|
||
// TODO replace with plugin in #2063 | ||
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() | ||
} | ||
|
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
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,5 @@ | ||
# Ignore Gradle project-specific cache directory | ||
.gradle | ||
|
||
# Ignore Gradle build output directory | ||
build |
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,132 @@ | ||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar | ||
|
||
plugins { | ||
application | ||
kotlin(Plugins.Kotlin.PLUGIN_JVM) | ||
id(Plugins.PLUGIN_SHADOW_JAR) version Versions.SHADOW | ||
id(Plugins.MAVEN_PUBLISH) | ||
} | ||
|
||
val artifactID = "flank_wrapper" | ||
val runnerClass = "com.github.flank.wrapper.MainKt" | ||
val shadowJar: ShadowJar by tasks | ||
|
||
shadowJar.apply { | ||
archiveClassifier.set("") | ||
archiveFileName.set("$artifactID.jar") | ||
mergeServiceFiles() | ||
|
||
@Suppress("UnstableApiUsage") | ||
manifest { | ||
attributes(mapOf("Main-Class" to runnerClass)) | ||
} | ||
} | ||
// <breaking change>.<feature added>.<fix/minor change> | ||
version = "1.0.0" | ||
group = "com.github.flank" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
publishing { | ||
repositories { | ||
maven { | ||
name = "GitHubPackages" | ||
url = uri("https://maven.pkg.github.com/Flank/flank") | ||
credentials { | ||
username = System.getenv("GITHUB_ACTOR") ?: properties["GITHUB_ACTOR"].toString() | ||
password = System.getenv("GITHUB_TOKEN") ?: properties["GITHUB_TOKEN"].toString() | ||
} | ||
} | ||
} | ||
publications { | ||
create<MavenPublication>("mavenJava") { | ||
groupId = group.toString() | ||
artifactId = artifactID | ||
version = version | ||
|
||
artifact(shadowJar) | ||
|
||
pom { | ||
name.set("Flank-wrapper") | ||
description.set("Wrapper to run latest version of Flank") | ||
url.set("https://github.com/Flank/flank") | ||
|
||
licenses { | ||
license { | ||
name.set("The Apache License, Version 2.0") | ||
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") | ||
} | ||
} | ||
} | ||
|
||
pom.withXml { | ||
// Remove deps since we're publishing a fat jar | ||
val pom = asNode() | ||
val depNode: groovy.util.NodeList = pom.get("dependencies") as groovy.util.NodeList | ||
for (child in depNode) { | ||
pom.remove(child as groovy.util.Node) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(project(":common")) | ||
implementation(Dependencies.Fuel.CORE) | ||
testImplementation(Dependencies.JUNIT) | ||
testImplementation(Dependencies.TRUTH) | ||
} | ||
|
||
val releaseFlankWrapper by tasks.registering(Exec::class) { | ||
dependsOn(":flank_wrapper:publish") | ||
commandLine( | ||
"gh", "release", "create", | ||
"flank-wrapper-$version", | ||
"$buildDir/libs/$artifactID.jar", | ||
"flankw", | ||
"flankw.bat", | ||
"-t", "Flank Wrapper $version", | ||
"-p" | ||
) | ||
} | ||
|
||
|
||
application { | ||
mainClass.set(runnerClass) | ||
} | ||
|
||
// TODO replace with plugin in #2063 | ||
val checkIfVersionUpdated by tasks.registering(Exec::class) { | ||
group = "verification" | ||
commandLine("git", "fetch", "--no-tags") | ||
|
||
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_wrapper") }.not() || | ||
(changedFiles.contains("flank_wrapper/build.gradle.kts") && isVersionChangedInBuildGradle()) | ||
|
||
if (isVersionChanged.not()) { | ||
throw GradleException( | ||
""" | ||
Flank wrapper version is not updated, but files changed. | ||
Please update version according to schema: <breaking change>.<feature added>.<fix/minor change> | ||
""".trimIndent() | ||
|
||
) | ||
} | ||
} | ||
} | ||
|
||
val prepareJar by tasks.registering(Copy::class) { | ||
dependsOn("shadowJar") | ||
from("$buildDir/libs") | ||
include("flank_wrapper.jar") | ||
into("$projectDir") | ||
} | ||
|
||
|
||
tasks["lintKotlin"].dependsOn(checkIfVersionUpdated) |
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,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
DIR=`dirname "$BASH_SOURCE"` | ||
|
||
/usr/bin/env java -jar "$DIR/flank_wrapper.jar" "$@" |
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 @@ | ||
java -jar "flank_wrapper.jar" %* |
7 changes: 7 additions & 0 deletions
7
flank_wrapper/src/main/kotlin/com/github/flank/wrapper/Main.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,7 @@ | ||
package com.github.flank.wrapper | ||
|
||
import com.github.flank.wrapper.internal.runFlankOnLatestVersion | ||
|
||
fun main(vararg args: String) { | ||
runFlankOnLatestVersion(args) | ||
} |
17 changes: 17 additions & 0 deletions
17
flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/CheckSumCalculator.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,17 @@ | ||
package com.github.flank.wrapper.internal | ||
|
||
import java.io.File | ||
import java.security.MessageDigest | ||
|
||
internal fun File.sha256(): String = readBytes().sha256() | ||
|
||
private fun ByteArray.sha256(): String { | ||
return hashString(this, "SHA-256") | ||
} | ||
|
||
private fun hashString(input: ByteArray, algorithm: String): String { | ||
return MessageDigest | ||
.getInstance(algorithm) | ||
.digest(input) | ||
.fold("") { str, it -> str + "%02x".format(it) } | ||
} |
21 changes: 21 additions & 0 deletions
21
flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/ChecksumVerification.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,21 @@ | ||
package com.github.flank.wrapper.internal | ||
|
||
import flank.common.downloadFile | ||
import java.io.File | ||
import kotlin.io.path.createTempFile | ||
import kotlin.io.path.readText | ||
|
||
internal fun compareLatestVersionCheckSumWithCurrent(): Boolean = getFlankLocalChecksum() == getFlankRemoteChecksum() | ||
|
||
private fun getFlankLocalChecksum(): String { | ||
val flankFile = File(flankRunnerPath) | ||
return flankFile.takeIf(File::exists)?.let(File::sha256).orEmpty() | ||
} | ||
|
||
private fun getFlankRemoteChecksum(): String = with(createTempFile("flank", "sha256")) { | ||
downloadFile( | ||
sourceUrl = "https://github.com/Flank/flank/releases/latest/download/flank.sha256", | ||
destinationPath = toAbsolutePath() | ||
) | ||
readText().split("\\s+".toRegex()).first() | ||
} |
12 changes: 12 additions & 0 deletions
12
flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/DownloadLatestVersion.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,12 @@ | ||
package com.github.flank.wrapper.internal | ||
|
||
import flank.common.downloadFile | ||
|
||
internal fun downloadLatestFlankVersion() { | ||
downloadFile( | ||
sourceUrl = FLANK_JAR_REMOTE_PATH, | ||
destination = flankRunnerPath | ||
) | ||
} | ||
|
||
private const val FLANK_JAR_REMOTE_PATH = "https://github.com/Flank/flank/releases/latest/download/flank.jar" |
18 changes: 18 additions & 0 deletions
18
flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/FlankExecutor.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,18 @@ | ||
package com.github.flank.wrapper.internal | ||
|
||
import kotlin.system.exitProcess | ||
|
||
internal fun executeFlank(args: Array<out String>) { | ||
ProcessBuilder() | ||
.command(buildRunCommand(args)) | ||
.inheritIO() | ||
.start() | ||
.waitFor() | ||
.let { flankExitCode -> exitProcess(flankExitCode) } | ||
} | ||
|
||
internal fun buildRunCommand(args: Array<out String>): List<String> = listOf( | ||
"java", | ||
"-jar", | ||
flankRunnerPath | ||
) + args.asList() |
8 changes: 8 additions & 0 deletions
8
flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/FlankRunnerPath.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,8 @@ | ||
package com.github.flank.wrapper.internal | ||
|
||
import flank.common.dotFlank | ||
|
||
internal val flankRunnerPath: String | ||
get() = "$dotFlank/$FLANK_JAR_NAME" | ||
|
||
private const val FLANK_JAR_NAME = "flank.jar" |
10 changes: 10 additions & 0 deletions
10
flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/RunFlankOnLatestVersion.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,10 @@ | ||
package com.github.flank.wrapper.internal | ||
|
||
internal fun runFlankOnLatestVersion(args: Array<out String>) { | ||
if (!compareLatestVersionCheckSumWithCurrent()) { | ||
println("The new Flank version is available. Downloading new version...") | ||
downloadLatestFlankVersion() | ||
println("The new Flank version is ready to use") | ||
} | ||
executeFlank(args) | ||
} |
Oops, something went wrong.