Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ inputs:
version:
description: 'Flank version to run'
required: false
service_account:
description: 'Service account for authentication. It could be file content or file itself.'
required: true
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
curl -L https://github.com/Flank/flank/releases/download/flank-scripts-1.9.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
- id: authentication
run: |
./flankScripts firebase save_service_account --account=${{ inputs.service_account }}
shell: bash
4 changes: 4 additions & 0 deletions common/src/main/kotlin/flank/common/Files.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

val defaultCredentialPath: Path by lazy {
Paths.get(userHome, ".config/gcloud/application_default_credentials.json")
}

val userHome: String by lazy {
if (isWindows) System.getenv("HOMEPATH") else System.getProperty("user.home")
}
Expand Down
92 changes: 3 additions & 89 deletions docs/flank-scripts/command_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ ___

- `firebase` - Group of commands for managing firebase integrations
- `check_for_sdk_updates` - Check for new SDK features and create update tasks for it
- `generate_client` - Generate Java Client based on api schema
- `update_api` - Update api schema
- `generate_client` - Generate Java Client based on api schema
- `update_api` - Update api schema
- `save_service_account` - Save given service account to flank credentials location

___

Expand Down Expand Up @@ -75,93 +76,6 @@ ___

(1) - please note that there is only one command, but it may change in the future.

### Package structure for CLI

```bash
flank-scripts/
├── 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

`flankScripts <command group> [<subgroup>] <command name> [<arguments>]`
92 changes: 0 additions & 92 deletions docs/flank-scripts/ops_structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,95 +4,3 @@ Flank-scripts `ops` packages mostly match `cli` structure, however, for widely u
called `common`.
For better code organization `updatebinaries` has a separate package inside `dependencies`, as well as `jfrog` in
`release` package.

Ops package structure and file organization are presented on the tree below:

```bash
├── ops
│ ├── assemble
│ │ ├── BuildFlank.kt
│ │ ├── BuildGo.kt
│ │ ├── android
│ │ │ ├── BuildBaseAndroidApk.kt
│ │ │ ├── BuildBaseAndroidTests.kt
│ │ │ ├── BuildCucumberSampleApk.kt
│ │ │ ├── BuildDuplicatedNamesApks.kt
│ │ │ ├── BuildMultiModulesApks.kt
│ │ │ ├── Common.kt
│ │ │ └── RunAndroidOps.kt
│ │ └── ios
│ │ ├── BuildEarlGreyExample.kt
│ │ ├── BuildExample.kt
│ │ ├── BuildFlankExampleCommand.kt
│ │ ├── BuildFtl.kt
│ │ ├── BuildGameLoopExampleCommand.kt
│ │ ├── BuildIosIPA.kt
│ │ ├── BuildIosTestArtifacts.kt
│ │ ├── BuildTestPlansExample.kt
│ │ ├── IosBuildCommand.kt
│ │ ├── RunFtlLocal.kt
│ │ └── UniversalFramework.kt
│ ├── common
│ │ ├── DownloadSoftware.kt
│ │ ├── EarlGreyExampleConsts.kt
│ │ ├── GenerateChangeLog.kt
│ │ └── ReleaseNotesWithType.kt
│ ├── dependencies
│ │ ├── InstallXcPretty.kt
│ │ ├── SetupIosEnv.kt
│ │ ├── UpdateAllDependencies.kt
│ │ └── common
│ │ ├── DependenciesResultCheck.kt
│ │ ├── DependencyExtensions.kt
│ │ ├── DependencyUpdate.kt
│ │ ├── FindOutdatedDependencies.kt
│ │ ├── GradleDependency.kt
│ │ ├── UpdateDependencies.kt
│ │ ├── UpdateGradle.kt
│ │ ├── UpdatePlugins.kt
│ │ └── UpdateVersionsInFile.kt
│ ├── firebase
│ │ ├── CheckForSDKUpdate.kt
│ │ ├── CommitList.kt
│ │ ├── GenerateJavaClient.kt
│ │ ├── SDKUpdateContext.kt
│ │ ├── UpdateApiJson.kt
│ │ └── common
│ │ └── Extensions.kt
│ ├── github
│ │ ├── CopyGitHubProperties.kt
│ │ ├── DeleteOldRelease.kt
│ │ ├── DeleteOldTag.kt
│ │ ├── DownloadFlank.kt
│ │ └── ReleaseFlank.kt
│ ├── integrationtests
│ │ ├── ProcessIntegrationTestsResult.kt
│ │ └── common
│ │ ├── ITResult.kt
│ │ ├── IntegrationResultContext.kt
│ │ └── PrepareMessage.kt
│ ├── linter
│ │ ├── ApplyKtlintToIdea.kt
│ │ └── LinkGitHooks.kt
│ ├── release
│ │ ├── CreateReleaseNotes.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


