.nx-base:
  extends: .with_npm_cache

# Creating template for DTE agents
.dte-agent:
  interruptible: true
  extends: .nx-base
  script:
    - yarn exec nx-cloud start-agent

.run:
  extends: .nx-base
  variables:
    TARGET: "$CI_JOB_NAME"
  script:
    - echo "run ${TARGET} with ${ADDITIONAL_TARGET_OPTIONS:-no additional options}"
    - yarn nx run ${TARGET} ${ADDITIONAL_TARGET_OPTIONS}

.run-many:
  extends: .run
  script:
    - echo "run-many ${TARGET} in parallel ${NX_PARALLEL:-3} with ${ADDITIONAL_TARGET_OPTIONS:-no additional options}"
    - yarn nx run-many --target ${TARGET} --parallel ${NX_PARALLEL:-3} ${ADDITIONAL_TARGET_OPTIONS}
    - NX_CLOUD_DISTRIBUTED_EXECUTION=false yarn nx run workspace:ci-info

.run-many-dte:
  extends: .run-many
  before_script:
    - apk add --no-cache git || apt-get update && apt-get install -y git || true
    - sh ./tools/scripts/install-dependencies.sh
    - yarn exec nx-cloud start-ci-run
  after_script:
    - yarn exec nx-cloud stop-all-agents
