Skip to content

Commit

Permalink
chore: upgrade to 1.9.0
Browse files Browse the repository at this point in the history
feat: set run title and description with enterpriseStart, closes HYB-592
feat: allow custom package configuration file path

Ref: HYB-592, HYB-596
  • Loading branch information
Obero committed Apr 19, 2024
1 parent cf34935 commit f65f126
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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 := {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/io/gatling/sbt/GatlingKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("<package descriptor filename> (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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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("<simulation name>")

Expand All @@ -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("<run title>")
.map(title => _.copy(runTitle = Some(title)))

private val RunDescriptionParser: Parser[CommandArgs => CommandArgs] =
token("--run-description") ~> Space ~> StringBasic
.examples("<run description>")
.map(description => _.copy(runDescription = Some(description)))

private val PackageDescriptorFileNameParser: Parser[CommandArgs => CommandArgs] =
token("--package-descriptor-filename") ~> Space ~> StringBasic
.examples("<package descriptor filename> (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) =>
Expand All @@ -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) {
Expand All @@ -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)

Expand Down

0 comments on commit f65f126

Please sign in to comment.