```
2 changes: 1 addition & 1 deletion flank-scripts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ shadowJar.apply {
}
}
// <breaking change>.<feature added>.<fix/minor change>
version = "1.8.0"
version = "1.9.0"
group = "com.github.flank"

application {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ object FirebaseCommand : CliktCommand(
subcommands(
UpdateApiCommand,
GenerateClientCommand,
CheckForSdkUpdatesCommand
CheckForSdkUpdatesCommand,
SaveServiceAccountCommand
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package flank.scripts.cli.firebase

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.required
import flank.scripts.ops.firebase.saveServiceAccount

object SaveServiceAccountCommand : CliktCommand(
name = "save_service_account",
help = "Save given service account to flank credentials location"
) {
private val serviceAccount: String by option("--account").required()
Comment thread
pawelpasterz marked this conversation as resolved.
override fun run() {
saveServiceAccount(serviceAccount)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package flank.scripts.ops.firebase

import flank.common.defaultCredentialPath
import flank.common.downloadFile
import java.io.File
import java.nio.file.Path

fun saveServiceAccount(
serviceAccount: String,
serviceAccountPath: Path = defaultCredentialPath.toAbsolutePath()
) = when {
serviceAccount.startsWith("http", true) -> downloadFile(serviceAccount, serviceAccountPath)
Comment thread
pawelpasterz marked this conversation as resolved.
serviceAccount.endsWith(".json", true) -> saveFromFile(serviceAccount, serviceAccountPath)
else -> saveFromStr(serviceAccount, serviceAccountPath)
}

private fun saveFromFile(
path: String,
serviceAccountPath: Path = defaultCredentialPath.toAbsolutePath()
) {
File(path).copyTo(serviceAccountPath.toFile(), overwrite = true)
}

private fun saveFromStr(
serviceAccountData: String,
serviceAccountPath: Path = defaultCredentialPath.toAbsolutePath()
) {
serviceAccountPath.toFile().writeText(serviceAccountData)
}
2 changes: 2 additions & 0 deletions flank-scripts/src/test/kotlin/flank/scripts/FuelMockServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import com.github.kittinunf.fuel.core.Request
import com.github.kittinunf.fuel.core.Response
import com.github.kittinunf.fuel.core.requests.DefaultBody
import flank.scripts.data.zenhub.ZENHUB_BASE_URL
import flank.scripts.ops.firebase.testContent

class FuelMockServer : Client {
override fun executeRequest(request: Request): Response {
val url = request.url.toString()
return when {
url.startsWith("https://api.github.com/repos/flank/flank/", ignoreCase = true) -> handleGithubMockRequest(url, request)
url.startsWith(ZENHUB_BASE_URL) -> handleZenhubMockRequest(url, request)
url == "http://test.account.service" -> request.buildResponse(testContent, 200)
else -> Response(request.url)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package flank.scripts.ops.firebase

import com.google.common.truth.Truth.assertThat
import flank.scripts.FuelTestRunner
import org.junit.Test
import org.junit.runner.RunWith
import java.nio.file.Files

@RunWith(FuelTestRunner::class)
class SaveServiceAccountTest {

@Test
fun `Should download service account`() {
// given
val testPath = Files.createTempFile("xxx", ".json")
val testLink = "http://test.account.service"

// when
saveServiceAccount(testLink, testPath)

// then
assertThat(testPath.toFile().readText()).isEqualTo(testContent)
}

@Test
fun `Should store service account`() {
// given
val testPath = Files.createTempFile("xxx", ".json")
val storeTestContent = "$testContent store"

// when
saveServiceAccount(storeTestContent, testPath)

// then
assertThat(testPath.toFile().readText()).isEqualTo(storeTestContent)
}

@Test
fun `Should copy service account`() {
// given
val testPath = Files.createTempFile("xxx", ".json")
val fileTestContent = "$testContent file"
val serviceAccount = Files.createTempFile("account", ".json").apply {
toFile().writeText(fileTestContent)
}

// when
saveServiceAccount(serviceAccount.toString(), testPath)

// then
println(testPath.toFile().readText())
assertThat(testPath.toFile().readText()).isEqualTo(fileTestContent)
}
}

internal const val testContent = "service @ccount"
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.google.cloud.storage.BucketInfo
import com.google.cloud.storage.Storage
import com.google.cloud.storage.StorageClass
import com.google.cloud.storage.StorageOptions
import flank.common.defaultCredentialPath
import flank.common.isWindows
import flank.common.logLn
import ftl.args.IArgs.Companion.AVAILABLE_PHYSICAL_SHARD_COUNT_RANGE
Expand All @@ -17,7 +18,6 @@ import ftl.config.FtlConstants.GCS_PREFIX
import ftl.config.FtlConstants.JSON_FACTORY
import ftl.config.FtlConstants.useMock
import ftl.config.credential
import ftl.config.defaultCredentialPath
import ftl.gc.GcStorage
import ftl.gc.GcToolResults
import ftl.reports.xml.model.JUnitTestResult
Expand Down
Loading