diff --git a/action.yml b/action.yml new file mode 100644 index 0000000000..1e2705e55d --- /dev/null +++ b/action.yml @@ -0,0 +1,19 @@ +name: 'Flank' +description: 'Run Flank from Github actions!' +inputs: + version: + description: 'Flank version to run' + required: false +runs: + using: "composite" + steps: + - name: Download flankScripts + run: | + curl -L https://github.com/Flank/flank/releases/download/flank-scripts-1.8.0/flank-scripts.jar --output flank-scripts.jar + echo 'java -jar ./flank-scripts.jar "$@"' > flankScripts + chmod +x flankScripts + shell: bash + - id: download_flank + run: | + ./flankScripts github download_flank --version=${{ inputs.version }} + shell: bash diff --git a/docs/flank-scripts/README.md b/docs/flank-scripts/README.md index b74053866d..62eacef120 100644 --- a/docs/flank-scripts/README.md +++ b/docs/flank-scripts/README.md @@ -155,6 +155,7 @@ Properties are skipped by git and should not be attached to a commit. Note, the │ │ ├── CopyIssuePropertiesCommand.kt │ │ ├── DeleteOldTagCommand.kt │ │ ├── DeleteReleaseCommand.kt +│ │ ├── DownloadFlankCommand.kt │ │ ├── GitHubCommand.kt │ │ └── MakeReleaseCommand.kt │ ├── integrationtests @@ -165,11 +166,9 @@ Properties are skipped by git and should not be attached to a commit. Note, the │ │ ├── ApplyToIdeCommand.kt │ │ └── LinterCommand.kt │ ├── release -│ │ ├── DeleteSnapshotCommand.kt │ │ ├── GenerateReleaseNotesCommand.kt │ │ ├── NextTagCommand.kt -│ │ ├── ReleaseCommand.kt -│ │ └── SyncWithMavenCentralCommand.kt +│ │ └── ReleaseCommand.kt │ └── testartifacts │ ├── DownloadCommand.kt │ ├── LinkCommand.kt @@ -256,17 +255,14 @@ Properties are skipped by git and should not be attached to a commit. Note, the │ │ ├── CopyGitHubProperties.kt │ │ ├── DeleteOldRelease.kt │ │ ├── DeleteOldTag.kt +│ │ ├── DownloadFlank.kt │ │ └── ReleaseFlank.kt │ ├── integrationtests │ │ ├── ProcessIntegrationTestsResult.kt │ │ └── common -│ │ ├── ITResults.kt -│ │ ├── IntegrationContext.kt +│ │ ├── ITResult.kt +│ │ ├── IntegrationResultContext.kt │ │ └── PrepareMessage.kt -│ ├── jfrog -│ │ ├── DeleteOldSnapshot.kt -│ │ ├── JFrogCommandHelper.kt -│ │ └── SyncMaven.kt │ ├── linter │ │ ├── ApplyKtlintToIdea.kt │ │ └── LinkGitHooks.kt diff --git a/docs/flank-scripts/command_overview.md b/docs/flank-scripts/command_overview.md index ae312a6d50..7b468cfb56 100644 --- a/docs/flank-scripts/command_overview.md +++ b/docs/flank-scripts/command_overview.md @@ -39,6 +39,7 @@ ___ - `delete_old_tag` - Delete old tag on GitHub - `delete_release` - Delete old release on github - `make_release` - Make new Github release + - `download_flank` - Downloads flank.jar with selected version. ___ @@ -78,47 +79,87 @@ ___ ```bash flank-scripts/ -└── cli/ - ├── assemble/ - │ ├── android/ - │ │ └── AppCommand.kt - │ ├── ios/ - │ │ ├── AllCommand.kt - │ │ ├── EarlGreyCommand.kt - │ │ ├── FlankExampleCommand.kt - │ │ ├── GameLoopCommand.kt - │ │ └── TestPlansCommand.kt - │ └── GoArtifactsCommand.kt - ├── firebase/ - │ ├── CheckForSdkUpdatesCommand.kt - │ ├── GenerateClientCommand.kt - │ └── UpdateApiCommand.kt - ├── github/ - │ ├── DeleteOldTagCommand.kt - │ ├── DeleteGithubReleaseCommand.kt - │ ├── MakeGithubReleaseCommand.kt - │ ├── CopyIssuePropertiesCommand.kt - ├── gradle/ - │ └── UpdateDependenciesCommand.kt - ├── integrationtests/ - │ └── ProcessResultsCommand.kt - ├── linter/ - │ ├── ApplyToGitHooksCommand.kt - │ └── ApplyToIdeCommand.kt - ├── release/ - │ ├── DeleteSnapshotCommand.kt - │ ├── GenerateReleaseNotesCommand.kt - │ ├── NextTagCommand.kt - │ └── SyncWithMavenCentralCommand.kt - └── testartifacts/ - ├── DownloadCommand.kt - ├── LinkCommand.kt - ├── PrepareCommand.kt - ├── RemoveRemoteCommand.kt - ├── ResolveCommand.kt - ├── UnzipCommand.kt - ├── UploadCommand.kt - └── ZipCommand.kt +├── cli +│ ├── Main.kt +│ ├── assemble +│ │ ├── AssembleCommand.kt +│ │ ├── FlankCommand.kt +│ │ ├── GoCommand.kt +│ │ ├── android +│ │ │ ├── AndroidCommand.kt +│ │ │ └── AppCommand.kt +│ │ └── ios +│ │ ├── EarlGreyCommand.kt +│ │ ├── ExampleCommand.kt +│ │ ├── FlankExampleCommand.kt +│ │ ├── FtlCommand.kt +│ │ ├── GameLoopExampleCommand.kt +│ │ ├── IosCommand.kt +│ │ ├── RunFtlLocalCommand.kt +│ │ └── TestPlansExample.kt +│ ├── dependencies +│ │ ├── DependenciesCommand.kt +│ │ ├── InstallXcPrettyCommand.kt +│ │ ├── SetupIosEnvCommand.kt +│ │ ├── UniversalFrameworkCommand.kt +│ │ ├── UpdateBinariesCommand.kt +│ │ └── UpdateCommand.kt +│ ├── firebase +│ │ ├── CheckForSdkUpdatesCommand.kt +│ │ ├── FirebaseCommand.kt +│ │ ├── GenerateClientCommand.kt +│ │ └── UpdateApiCommand.kt +│ ├── github +│ │ ├── CopyIssuePropertiesCommand.kt +│ │ ├── DeleteOldTagCommand.kt +│ │ ├── DeleteReleaseCommand.kt +│ │ ├── DownloadFlankCommand.kt +│ │ ├── GitHubCommand.kt +│ │ └── MakeReleaseCommand.kt +│ ├── integrationtests +│ │ ├── IntegrationTestsCommand.kt +│ │ └── ProcessResultCommand.kt +│ ├── linter +│ │ ├── ApplyToGitHooksCommand.kt +│ │ ├── ApplyToIdeCommand.kt +│ │ └── LinterCommand.kt +│ ├── release +│ │ ├── GenerateReleaseNotesCommand.kt +│ │ ├── NextTagCommand.kt +│ │ └── ReleaseCommand.kt +│ └── testartifacts +│ ├── DownloadCommand.kt +│ ├── LinkCommand.kt +│ ├── PrepareCommand.kt +│ ├── RemoveRemoteCommand.kt +│ ├── ResolveCommand.kt +│ ├── TestArtifactsCommand.kt +│ ├── UnzipCommand.kt +│ ├── UploadCommand.kt +│ └── ZipCommand.kt +├── data +│ ├── github +│ │ ├── GitHubErrorResponse.kt +│ │ ├── GithubApi.kt +│ │ ├── commons +│ │ │ └── LastWorkflowRunDate.kt +│ │ └── objects +│ │ ├── GitHubCommit.kt +│ │ ├── GitHubCreateIssue.kt +│ │ ├── GitHubCreateIssueComment.kt +│ │ ├── GitHubRelease.kt +│ │ ├── GitHubSetAssigneesRequest.kt +│ │ ├── GitHubSetLabelsRequest.kt +│ │ ├── GitHubUpdateIssue.kt +│ │ ├── GitHubWorkflowRun.kt +│ │ └── GithubPullRequest.kt +│ └── zenhub +│ ├── ZenHubAPI.kt +│ ├── ZenHubIssue.kt +│ └── objects +│ └── ConvertToEpicRequest.kt + + ``` ### Usage diff --git a/docs/flank-scripts/ops_structure.md b/docs/flank-scripts/ops_structure.md index 29cbe6b905..33f917d639 100644 --- a/docs/flank-scripts/ops_structure.md +++ b/docs/flank-scripts/ops_structure.md @@ -30,82 +30,69 @@ Ops package structure and file organization are presented on the tree below: │ │ ├── BuildIosTestArtifacts.kt │ │ ├── BuildTestPlansExample.kt │ │ ├── IosBuildCommand.kt -│ │ ├── LipoHelper.kt │ │ ├── RunFtlLocal.kt │ │ └── UniversalFramework.kt │ ├── common -│ │ ├── ConventionalCommitFormatter.kt +│ │ ├── DownloadSoftware.kt │ │ ├── EarlGreyExampleConsts.kt │ │ ├── GenerateChangeLog.kt │ │ └── ReleaseNotesWithType.kt │ ├── dependencies -│ │ ├── DependenciesResultCheck.kt -│ │ ├── DependencyExtensions.kt -│ │ ├── DependencyUpdate.kt -│ │ ├── DownloadSoftware.kt -│ │ ├── FindOutdatedDependencies.kt -│ │ ├── FindVersionInLines.kt -│ │ ├── GradleDependency.kt │ │ ├── InstallXcPretty.kt │ │ ├── SetupIosEnv.kt │ │ ├── UpdateAllDependencies.kt -│ │ ├── UpdateDependencies.kt -│ │ ├── UpdateGradle.kt -│ │ ├── UpdatePlugins.kt -│ │ ├── UpdateVersionsInFile.kt -│ │ └── updatebinaries -│ │ ├── UpdateAtomic.kt -│ │ ├── UpdateBinaries.kt -│ │ ├── UpdateLlvm.kt -│ │ └── UpdateSwift.kt +│ │ └── common +│ │ ├── DependenciesResultCheck.kt +│ │ ├── DependencyExtensions.kt +│ │ ├── DependencyUpdate.kt +│ │ ├── FindOutdatedDependencies.kt +│ │ ├── GradleDependency.kt +│ │ ├── UpdateDependencies.kt +│ │ ├── UpdateGradle.kt +│ │ ├── UpdatePlugins.kt +│ │ └── UpdateVersionsInFile.kt │ ├── firebase -│ │ ├── CheckForSDKUpdateCommand.kt +│ │ ├── CheckForSDKUpdate.kt │ │ ├── CommitList.kt -│ │ ├── Extensions.kt │ │ ├── GenerateJavaClient.kt -│ │ ├── LastSDKUpdateRun.kt -│ │ ├── OpenedUpdates.kt │ │ ├── SDKUpdateContext.kt -│ │ └── UpdateApiJson.kt +│ │ ├── UpdateApiJson.kt +│ │ └── common +│ │ └── Extensions.kt │ ├── github │ │ ├── CopyGitHubProperties.kt │ │ ├── DeleteOldRelease.kt │ │ ├── DeleteOldTag.kt -│ │ ├── FindReferenceIssue.kt -│ │ ├── ReleaseFlank.kt -│ │ ├── SetAssignees.kt -│ │ └── SetLabels.kt +│ │ ├── DownloadFlank.kt +│ │ └── ReleaseFlank.kt │ ├── integrationtests -│ │ ├── CommitList.kt -│ │ ├── Extensions.kt -│ │ ├── IntegrationContext.kt -│ │ ├── IssueList.kt -│ │ ├── PrepareMessage.kt │ │ ├── ProcessIntegrationTestsResult.kt -│ │ └── WorkflowSummary.kt +│ │ └── common +│ │ ├── ITResult.kt +│ │ ├── IntegrationResultContext.kt +│ │ └── PrepareMessage.kt │ ├── linter │ │ ├── ApplyKtlintToIdea.kt │ │ └── LinkGitHooks.kt │ ├── release -│ │ ├── AppendReleaseNotes.kt │ │ ├── CreateReleaseNotes.kt -│ │ ├── NextReleaseTag.kt -│ │ └── jfrog -│ │ ├── DeleteOldSnapshot.kt -│ │ ├── JFrogCommandHelper.kt -│ │ └── SyncMaven.kt -│ └── testartifacts -│ ├── ArtifactsArchive.kt -│ ├── Constants.kt -│ ├── Context.kt -│ ├── DownloadFixtures.kt -│ ├── IsNewVersionAvailable.kt -│ ├── LinkArtifacts.kt -│ ├── PrepareTestArtifacts.kt -│ ├── RemoveRemoteCopy.kt -│ ├── ResolveArtifacts.kt -│ ├── TestArtifactsRepo.kt -│ ├── UploadFixtures.kt -│ └── ZipArtifacts.kt +│ │ └── NextReleaseTag.kt +│ ├── testartifacts +│ │ ├── ArtifactsArchive.kt +│ │ ├── Context.kt +│ │ ├── DownloadFixtures.kt +│ │ ├── Helpers.kt +│ │ ├── LinkArtifacts.kt +│ │ ├── PrepareTestArtifacts.kt +│ │ ├── RemoveRemoteCopy.kt +│ │ ├── ResolveArtifacts.kt +│ │ ├── UploadFixtures.kt +│ │ └── ZipArtifacts.kt +│ └── updatebinaries +│ ├── UpdateAtomic.kt +│ ├── UpdateBinaries.kt +│ ├── UpdateLlvm.kt +│ └── UpdateSwift.kt + ``` diff --git a/flank-scripts/build.gradle.kts b/flank-scripts/build.gradle.kts index b1f5ce5548..8a3ab19d9f 100644 --- a/flank-scripts/build.gradle.kts +++ b/flank-scripts/build.gradle.kts @@ -26,7 +26,7 @@ shadowJar.apply { } } // .. -version = "1.7.3" +version = "1.8.0" group = "com.github.flank" application { diff --git a/flank-scripts/src/main/kotlin/flank/scripts/cli/github/DownloadFlankCommand.kt b/flank-scripts/src/main/kotlin/flank/scripts/cli/github/DownloadFlankCommand.kt new file mode 100644 index 0000000000..744e9fb0d8 --- /dev/null +++ b/flank-scripts/src/main/kotlin/flank/scripts/cli/github/DownloadFlankCommand.kt @@ -0,0 +1,22 @@ +package flank.scripts.cli.github + +import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.parameters.options.option +import flank.scripts.ops.github.downloadFlank +import kotlinx.coroutines.runBlocking + +object DownloadFlankCommand : CliktCommand( + name = "download_flank", + help = "Downloads flank.jar with selected version." + +) { + + private val version by option( + "--version", "-v", + help = "If the version not set, the latest version will be used." + ) + + override fun run() = runBlocking { + downloadFlank(version) + } +} diff --git a/flank-scripts/src/main/kotlin/flank/scripts/cli/github/GitHubCommand.kt b/flank-scripts/src/main/kotlin/flank/scripts/cli/github/GitHubCommand.kt index 7bdf77731c..509cb7b3b0 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/cli/github/GitHubCommand.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/cli/github/GitHubCommand.kt @@ -12,7 +12,8 @@ object GitHubCommand : CliktCommand( CopyIssuePropertiesCommand, DeleteReleaseCommand, DeleteOldTagCommand, - MakeReleaseCommand + MakeReleaseCommand, + DownloadFlankCommand ) } diff --git a/flank-scripts/src/main/kotlin/flank/scripts/data/github/GithubApi.kt b/flank-scripts/src/main/kotlin/flank/scripts/data/github/GithubApi.kt index 30dbb80e00..5b66d6c5f2 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/data/github/GithubApi.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/data/github/GithubApi.kt @@ -40,7 +40,11 @@ import flank.scripts.utils.toJson private const val URL_BASE = "https://api.github.com/repos" // ============= HTTP GITHUB API ============= -suspend fun getPrDetailsByCommit(commitSha: String, githubToken: String, repo: String = flankRepository): Result, Exception> = +suspend fun getPrDetailsByCommit( + commitSha: String, + githubToken: String, + repo: String = flankRepository +): Result, Exception> = Fuel.get("$URL_BASE/$repo/commits/$commitSha/pulls") .appendGitHubHeaders(githubToken, "application/vnd.github.groot-preview+json") .awaitResult(GithubPullRequestListDeserializer) @@ -53,44 +57,74 @@ suspend fun getLatestReleaseTag(githubToken: String, repo: String = flankReposit .awaitResult(GithubReleaseDeserializable) .mapClientErrorToGithubException() -suspend fun getGitHubPullRequest(githubToken: String, issueNumber: Int, repo: String = flankRepository): Result = +suspend fun getGitHubPullRequest( + githubToken: String, + issueNumber: Int, + repo: String = flankRepository +): Result = Fuel.get("$URL_BASE/$repo/pulls/$issueNumber") .appendGitHubHeaders(githubToken) .awaitResult(GithubPullRequestDeserializer) .mapClientErrorToGithubException() -suspend fun getGitHubIssue(githubToken: String, issueNumber: Int, repo: String = flankRepository): Result = +suspend fun getGitHubIssue( + githubToken: String, + issueNumber: Int, + repo: String = flankRepository +): Result = Fuel.get("$URL_BASE/$repo/issues/$issueNumber") .appendGitHubHeaders(githubToken) .awaitResult(GithubPullRequestDeserializer) .mapClientErrorToGithubException() -suspend fun getGitHubIssueList(githubToken: String, parameters: Parameters = emptyList(), repo: String = flankRepository): Result, Exception> = +suspend fun getGitHubIssueList( + githubToken: String, + parameters: Parameters = emptyList(), + repo: String = flankRepository +): Result, Exception> = Fuel.get("$URL_BASE/$repo/issues", parameters) .appendGitHubHeaders(githubToken) .awaitResult(GithubPullRequestListDeserializer) .mapClientErrorToGithubException() -suspend fun getGitHubCommitList(githubToken: String, parameters: Parameters = emptyList(), repo: String = flankRepository): Result, Exception> = +suspend fun getGitHubCommitList( + githubToken: String, + parameters: Parameters = emptyList(), + repo: String = flankRepository +): Result, Exception> = Fuel.get("$URL_BASE/$repo/commits", parameters) .appendGitHubHeaders(githubToken) .awaitResult(GitHubCommitListDeserializer) .mapClientErrorToGithubException() -suspend fun getGitHubWorkflowRunsSummary(githubToken: String, workflow: String, parameters: Parameters = emptyList(), repo: String = flankRepository): Result = +suspend fun getGitHubWorkflowRunsSummary( + githubToken: String, + workflow: String, + parameters: Parameters = emptyList(), + repo: String = flankRepository +): Result = Fuel.get("$URL_BASE/$repo/actions/workflows/$workflow/runs", parameters) .appendGitHubHeaders(githubToken) .awaitResult(GithubWorkflowRunsSummaryDeserializer) .mapClientErrorToGithubException() -suspend fun postNewIssueComment(githubToken: String, issueNumber: Int, payload: GitHubCreateIssueCommentRequest, repo: String = flankRepository): Result = +suspend fun postNewIssueComment( + githubToken: String, + issueNumber: Int, + payload: GitHubCreateIssueCommentRequest, + repo: String = flankRepository +): Result = Fuel.post("$URL_BASE/$repo/issues/$issueNumber/comments") .appendGitHubHeaders(githubToken) .body(payload.toJson()) .awaitResult(GitHubCreateIssueCommentResponseDeserializer) .mapClientErrorToGithubException() -suspend fun postNewIssue(githubToken: String, payload: GitHubCreateIssueRequest, repo: String = flankRepository): Result = +suspend fun postNewIssue( + githubToken: String, + payload: GitHubCreateIssueRequest, + repo: String = flankRepository +): Result = Fuel.post("$URL_BASE/$repo/issues") .appendGitHubHeaders(githubToken) .body(payload.toJson()) @@ -103,7 +137,12 @@ suspend fun getLabelsFromIssue(githubToken: String, issueNumber: Int, repo: Stri .awaitResult(GitHubLabelDeserializable) .mapClientErrorToGithubException() -suspend fun setLabelsToPullRequest(githubToken: String, pullRequestNumber: Int, labels: List, repo: String = flankRepository) { +suspend fun setLabelsToPullRequest( + githubToken: String, + pullRequestNumber: Int, + labels: List, + repo: String = flankRepository +) { Fuel.post("$URL_BASE/$repo/issues/$pullRequestNumber/labels") .appendGitHubHeaders(githubToken) .body(GitHubSetLabelsRequest(labels).toJson()) @@ -112,7 +151,12 @@ suspend fun setLabelsToPullRequest(githubToken: String, pullRequestNumber: Int, .success { println("$labels set to pull request #$pullRequestNumber") } } -suspend fun setAssigneesToPullRequest(githubToken: String, pullRequestNumber: Int, assignees: List, repo: String = flankRepository) { +suspend fun setAssigneesToPullRequest( + githubToken: String, + pullRequestNumber: Int, + assignees: List, + repo: String = flankRepository +) { Fuel.post("$URL_BASE/$repo/issues/$pullRequestNumber/assignees") .appendGitHubHeaders(githubToken) .body(GitHubSetAssigneesRequest(assignees).toJson()) @@ -124,7 +168,12 @@ suspend fun setAssigneesToPullRequest(githubToken: String, pullRequestNumber: In .success { println("$assignees set to pull request #$pullRequestNumber") } } -fun patchIssue(githubToken: String, issueNumber: Int, payload: GitHubUpdateIssueRequest, repo: String = flankRepository): Result = +fun patchIssue( + githubToken: String, + issueNumber: Int, + payload: GitHubUpdateIssueRequest, + repo: String = flankRepository +): Result = Fuel.patch("$URL_BASE/$repo/issues/$issueNumber") .appendGitHubHeaders(githubToken) .body(payload.toJson()) @@ -132,7 +181,12 @@ fun patchIssue(githubToken: String, issueNumber: Int, payload: GitHubUpdateIssue .third .mapClientErrorToGithubException() -fun deleteOldTag(tag: String, username: String, password: String, repo: String = flankRepository): Result = +fun deleteOldTag( + tag: String, + username: String, + password: String, + repo: String = flankRepository +): Result = Fuel.delete("$URL_BASE/$repo/git/refs/tags/$tag") .authentication() .basic(username, password) @@ -141,8 +195,10 @@ fun deleteOldTag(tag: String, username: String, password: String, repo: String = .mapClientErrorToGithubException() fun Request.appendGitHubHeaders(githubToken: String, contentType: String = "application/vnd.github.v3+json") = - appendHeader("Accept", contentType) - .appendHeader("Authorization", "token $githubToken") + appendHeader("Accept", contentType).also { + if (githubToken.isNotBlank()) + appendHeader("Authorization", "token $githubToken") + } // ============= JCABI GITHUB API ============= diff --git a/flank-scripts/src/main/kotlin/flank/scripts/ops/github/DownloadFlank.kt b/flank-scripts/src/main/kotlin/flank/scripts/ops/github/DownloadFlank.kt new file mode 100644 index 0000000000..8d789fa521 --- /dev/null +++ b/flank-scripts/src/main/kotlin/flank/scripts/ops/github/DownloadFlank.kt @@ -0,0 +1,19 @@ +package flank.scripts.ops.github + +import com.github.kittinunf.result.map +import com.google.common.annotations.VisibleForTesting +import flank.common.downloadFile +import flank.scripts.data.github.getLatestReleaseTag + +suspend fun downloadFlank(version: String?) = + version.getVersion().prepareDownloadUrl().downloadFlank() + +@VisibleForTesting +internal suspend fun String?.getVersion(): String = + takeUnless { it.isNullOrBlank() } ?: getLatestReleaseTag("").map { it.tag }.get() + +private fun String.prepareDownloadUrl() = "https://github.com/Flank/flank/releases/download/$this/$FLANK_JAR" + +private fun String.downloadFlank() = downloadFile(this, FLANK_JAR) + +private const val FLANK_JAR = "flank.jar" diff --git a/flank-scripts/src/test/kotlin/flank/scripts/GithubMockServerHandler.kt b/flank-scripts/src/test/kotlin/flank/scripts/GithubMockServerHandler.kt index a237a4b776..58646a5f89 100644 --- a/flank-scripts/src/test/kotlin/flank/scripts/GithubMockServerHandler.kt +++ b/flank-scripts/src/test/kotlin/flank/scripts/GithubMockServerHandler.kt @@ -34,7 +34,7 @@ fun handleGithubMockRequest(url: String, request: Request) = when { url ends """/issues/\d*/comments""" && request.isPOST -> request.buildResponse(createComment, 200) url ends """/commits\?since=*""" -> request.buildResponse(testGithubIssueList, 200) url.endsWith("/git/refs/tags/success") -> request.buildResponse("", 200) - url.endsWith("/releases/latest") && request.containsSuccessHeader() -> + url.endsWith("/releases/latest") -> request.buildResponse(GitHubRelease("v20.08.0").toJson(), 200) url.endsWith("/commits/success/pulls") -> request.buildResponse(Json.encodeToString(githubPullRequestTest), 200) url.endsWith("/commits") -> request.buildResponse(testGithubIssueList, 200) diff --git a/flank-scripts/src/test/kotlin/flank/scripts/ops/github/DownloadFlankTest.kt b/flank-scripts/src/test/kotlin/flank/scripts/ops/github/DownloadFlankTest.kt new file mode 100644 index 0000000000..4b0b72c57a --- /dev/null +++ b/flank-scripts/src/test/kotlin/flank/scripts/ops/github/DownloadFlankTest.kt @@ -0,0 +1,33 @@ +package flank.scripts.ops.github + +import com.github.kittinunf.result.map +import flank.scripts.data.github.getLatestReleaseTag +import kotlinx.coroutines.runBlocking +import org.junit.Assert +import org.junit.Test + +class DownloadFlankTest { + + @Test + fun `Should return latest tag if version is null`() { + val downloadedVersion = runBlocking { null.getVersion() } + val latestVersion = runBlocking { getLatestReleaseTag("").map { it.tag }.get() } + Assert.assertEquals(downloadedVersion, latestVersion) + } + + @Test + fun `Should return latest tag if version is empty`() { + val downloadedVersion = runBlocking { "".getVersion() } + val latestVersion = runBlocking { getLatestReleaseTag("").map { it.tag }.get() } + Assert.assertEquals(downloadedVersion, latestVersion) + } + + @Test + fun `Should return specified release tag`() { + val expectedReleaseTag = "v.1.1.1" + + val downloadedVersion = runBlocking { expectedReleaseTag.getVersion() } + + Assert.assertEquals(downloadedVersion, expectedReleaseTag) + } +}