Skip to content

Commit

Permalink
Add configuration file parameter to test, cloud and record commands (#…
Browse files Browse the repository at this point in the history
…1829)

* plan gets config file as parameter

* added `--config` parameter to test command

* added description to --config parameter

* added `--config` parameter to CloudCommand

* added `--config` parameter to RecordCommand

* Added test cases for confing injection

* Update maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt

* Update maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt

* WorkspaceExecutionPlanner: use Path instead of File

* standarize on YAML file ext

* WorkspaceExecutionPlannerErrorsTest: use named args for plan() invocation


* disable fail-fast in E2E GitHub Action

---------

Co-authored-by: Bartek Pacia <[email protected]>
  • Loading branch information
Hyla96 and bartekpacia authored Sep 3, 2024
1 parent 3384806 commit 2b73223
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
timeout-minutes: 20

strategy:
fail-fast: false
matrix:
java-version: [11, 17]

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
java-version: [11, 17]

Expand Down
8 changes: 8 additions & 0 deletions maestro-cli/src/main/java/maestro/cli/command/CloudCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class CloudCommand : Callable<Int> {
@CommandLine.Parameters(hidden = true, arity = "0..2", description = ["App file and/or Flow file i.e <appFile> <flowFile>"])
private lateinit var files: List<File>

@Option(names = ["--config"], description = ["Optional .yaml configuration file for Flows. If not provided, Maestro will look for a config.yaml file in the root directory."])
private var configFile: File? = null

@Option(names = ["--app-file"], description = ["App binary to run your Flows against"])
private var appFile: File? = null

Expand Down Expand Up @@ -217,6 +220,7 @@ class CloudCommand : Callable<Int> {
input = flowsFile.toPath().toAbsolutePath(),
includeTags = includeTags,
excludeTags = excludeTags,
config = configFile?.toPath()?.toAbsolutePath(),
)
} catch (e: Exception) {
throw CliError("Upload aborted. Received error when evaluating workspace: ${e.message}")
Expand All @@ -225,6 +229,10 @@ class CloudCommand : Callable<Int> {

private fun validateFiles() {

if (configFile != null && configFile?.exists()?.not() == true) {
throw CliError("The config file ${configFile?.absolutePath} does not exist.")
}

// Maintains backwards compatibility for this syntax: maestro cloud <appFile> <workspace>
// App file can be optional now
if (this::files.isInitialized) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class RecordCommand : Callable<Int> {
@CommandLine.Parameters
private lateinit var flowFile: File

@Option(names = ["--config"], description = ["Optional .yaml configuration file for Flows. If not provided, Maestro will look for a config.yaml file in the root directory."])
private var configFile: File? = null

@Option(names = ["-e", "--env"])
private var env: Map<String, String> = emptyMap()

Expand All @@ -77,6 +80,9 @@ class RecordCommand : Callable<Int> {
)
}

if (configFile != null && configFile?.exists()?.not() == true) {
throw CliError("The config file ${configFile?.absolutePath} does not exist.")
}
TestDebugReporter.install(debugOutputPathAsString = debugOutput, printToConsole = parent?.verbose == true)
val path = TestDebugReporter.getDebugOutputPath()

Expand Down
10 changes: 10 additions & 0 deletions maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ class TestCommand : Callable<Int> {
@CommandLine.Parameters
private lateinit var flowFile: File

@Option(
names = ["--config"],
description = ["Optional YAML configuration file for the workspace. If not provided, Maestro will look for a config.yaml file in the workspace's root directory."])
private var configFile: File? = null

@Option(
names = ["-s", "--shards"],
description = ["Number of parallel shards to distribute tests across"],
Expand Down Expand Up @@ -178,11 +183,16 @@ class TestCommand : Callable<Int> {
shardSplit = legacyShardCount
}

if (configFile != null && configFile?.exists()?.not() == true) {
throw CliError("The config file ${configFile?.absolutePath} does not exist.")
}

val executionPlan = try {
WorkspaceExecutionPlanner.plan(
input = flowFile.toPath().toAbsolutePath(),
includeTags = includeTags,
excludeTags = excludeTags,
config = configFile?.toPath()?.toAbsolutePath(),
)
} catch (e: ValidationError) {
throw CliError(e.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import maestro.orchestra.yaml.YamlCommandReader
import org.slf4j.LoggerFactory
import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.absolute
import kotlin.io.path.absolutePathString
import kotlin.io.path.exists
import kotlin.io.path.isRegularFile
Expand All @@ -24,6 +25,7 @@ object WorkspaceExecutionPlanner {
input: Path,
includeTags: List<String>,
excludeTags: List<String>,
config: Path?,
): ExecutionPlan {
logger.info("start planning execution")

Expand Down Expand Up @@ -55,10 +57,13 @@ object WorkspaceExecutionPlanner {
}

// Filter flows based on flows config

val workspaceConfig = findConfigFile(input)
?.let { YamlCommandReader.readWorkspaceConfig(it) }
?: WorkspaceConfig()
val workspaceConfig = if (config != null) {
YamlCommandReader.readWorkspaceConfig(config.absolute())
} else {
findConfigFile(input)
?.let { YamlCommandReader.readWorkspaceConfig(it) }
?: WorkspaceConfig()
}

val globs = workspaceConfig.flows ?: listOf("*")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ internal class WorkspaceExecutionPlannerErrorsTest {
val excludeTags = path.resolve("excludeTags.txt").takeIf { it.isRegularFile() }?.readLines() ?: emptyList()
try {
val inputPath = singleFlowFilePath?.let { workspacePath.resolve(it) } ?: workspacePath
WorkspaceExecutionPlanner.plan(inputPath, includeTags, excludeTags)
WorkspaceExecutionPlanner.plan(
input = inputPath,
includeTags = includeTags,
excludeTags = excludeTags,
config = null,
)
assertWithMessage("No exception was not thrown. Ensure this test case triggers a ValidationError.").fail()
} catch (e: Exception) {
if (e !is ValidationError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal class WorkspaceExecutionPlannerTest {
input = path("/workspaces/000_individual_file/flow.yaml"),
includeTags = listOf(),
excludeTags = listOf(),
config = null,
)

// Then
Expand All @@ -29,6 +30,7 @@ internal class WorkspaceExecutionPlannerTest {
input = path("/workspaces/001_simple"),
includeTags = listOf(),
excludeTags = listOf(),
config = null,
)

// Then
Expand All @@ -45,6 +47,7 @@ internal class WorkspaceExecutionPlannerTest {
input = path("/workspaces/002_subflows"),
includeTags = listOf(),
excludeTags = listOf(),
config = null,
)

// Then
Expand All @@ -61,6 +64,7 @@ internal class WorkspaceExecutionPlannerTest {
input = path("/workspaces/003_include_tags"),
includeTags = listOf("included"),
excludeTags = listOf(),
config = null,
)

// Then
Expand All @@ -76,6 +80,7 @@ internal class WorkspaceExecutionPlannerTest {
input = path("/workspaces/004_exclude_tags"),
includeTags = listOf(),
excludeTags = listOf("excluded"),
config = null,
)

// Then
Expand All @@ -92,6 +97,7 @@ internal class WorkspaceExecutionPlannerTest {
input = path("/workspaces/005_custom_include_pattern"),
includeTags = listOf(),
excludeTags = listOf(),
config = null,
)

// Then
Expand All @@ -108,6 +114,7 @@ internal class WorkspaceExecutionPlannerTest {
input = path("/workspaces/006_include_subfolders"),
includeTags = listOf(),
excludeTags = listOf(),
config = null,
)

// Then
Expand All @@ -126,6 +133,7 @@ internal class WorkspaceExecutionPlannerTest {
input = path("/workspaces/007_empty_config"),
includeTags = listOf(),
excludeTags = listOf(),
config = null,
)

// Then
Expand All @@ -142,6 +150,7 @@ internal class WorkspaceExecutionPlannerTest {
input = path("/workspaces/008_literal_pattern"),
includeTags = listOf(),
excludeTags = listOf(),
config = null,
)

// Then
Expand All @@ -157,6 +166,7 @@ internal class WorkspaceExecutionPlannerTest {
input = path("/workspaces/009_custom_config_fields"),
includeTags = listOf(),
excludeTags = listOf(),
config = null,
)

// Then
Expand All @@ -173,6 +183,7 @@ internal class WorkspaceExecutionPlannerTest {
input = path("/workspaces/010_global_include_tags"),
includeTags = listOf("featureB"),
excludeTags = listOf(),
config = null,
)

// Then
Expand All @@ -190,6 +201,7 @@ internal class WorkspaceExecutionPlannerTest {
input = path("/workspaces/011_global_exclude_tags"),
includeTags = listOf(),
excludeTags = listOf("featureA"),
config = null,
)

// Then
Expand All @@ -207,6 +219,7 @@ internal class WorkspaceExecutionPlannerTest {
input = path("/workspaces/012_local_deterministic_order"),
includeTags = listOf(),
excludeTags = listOf(),
config = null,
)

// Then
Expand All @@ -224,6 +237,7 @@ internal class WorkspaceExecutionPlannerTest {
input = path("/workspaces/013_execution_order"),
includeTags = listOf(),
excludeTags = listOf(),
config = null,
)

// Then
Expand All @@ -240,6 +254,22 @@ internal class WorkspaceExecutionPlannerTest {
).inOrder()
}

@Test
internal fun `014 - Config not null`() {
// When
val plan = WorkspaceExecutionPlanner.plan(
input = path("/workspaces/014_config_not_null"),
includeTags = listOf(),
excludeTags = listOf(),
config = path("/workspaces/014_config_not_null/config/another_config.yaml"),
)

// Then
assertThat(plan.flowsToRun).containsExactly(
path("/workspaces/014_config_not_null/flowA.yaml"),
)
}

private fun path(pathStr: String): Path {
return Paths.get(WorkspaceExecutionPlannerTest::class.java.getResource(pathStr).toURI())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
includeTags:
- included
- excluded
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includeTags:
- included
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
appId: com.example.app
tags:
- included
---
- launchApp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
appId: com.example.app
tags:
- excluded
---
- launchApp

0 comments on commit 2b73223

Please sign in to comment.