Skip to content

Commit

Permalink
fixed code
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Adamczyk committed Jul 29, 2020
1 parent 5e3b1a6 commit b6d5110
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 64 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ jobs:
protocol: https
EOF
- name: Remove old release
- name: Delete old release
run: |
hub version
flankScripts release deleteOldRelease --git-tag=$RELEASE_TAG
- name: Rename old tag
- name: Delete old tag
if: ${{ env.RELEASE_TAG == 'flank_snapshot' }}
run: flankScripts release removeOldTag --git-tag=$RELEASE_TAG --username=$GITHUB_ACTOR --token=${{ secrets.GITHUB_TOKEN }}
run: flankScripts release deleteOldTag --git-tag=$RELEASE_TAG --username=$GITHUB_ACTOR --token=${{ secrets.GITHUB_TOKEN }}

- name: Release snapshot
if: ${{ env.RELEASE_TAG == 'flank_snapshot' }}
Expand Down
6 changes: 3 additions & 3 deletions flank-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Available commands are:
- `jFrogDelete` Delete old version on bintray
- `jFrogSync` Sync maven repository using jfrog
- `deleteOldRelease` Delete old release on github
- `removeOldTag` Remove old tag on GitHub
- `deleteOldTag` Delete old tag on GitHub

#### `releaseFlank`
Release Flank on GitHub
Expand Down Expand Up @@ -74,8 +74,8 @@ Delete old release on github
| `--git-tag` | Git Tag |


#### `removeOldTag`
Remove old tag on GitHub
#### `deleteOldTag`
Delete old tag on GitHub

| Option | Description |
|----------------- |----------------- |
Expand Down
8 changes: 3 additions & 5 deletions flank-scripts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ val artifactID = "flankScripts"
val shadowJar: ShadowJar by tasks
shadowJar.apply {
archiveClassifier.set("")
archiveFileName.set("${artifactID}.jar")
archiveFileName.set("$artifactID.jar")
mergeServiceFiles()

@Suppress("UnstableApiUsage")
manifest {
attributes(mapOf("Main-Class" to "flank.scripts.MainKt"))
}
//copyJarFile("$buildDir/libs/${artifactID}.jar", "$rootDir/bash/${artifactID}.jar")
}

version = "1.0"
Expand All @@ -29,16 +28,15 @@ application {
mainClassName = "flank.scripts.MainKt"
}


repositories {
jcenter()
mavenCentral()
maven(url = "https://kotlin.bintray.com/kotlinx")
maven(url = "https://kotlin.bintray.com/kotlinx")
}

