From f65f1261f6829d84cd8644c0f54e78479cff199c Mon Sep 17 00:00:00 2001 From: Thibaut Royer Date: Wed, 17 Apr 2024 18:44:36 +0200 Subject: [PATCH] chore: upgrade to 1.9.0 feat: set run title and description with enterpriseStart, closes HYB-592 feat: allow custom package configuration file path Ref: HYB-592, HYB-596 --- build.sbt | 2 +- .../scala/io/gatling/sbt/GatlingKeys.scala | 2 +- .../settings/gatling/EnterpriseSettings.scala | 2 +- .../gatling/TaskEnterpriseDeploy.scala | 34 ++++++++++++++- .../gatling/TaskEnterpriseStart.scala | 43 ++++++++++++++++--- 5 files changed, 72 insertions(+), 11 deletions(-) diff --git a/build.sbt b/build.sbt index d36fe0d..1fd5d1b 100644 --- a/build.sbt +++ b/build.sbt @@ -9,7 +9,7 @@ githubPath := "gatling/gatling-sbt-plugin" libraryDependencies ++= Seq( "org.scalatest" %% "scalatest" % "3.2.18" % Test, - "io.gatling" % "gatling-enterprise-plugin-commons" % "1.9.0-M17" + "io.gatling" % "gatling-enterprise-plugin-commons" % "1.9.0" ) scriptedLaunchOpts := { diff --git a/src/main/scala/io/gatling/sbt/GatlingKeys.scala b/src/main/scala/io/gatling/sbt/GatlingKeys.scala index 5bff08f..0b278d0 100644 --- a/src/main/scala/io/gatling/sbt/GatlingKeys.scala +++ b/src/main/scala/io/gatling/sbt/GatlingKeys.scala @@ -82,7 +82,7 @@ object GatlingKeys { |""".stripMargin ) - val enterpriseDeploy = taskKey[Unit]("Deploy a package and configured simulations") + val enterpriseDeploy = inputKey[Unit]("Deploy a package and configured simulations") val enterpriseStart = inputKey[Unit](s"""Start a simulation deployed with `enterpriseDeploy`. Require `enterpriseApiToken`. |In batch mode, simulation name is required as first argument. diff --git a/src/main/scala/io/gatling/sbt/settings/gatling/EnterpriseSettings.scala b/src/main/scala/io/gatling/sbt/settings/gatling/EnterpriseSettings.scala index 6c8316b..0b8e838 100644 --- a/src/main/scala/io/gatling/sbt/settings/gatling/EnterpriseSettings.scala +++ b/src/main/scala/io/gatling/sbt/settings/gatling/EnterpriseSettings.scala @@ -54,7 +54,7 @@ object EnterpriseSettings { config / enterpriseUrl := new URL("https://cloud.gatling.io"), config / enterprisePackage := taskPackage.buildEnterprisePackage.value, config / enterpriseUpload := taskUpload.uploadEnterprisePackage.value, - config / enterpriseDeploy := taskDeploy.enterpriseDeploy.value, + config / enterpriseDeploy := taskDeploy.enterpriseDeploy.evaluated, config / enterpriseStart := taskStart.enterpriseSimulationStart.evaluated, config / enterprisePackageId := sys.props.get("gatling.enterprise.packageId").getOrElse(""), config / enterpriseSimulationId := sys.props.get("gatling.enterprise.simulationId").getOrElse(""), diff --git a/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseDeploy.scala b/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseDeploy.scala index 23f52a3..b4c0387 100644 --- a/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseDeploy.scala +++ b/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseDeploy.scala @@ -22,16 +22,46 @@ import io.gatling.plugin.deployment.DeploymentConfiguration import io.gatling.plugin.model._ import io.gatling.sbt.GatlingKeys._ import io.gatling.sbt.settings.gatling.EnterpriseUtils._ +import io.gatling.sbt.settings.gatling.TaskEnterpriseDeploy.CommandArgs.CommandArgsParser import sbt._ import sbt.Keys._ +import sbt.complete.DefaultParsers._ +import sbt.internal.util.complete.Parser + +object TaskEnterpriseDeploy { + object CommandArgs { + private val Default = CommandArgs(customFileName = None) + + private val PackageDescriptorFileNameParser: Parser[CommandArgs => CommandArgs] = + token("--package-descriptor-filename") ~> Space ~> StringBasic + .examples(" (inside .gatling/)") + .map(customFileName => _.copy(customFileName = Some(customFileName))) + + val CommandArgsParser: Parser[CommandArgs] = + (Space ~> PackageDescriptorFileNameParser).*.map { results => + results + .foldLeft(Default) { (current, op) => + op.apply(current) + } + } + } + + final case class CommandArgs(customFileName: Option[String]) +} class TaskEnterpriseDeploy(config: Configuration, enterprisePackage: TaskEnterprisePackage) extends RecoverEnterprisePluginException(config) { - val enterpriseDeploy: InitializeTask[DeploymentInfo] = Def.task { + val enterpriseDeploy: InitializeInputTask[DeploymentInfo] = Def.inputTaskDyn { + val commandArgs = CommandArgsParser.parsed + + enterpriseDeployTask(commandArgs.customFileName) + } + + def enterpriseDeployTask(customFileName: Option[String]): InitializeTask[DeploymentInfo] = Def.task { val logger = streams.value.log val enterprisePlugin = EnterprisePluginTask.batchEnterprisePluginTask(config).value val packageFile = enterprisePackage.buildEnterprisePackage.value - val descriptorFile = DeploymentConfiguration.fromBaseDirectory((config / baseDirectory).value) + val descriptorFile = DeploymentConfiguration.fromBaseDirectory((config / baseDirectory).value, customFileName.orNull) val artifactId = (config / name).value val controlPlaneUrl = (config / enterpriseControlPlaneUrl).value diff --git a/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseStart.scala b/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseStart.scala index 445617c..2c9ed41 100644 --- a/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseStart.scala +++ b/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseStart.scala @@ -19,7 +19,7 @@ package io.gatling.sbt.settings.gatling import scala.util._ import io.gatling.plugin.EnterprisePlugin -import io.gatling.plugin.model.RunSummary +import io.gatling.plugin.model._ import io.gatling.sbt.GatlingKeys._ import io.gatling.sbt.settings.gatling.EnterpriseUtils.InitializeInputTask import io.gatling.sbt.settings.gatling.TaskEnterpriseStart.CommandArgs.CommandArgsParser @@ -32,7 +32,13 @@ import sbt.internal.util.complete.Parser object TaskEnterpriseStart { object CommandArgs { - private val Default = CommandArgs(simulationName = None, requireBatchMode = false) + private val Default = CommandArgs( + simulationName = None, + requireBatchMode = false, + runTitle = None, + runDescription = None, + customFileName = None + ) private val SimulationNameParser: Parser[String] = StringBasic.examples("") @@ -42,8 +48,26 @@ object TaskEnterpriseStart { private val NoBatchModeParser: Parser[CommandArgs => CommandArgs] = token("--no-batch-mode" ^^^ (_.copy(requireBatchMode = System.console() == null))) + private val RunTitleParser: Parser[CommandArgs => CommandArgs] = + token("--run-title") ~> Space ~> StringBasic + .examples("") + .map(title => _.copy(runTitle = Some(title))) + + private val RunDescriptionParser: Parser[CommandArgs => CommandArgs] = + token("--run-description") ~> Space ~> StringBasic + .examples("") + .map(description => _.copy(runDescription = Some(description))) + + private val PackageDescriptorFileNameParser: Parser[CommandArgs => CommandArgs] = + token("--package-descriptor-filename") ~> Space ~> StringBasic + .examples(" (inside .gatling/)") + .map(customFileName => _.copy(customFileName = Some(customFileName))) + val CommandArgsParser: Parser[CommandArgs] = - ((Space ~> (NoBatchModeParser | RequireBatchModeParser)).* ~ (Space ~> SimulationNameParser).?) + ( + (Space ~> (NoBatchModeParser | RequireBatchModeParser | RunTitleParser | RunDescriptionParser | PackageDescriptorFileNameParser)).* + ~ (Space ~> SimulationNameParser).? + ) .map { case (results, simulationName) => results .foldLeft(Default) { (current, op) => @@ -52,7 +76,13 @@ object TaskEnterpriseStart { .copy(simulationName = simulationName) } } - final case class CommandArgs(simulationName: Option[String], requireBatchMode: Boolean) + final case class CommandArgs( + simulationName: Option[String], + requireBatchMode: Boolean, + runTitle: Option[String], + runDescription: Option[String], + customFileName: Option[String] + ) } class TaskEnterpriseStart(config: Configuration, taskEnterpriseDeploy: TaskEnterpriseDeploy) extends RecoverEnterprisePluginException(config) { @@ -62,10 +92,11 @@ class TaskEnterpriseStart(config: Configuration, taskEnterpriseDeploy: TaskEnter Def.task { val logger = streams.value.log val enterprisePlugin = EnterprisePluginTask.enterprisePluginTask(config, commandArgs.requireBatchMode).value - val deploymentInfo = taskEnterpriseDeploy.enterpriseDeploy.value + val deploymentInfo = taskEnterpriseDeploy.enterpriseDeployTask(commandArgs.customFileName).value val waitForRunEndSetting = waitForRunEnd.value + val runComment = new RunComment(commandArgs.runTitle.orNull, commandArgs.runDescription.orNull) - val runSummary = enterprisePlugin.startSimulation(commandArgs.simulationName.orNull, deploymentInfo) + val runSummary = enterprisePlugin.startSimulation(commandArgs.simulationName.orNull, deploymentInfo, runComment) logStartResult(logger, runSummary, waitForRunEndSetting, baseUrl = (config / enterpriseUrl).value)