Skip to content

Commit

Permalink
refactor: Refactor flank scripts (#1533)
Browse files Browse the repository at this point in the history
Fixes #1541

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

All tests pass, Flank scripts work like before

## Checklist

- [X] CiCommand
- [X] ContributionCommand
- [X] DependenciesCommand
- [X] PullRequestCommand
- [x] IntegrationCommand 
- [x] ReleaseCommand
- [x] ShellCommand 
   - [x]   FirebaseCommand, 
   - [x]   BuildExampleCommand, 
   - [x]   BuildFtlCommand,
   - [x]   RunFtlLocalCommand,
   - [x]   UniversalFrameworkCommand,
   - [x]   OpsCommand,
   - [x]   UpdateBinariesCommand,
   - [x]   BuildFlankCommand,
   - [x]   InstallXcPrettyCommand,
   - [x]   SetupIosEnvCommand
- [x] TestArtifactsCommand
- [x] Utils
- [x] Tests
  • Loading branch information
adamfilipow92 authored Feb 3, 2021
1 parent 9f09d47 commit ae09391
Show file tree
Hide file tree
Showing 240 changed files with 2,034 additions and 1,702 deletions.
52 changes: 52 additions & 0 deletions common/src/test/kotlin/flank/common/FilesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package flank.common

import io.mockk.InternalPlatformDsl.toStr
import org.junit.After
import org.junit.Assert
import org.junit.Assert.assertTrue
import org.junit.Assume.assumeFalse
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
Expand All @@ -14,6 +16,9 @@ class FilesTest {
private val linkName = "tmp"
private val targetName = "../"

@get:Rule
val root = TemporaryFolder()

@Test
fun `should create symbolic link`() {
assumeFalse(isWindows)
Expand Down Expand Up @@ -63,4 +68,51 @@ class FilesTest {
fun tearDown() {
File(linkName).delete()
}

@Test
fun `Should create symbolic file at desired location`() {
assumeFalse(isWindows)
// given
val testFile = root.newFile("test.file").toPath()
val expectedDestination = Paths.get(root.newFolder("temp").toString(), "test.link")

// when
createSymbolicLinkToFile(expectedDestination, testFile)

// then
assertTrue(Files.isSymbolicLink(expectedDestination))

// clean
testFile.toFile().delete()
expectedDestination.toFile().delete()
}

@Test
fun `Should check if directory contains all needed files`() {
// given
val testDirectory = root.newFolder("test").toPath()
val testFiles = listOf(
Paths.get(testDirectory.toString(), "testFile1"),
Paths.get(testDirectory.toString(), "testFile2"),
Paths.get(testDirectory.toString(), "testFile3"),
Paths.get(testDirectory.toString(), "testFile4")
)

testFiles.forEach { Files.createFile(it) }

// when
val resultTrue = testDirectory.toFile().hasAllFiles(testFiles.map { it.fileName.toString() })
val resultFalse = testDirectory.toFile()
.hasAllFiles(
(testFiles + Paths.get(testDirectory.toString(), "testFile5"))
.map { it.fileName.toString() }
)

// then
assertTrue(resultTrue)
Assert.assertFalse(resultFalse)

// clean
testDirectory.toFile().deleteRecursively()
}
}
4 changes: 2 additions & 2 deletions flank-scripts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ shadowJar.apply {
}
}
// <breaking change>.<feature added>.<fix/minor change>
version = "1.4.6"
version = "1.5.0"
group = "com.github.flank"

application {
mainClassName = "flank.scripts.MainKt"
mainClassName = "flank.scripts.cli.MainKt"
applicationDefaultJvmArgs = listOf(
"-Xmx2048m",
"-Xms512m"
Expand Down
30 changes: 0 additions & 30 deletions flank-scripts/src/main/kotlin/flank/scripts/Main.kt

This file was deleted.

16 changes: 0 additions & 16 deletions flank-scripts/src/main/kotlin/flank/scripts/ci/CiCommand.kt

This file was deleted.

This file was deleted.

This file was deleted.

30 changes: 30 additions & 0 deletions flank-scripts/src/main/kotlin/flank/scripts/cli/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package flank.scripts.cli

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.subcommands
import flank.scripts.cli.ci.CiCommand
import flank.scripts.cli.contribution.ContributionCommand
import flank.scripts.cli.dependencies.DependenciesCommand
import flank.scripts.cli.integration.IntegrationCommand
import flank.scripts.cli.pullrequest.PullRequestCommand
import flank.scripts.cli.release.ReleaseCommand
import flank.scripts.cli.shell.ShellCommand
import flank.scripts.cli.testartifacts.TestArtifactsCommand

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

fun main(args: Array<String>) {
Main().subcommands(
ReleaseCommand,
CiCommand,
DependenciesCommand,
TestArtifactsCommand,
ShellCommand,
PullRequestCommand,
IntegrationCommand,
ContributionCommand
).main(args)
}
17 changes: 17 additions & 0 deletions flank-scripts/src/main/kotlin/flank/scripts/cli/ci/CiCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package flank.scripts.cli.ci

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.subcommands

object CiCommand : CliktCommand(
help = "Contains command related to CI",
name = "ci"
) {
init {
subcommands(GenerateReleaseNotesCommand, NextReleaseTagCommand)
}

@Suppress("EmptyFunctionBlock")
override fun run() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package flank.scripts.cli.ci

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.required
import com.google.common.annotations.VisibleForTesting
import flank.scripts.ops.ci.createReleaseNotes

object GenerateReleaseNotesCommand : CliktCommand(
help = "Command to append item to release notes",
name = "generateReleaseNotes"
) {
private val token by option(help = "Git Token").required()

@VisibleForTesting
internal val releaseNotesFile by option(help = "Path to release_notes.md")
.default("release_notes.md")

override fun run() {
createReleaseNotes(token, releaseNotesFile)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package flank.scripts.cli.ci

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.ci.createNextReleaseTag

object NextReleaseTagCommand : CliktCommand(
help = "Print next release tag",
name = "nextReleaseTag"
) {
private val token by option(help = "Git Token").required()

override fun run() {
createNextReleaseTag(token)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package flank.scripts.cli.contribution

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.subcommands

object ContributionCommand : CliktCommand(
name = "contribution",
help = "Tasks for assisting with contribution"
) {
init {
subcommands(
GitHooksLinkCommand,
IdeaKtlintCodeStyleCommand
)
}

@Suppress("EmptyFunctionBlock")
override fun run() {
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package flank.scripts.contribution.githooks
package flank.scripts.cli.contribution

import com.github.ajalt.clikt.core.CliktCommand
import flank.common.logLn
import flank.scripts.utils.runCommand
import flank.scripts.ops.contribution.linkGitHooks

object GitHooksLinkCommand : CliktCommand(
name = "linkGitHooks",
help = "Creates a link for pre-commit hook for automatic linting"
) {
override fun run() {
logLn("Linking Githooks.")
linkGitHooks()
}

private fun linkGitHooks() = "git config --local core.hooksPath .githooks/".runCommand()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package flank.scripts.cli.contribution

import com.github.ajalt.clikt.core.CliktCommand
import flank.scripts.ops.contribution.applyKtlintToIdea
import kotlinx.coroutines.runBlocking

object IdeaKtlintCodeStyleCommand : CliktCommand(
name = "applyKtlintToIdea",
help = "Applies Ktlint to this idea project forcefully"
) {
override fun run(): Unit = runBlocking {
applyKtlintToIdea()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package flank.scripts.cli.dependencies

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.subcommands

object DependenciesCommand : CliktCommand(
name = "dependencies",
help = "Task for manages dependencies"
) {
init {
subcommands(DependenciesUpdateCommand)
}

@Suppress("EmptyFunctionBlock")
override fun run() {
}
}
Loading

0 comments on commit ae09391

Please sign in to comment.