dependencies {
implementation(kotlin("stdlib"))
implementation(KOTLIN_SERIALIZATION)
implementation(Kotlin.KOTLIN_SERIALIZATION)
implementation(Fuel.CORE)
implementation(Fuel.KOTLINX_SERIALIZATION)
implementation(Fuel.COROUTINES)
Expand Down
6 changes: 0 additions & 6 deletions flank-scripts/buildSrc/src/main/kotlin/CopyJarFile.kt

This file was deleted.

4 changes: 1 addition & 3 deletions flank-scripts/buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
object Kotlin {
const val PLUGIN_JVM = "jvm"
const val PLUGIN_SERIALIZATION = "plugin.serialization"
const val KOTLIN_SERIALIZATION = "org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Versions.KOTLINX_SERIALIZATION}"
}

const val PLUGIN_SHADOW_JAR = "com.github.johnrengelman.shadow"

const val KOTLIN_SERIALIZATION = "org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Versions.KOTLINX_SERIALIZATION}"
const val CLIKT = "com.github.ajalt:clikt:${Versions.CLIKT}"

object Fuel {
const val CORE = "com.github.kittinunf.fuel:fuel:${Versions.FUEL}"
const val COROUTINES = "com.github.kittinunf.fuel:fuel-coroutines:${Versions.FUEL}"
const val KOTLINX_SERIALIZATION = "com.github.kittinunf.fuel:fuel-kotlinx-serialization:${Versions.FUEL}"
}

2 changes: 1 addition & 1 deletion flank-scripts/src/main/kotlin/flank/scripts/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.subcommands
import flank.scripts.release.ReleaseCommand

class Main: CliktCommand(name = "flankScripts") {
class Main : CliktCommand(name = "flankScripts") {
override fun run() {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import flank.scripts.utils.toObject

fun <V : Any, E : FuelError, E2 : Exception> Result<V, E>.mapClientError(transform: (E) -> E2) = when (this) {
is Result.Success -> Result.Success(value)
is Result.Failure -> if(error.response.isClientError) Result.Failure(transform(error)) else Result.Failure(error)
is Result.Failure -> if (error.response.isClientError) Result.Failure(transform(error)) else Result.Failure(error)
}
fun FuelError.toGithubException() =
GitHubException(response.body().asString("application/json").toObject(GitHubErrorResponse.serializer()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.subcommands
import flank.scripts.release.hub.DeleteOldReleaseCommand
import flank.scripts.release.hub.ReleaseFlankCommand
import flank.scripts.release.hub.RemoveOldTagCommand
import flank.scripts.release.hub.DeleteOldTagCommand
import flank.scripts.release.jfrog.delete.DeleteOldSnapshotCommand
import flank.scripts.release.jfrog.sync.SyncMavenCommand
import flank.scripts.release.updatebugsnag.UpdateBugSnagCommand
Expand All @@ -18,7 +18,7 @@ class ReleaseCommand : CliktCommand(name = "release", help = "Contains all relea
DeleteOldSnapshotCommand(),
SyncMavenCommand(),
DeleteOldReleaseCommand(),
RemoveOldTagCommand()
DeleteOldTagCommand()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.github.ajalt.clikt.parameters.options.required

class DeleteOldReleaseCommand : CliktCommand(name = "deleteOldRelease", help = "Delete old release on github") {

private val gitTag by option( help = "Git Tag").required()
private val gitTag by option(help = "Git Tag").required()

override fun run() {
deleteOldRelease(gitTag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext

class RemoveOldTagCommand : CliktCommand(name = "removeOldTag", help = "Remove old tag on GitHub") {
class DeleteOldTagCommand : CliktCommand(name = "deleteOldTag", help = "Delete old tag on GitHub") {

private val gitTag by option(help = "Git Tag").required()
private val username by option(help = "Git User").required()
private val token by option(help = "Git Token").required()

override fun run() {
runBlocking {
when(val response = withContext(Dispatchers.Default) { removeOldTag(gitTag, username, token) }) {
is Result.Success -> println("Tag $gitTag was removed")
when (val response = withContext(Dispatchers.Default) { deleteOldTag(gitTag, username, token) }) {
is Result.Success -> println("Tag $gitTag was deleted")
is Result.Failure -> println(response.error)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import kotlinx.serialization.Serializable

@Serializable
data class GitHubErrorResponse(
val message: String,
@SerialName("documentation_url") val documentationUrl: String? = ""
val message: String,
@SerialName("documentation_url") val documentationUrl: String? = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import flank.scripts.utils.runCommand
import java.io.File
import java.nio.file.Path

fun releaseFlank(path: Path, gitTag: String, commitHash: String, isSnapshotRelease: Boolean) {
fun releaseFlank(path: Path, gitTag: String, commitHash: String, isSnapshotRelease: Boolean): Int {
val releasePath = moveFlankToReleaseDirectory(path)
val releaseCommand = if(isSnapshotRelease) {
val releaseCommand = if (isSnapshotRelease) {
hubStableSnapshotCommand(releasePath, gitTag, commitHash)
} else {
hubStableReleaseCommand(releasePath, gitTag, commitHash)
}
releaseCommand.runCommand()
return releaseCommand.runCommand()
}

private fun hubStableReleaseCommand(path: String, gitTag: String, commitHash: String) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.required
import com.github.ajalt.clikt.parameters.types.path
import kotlin.system.exitProcess

class ReleaseFlankCommand : CliktCommand(name = "releaseFlank", help = "Release Flank on GitHub") {

private val inputFile by option(help = "Path to release file").path(mustExist = true).required()
private val snapshot by option(help = "Is Snapshot release").flag(default = false)
private val gitTag by option( help = "Git Tag").required()
private val commitHash by option( help = "Git Commit hash").required()
private val gitTag by option(help = "Git Tag").required()
private val commitHash by option(help = "Git Commit hash").required()

override fun run() {
releaseFlank(inputFile, gitTag, commitHash, snapshot)
exitProcess(releaseFlank(inputFile, gitTag, commitHash, snapshot))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import com.github.kittinunf.fuel.core.extensions.authentication
import flank.scripts.exceptions.mapClientError
import flank.scripts.exceptions.toGithubException

fun removeOldTag(tag: String, username: String, password: String) =
Fuel.delete(REMOVE_ENDPOINT + tag)
fun deleteOldTag(tag: String, username: String, password: String) =
Fuel.delete(DELETE_ENDPOINT + tag)
.authentication()
.basic(username, password)
.response()
.third
.mapClientError { it.toGithubException() }

private const val REMOVE_ENDPOINT = "https://api.github.com/repos/Flank/flank/git/refs/tags/"
private const val DELETE_ENDPOINT = "https://api.github.com/repos/Flank/flank/git/refs/tags/"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ package flank.scripts.release.jfrog.sync
import flank.scripts.release.jfrog.flankMaven
import flank.scripts.utils.runCommand

fun jFrogSync(gitTag: String) {
"jfrog bt mcs ${flankMaven(gitTag)}".runCommand(retryCount = 3)
}
fun jFrogSync(gitTag: String) = "jfrog bt mcs ${flankMaven(gitTag)}".runCommand(retryCount = 3)
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package flank.scripts.release.jfrog.sync
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.required
import kotlin.system.exitProcess

class SyncMavenCommand : CliktCommand(name = "jFrogSync", help = "Sync maven repository using jfrog") {

private val gitTag by option( help = "Git Tag").required()
private val gitTag by option(help = "Git Tag").required()

override fun run() {
jFrogSync(gitTag)
exitProcess(jFrogSync(gitTag))
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package flank.scripts.release.updatebugsnag

import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.Serializable

@Serializable
data class BugSnagRequest(
val apiKey: String,
val appVersion: String,
val releaseStage: String,
val builderName: String,
val sourceControl: SourceControl,
val metadata: Map<String, String> = mapOf()
val apiKey: String,
val appVersion: String,
val releaseStage: String,
val builderName: String,
val sourceControl: SourceControl,
val metadata: Map<String, String> = mapOf()
)

@Serializable
data class SourceControl(
val provider: String,
val repository: String,
val revision: String
val provider: String,
val repository: String,
val revision: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import kotlinx.serialization.Serializable

@Serializable
data class BugSnagResponse(
val status: String,
val warnings: List<String> = listOf(),
val errors: List<String> = listOf()
val status: String,
val warnings: List<String> = listOf(),
val errors: List<String> = listOf()
)

object BugSnagResponseDeserializer : ResponseDeserializable<BugSnagResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@ import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.required
import com.github.kittinunf.result.Result
import flank.scripts.utils.ERROR_WHEN_RUNNING
import flank.scripts.utils.SUCCESS
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import kotlin.system.exitProcess

class UpdateBugSnagCommand : CliktCommand(name = "updateBugsnag", help = "Update Bugnsag") {

private val bugsnagApiKey by option(help = "Bugsnag api key").required()
private val appVersion by option(help = "App version to update").required()
private val githubWorkflowUrl by option(help = "GitHub workflow url")


override fun run() {
runBlocking {
withContext(Dispatchers.IO) {
when(val response = updateBugsnag(bugsnagApiKey, appVersion, githubWorkflowUrl.orEmpty())) {
is Result.Success -> println("Bugsnag was updated")
is Result.Failure -> println(response.error)
when (val response = updateBugsnag(bugsnagApiKey, appVersion, githubWorkflowUrl.orEmpty())) {
is Result.Success -> {
println("Bugsnag was updated")
exitProcess(SUCCESS)
}
is Result.Failure -> {
println(response.error)
exitProcess(ERROR_WHEN_RUNNING)
}
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ private fun ProcessBuilder.startWithRetry(retryCount: Int): Int {
return processResponse
}

const val SUCCESS = 0
const val ERROR_WHEN_RUNNING = 1
private const val EXCEPTION_WHEN_CALLING_COMMAND_CODE = -1
2 changes: 1 addition & 1 deletion test_runner/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit b6d5110

Please sign in to comment.