# This CI jobs are copied from libdatadog-build one-pipeline.yml gitlab template.
# This URL is available in the dd-gitlab/publish-content-addresable-templates job whenever
# a change is made on the one-pipeline template.
variables:
  SCRIPTS_BASE_URL: https://gitlab-templates.ddbuild.io/libdatadog/one-pipeline/ca/ef1b27c2b0cdbbfb25d185344cdb7aa6bb4feb905cb2a77fa1a5a5340b570004/scripts/

.download-scripts-from-template: &download-scripts-from-template
  - mkdir -p scripts
  - |
    for script_file in "config-inversion-local-validation.py" "config-inversion-update-supported-range.py"
    do
      curl --location --fail --show-error --output "scripts/${script_file}" "${SCRIPTS_BASE_URL}/${script_file}"
      chmod +x scripts/$script_file
    done

.validate_supported_configurations_v2_local_file:
  allow_failure: false
  rules:
    - when: on_success
  variables:
    LOCAL_JSON_PATH: ""
    BACKFILLED: ""
  before_script:
    - *download-scripts-from-template
  script:
    - scripts/config-inversion-local-validation.py "$LOCAL_JSON_PATH" "$BACKFILLED"

.update_central_configurations_version_range_v2:
  allow_failure: false
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v?[0-9]+\.[0-9]+\.[0-9]+$/'
      when: on_success
  variables:
    LOCAL_JSON_PATH: ""
    LANGUAGE_NAME: ""
    MULTIPLE_RELEASE_LINES: "false" # expect "true" or "false" as a value to determine if a new "branch" identifier is needed to differentiate between multiple release lines
  before_script:
    - *download-scripts-from-template
    - export FP_API_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.$CI_PROJECT_NAME.FP_API_KEY --with-decryption --query "Parameter.Value" --out text)
  script:
    - scripts/config-inversion-update-supported-range.py "$LOCAL_JSON_PATH" "$LANGUAGE_NAME" "$MULTIPLE_RELEASE_LINES"