content: [config]
  default_to_workspace = false
  
  [env]
  # Determines the version of OpenSearch docker container used
  STACK_VERSION = { value = "latest", condition = { env_not_set = ["STACK_VERSION"] } }
  # Set publish flags to dry-run by default, to force user to explicitly define for publishing
  CARGO_MAKE_CARGO_PUBLISH_FLAGS = "--dry-run"
  # RUST_BACKTRACE is set to "full" in cargo make's builtin makefiles/stable.toml
  RUST_BACKTRACE = { value = "0", condition = { env_not_set = ["RUST_BACKTRACE"] } }
  SECURE_INTEGRATION = { value = "true", condition = { env_not_set = ["SECURE_INTEGRATION"] } }
  OPENSEARCH_PROTOCOL = { source = "${SECURE_INTEGRATION}", default_value = "https", mapping = { false = "http", true = "https" } }
  OPENSEARCH_URL = { value = "${OPENSEARCH_PROTOCOL}://localhost:9200", condition = { env_not_set = ["OPENSEARCH_URL"] } }
  
  ######################
  # OpenSearch Helpers #
  ######################
  
  [tasks.generate-certs]
  category = "OpenSearch"
  description = "Generates SSL certificates used for integration tests"
  command = "bash"
  args = ["./.ci/generate-certs.sh"]
  
  [tasks.run-opensearch]
  category = "OpenSearch"
  private = true
  condition = { env_set = [ "STACK_VERSION"], env_false = ["CARGO_MAKE_CI"] }
  command = "bash"
  args = ["./.ci/run-opensearch.sh"]
  
  [tasks.run-opensearch.windows]
  script_runner = "cmd"
  script = ['''
  bash -c "STACK_VERSION=%STACK_VERSION% DETACH=%DETACH% CLEANUP=%CLEANUP% bash .ci/run-opensearch.sh"
  ''']
  
  [tasks.start-opensearch]
  extend = "run-opensearch"
  private = false
  description = "Starts OpenSearch docker container with the given version and distribution"
  env = { CLEANUP = false, DETACH = true }
  
  [tasks.stop-opensearch]
  extend = "run-opensearch"
  private = false
  description = "Stops OpenSearch docker container, if running"
  env = { CLEANUP = true, DETACH = false }
  
  ###################
  # Code Generation #
  ###################
  
  [tasks.generate-yaml-tests-inner]
  category = "OpenSearch"
  private = true
  command = "cargo"
  args = ["run", "-p", "yaml_test_runner", "--", "-u", "${OPENSEARCH_URL}"]
  
  [tasks.generate-yaml-tests]
  category = "OpenSearch"
  description = "Generates OpenSearch client tests from YAML tests"
  dependencies = ["start-opensearch", "generate-yaml-tests-inner", "format"]
  run_task = "stop-opensearch"
  
  [tasks.generate-api-inner]
  category = "OpenSearch"
  private = true
  command = "cargo"
  args = ["run", "-p", "api_generator"]
  
  [tasks.generate-api]
  category = "OpenSearch"
  description = "Generates OpenSearch client from REST API specs"
  dependencies = ["generate-api-inner"]
  run_task = "format"
  
  ################
  # Test Helpers #
  ################
  
  [tasks.create-test-results-dir]
  category = "OpenSearch"
  private = true
  condition = { env_true = [ "CARGO_MAKE_CI" ] }
  script = ["[ -d test_results ] || mkdir -p test_results"]
  
  [tasks.set-coverage-vars]
  description = "Set environment variables to enable coverage data"
  private = true
  condition = { env_true = [ "CARGO_MAKE_CI" ] }
  env = { RUSTFLAGS = "-C instrument-coverage", LLVM_PROFILE_FILE = "${CARGO_MAKE_WORKING_DIRECTORY}/test_results/opensearch-%m.profraw" }
  
  [tasks.convert-coverage-data]
  description = "Convert coverage data to lcov format"
  private = true
  condition = { env_true = [ "CARGO_MAKE_CI" ] }
  command = "grcov"
  args = ["./test_results", "-s", ".", "--binary-path", "./target/debug", "-t", "lcov", "--branch", "--ignore-not-existing", "--llvm", "-o", "./test_results/opensearch.lcov"]
  
  #########
  # Tests #
  #########
  
  [tasks.test-yaml-inner]
  category = "OpenSearch"
  private = true
  command = "cargo"
  args = ["test", "-p", "yaml_test_runner", "--", "--test-threads", "1"]
  
  [tasks.test-yaml]
  category = "OpenSearch"
  description = "Generates and runs yaml_test_runner package tests against a given OpenSearch version"
  condition = { env_set = [ "STACK_VERSION"] }
  dependencies = [
      "set-coverage-vars", 
      "create-test-results-dir", 
      "start-opensearch", 
      "generate-yaml-tests-inner", 
      "format",
      "test-yaml-inner", 
      "convert-coverage-data"
  ]
  run_task = "stop-opensearch"
  
  [tasks.test-inner]
  category = "OpenSearch"
  private = true
  command = "cargo"
  args = [
      "test", 
      "--no-fail-fast", 
      "--workspace",
      "@@split(CARGO_MAKE_TASK_ARGS,;)"
  ]
  
  [tasks.test]
  clear = true
  category = "OpenSearch"
  description = "Runs all tests (except YAML) against a given OpenSearch version"
  dependencies = [
      "set-coverage-vars", 
      "create-test-results-dir", 
      "start-opensearch", 
      "test-inner",
      "convert-coverage-data"
  ]
  run_task = "stop-opensearch"
  
  [tasks.unittest-inner]
  category = "OpenSearch"
  private = true
  command = "cargo"
  args = ["test", "--lib", "--bins"]
  
  [tasks.unittest]
  category = "OpenSearch"
  description = "Runs workspace unit tests"
  dependencies = ["set-coverage-vars", "create-test-results-dir", "unittest-inner"]
  run_task = "convert-coverage-data"
  
  #################
  # Documentation #
  #################
  
  [tasks.docs]
  description = "Generate OpenSearch client documentation and opens in browser"
  clear = true
  category = "OpenSearch"
  command = "cargo"
  args = ["doc", "-p", "opensearch", "--no-deps", "--open", "--all-features"]
  
  ##############
  # Publishing #
  ##############
  
  [tasks.generate-release-notes]
  category = "OpenSearch"
  description = """
  Generates release notes for OpenSearch client using a common release notes generator docker image.
  Assumes the clients-team repo is checked out as a sibling directory of opensearch-rs
  """
  condition = { env_set = ["OLD_VERSION", "NEW_VERSION"], files_exist = [ "${CARGO_MAKE_WORKING_DIRECTORY}/../clients-team/scripts/release-notes-generator/Dockerfile" ] }
  script_runner = "@shell"
  script = [
  """
  cd ./../clients-team/scripts/release-notes-generator
  docker build --file ./Dockerfile --tag clients-team/release_notes_generator .
  docker run -v "${CARGO_MAKE_WORKING_DIRECTORY}/.ci/release/config.yml:/usr/src/release_notes_generator/config.yml" --rm clients-team/release_notes_generator -o ${OLD_VERSION} -n ${NEW_VERSION}
  """
  ]
  
  [tasks.publish-opensearch]
  description = "Runs the cargo publish command."
  category = "OpenSearch"
  private = true
  script_runner = "@duckscript"
  script = [
  """
  cd opensearch
  echo "publishing opensearch crate: cargo publish %{CARGO_MAKE_CARGO_PUBLISH_FLAGS}"
  if is_empty %{CARGO_MAKE_CARGO_PUBLISH_FLAGS}
      exec cargo publish
  else
      exec cargo publish %{CARGO_MAKE_CARGO_PUBLISH_FLAGS}
  end
  """
  ]
  
  [tasks.publish]
  clear = true
  dependencies = [ "publish-opensearch" ]
  run_task = "generate-release-notes"
  
  [tasks.package]
  clear = true
  description = "Runs the cargo package command for opensearch crate."
  category = "OpenSearch"
  script_runner = "@duckscript"
  script = [
  """
  cd opensearch
  echo "packaging opensearch crate: cargo package %{CARGO_MAKE_CARGO_PACKAGE_FLAGS}"
  if is_empty %{CARGO_MAKE_CARGO_PACKAGE_FLAGS}
      exec cargo package
  else
      exec cargo package %{CARGO_MAKE_CARGO_PACKAGE_FLAGS}
  end
  """
  ]
  
  [tasks.update-version]
  description = "Updates the package versions and version in docs"
  command = "bash"
  args = ["./.ci/update-version.sh", "@@split(CARGO_MAKE_TASK_ARGS,;)"]
  
  [tasks.default]
  clear = true
  script_runner = "@duckscript"
  script = ['''
      echo
      echo Main tasks:
      echo - generate-api: Generates OpenSearch client from REST API specs
      echo - start-opensearch: Starts OpenSearch docker container with the given version and distribution
      echo - stop-opensearch: Stops OpenSearch docker container, if running
      echo
      echo - test-yaml: Generates and runs yaml_test_runner package platinum/free tests against a given OpenSearch version
      echo - test-generator: Generates and runs api_generator package tests
      echo - test: Runs opensearch package tests against a given OpenSearch version
      echo
      echo - update-version: Updates the version
      echo       pass NEW_VERSION environment variable for version
      echo - generate-release-notes: Generates release notes for opensearch crate.
      echo       pass OLD_VERSION and NEW_VERSION environment variables to match release version GitHub labels e.g. v7.9.0-alpha.1
      echo - package: Packages the opensearch crate.
      echo       package flags can be overridden with CARGO_MAKE_CARGO_PACKAGE_FLAGS environment variable
      echo - publish: Publishes the opensearch crate.
      echo       By default, peforms a dry run by passing --dry-run, but publish flags can be overridden with CARGO_MAKE_CARGO_PUBLISH_FLAGS environment variable
      echo
      echo Most tasks use these environment variables:
      echo - STACK_VERSION (default '${STACK_VERSION}'): the version of OpenSearch
      echo - CI (default not set): set when running on CI to determine whether to start OpenSearch and format test output as JSON
      echo
      echo Run 'cargo make --list-all-steps' for a complete list of available tasks.
      echo
  ''']
  