default:
  before_script:
    - set -e
    # DANGER don't use `set -x` or print the environment via e.g. `env` in pipeline runs, this might leak credentials (has leaked them)
  tags:
    - 1cpu-4gb
  image: 'europe-north1-docker.pkg.dev/holi-shared/docker/holi-docker/holi-k6-builder'

linting:
  stage: test
  image: 'europe-north1-docker.pkg.dev/holi-shared/docker-hub-remote/node:22-slim'
  script:
    - corepack enable
    - yarn
    - yarn lint
  interruptible: true

execute_manual:
  stage: 'deploy'
  when: manual
  script:
    - k6 run --out 'web-dashboard=export=results.html' --out json=results.json scripts/main.js
  artifacts:
    when: always
    paths:
      - results.json
  tags:
    - 4cpu-4gb # more cpu, quicker testing

execute_manual_production:
  stage: 'deploy'
  when: manual
  script:
    - PRODUCTION=1 k6 run --out json=results.json scripts/main.js
  artifacts:
    paths:
      - results.json
  tags:
    - 4cpu-4gb # more cpu, quicker testing

execute-performance_manual:
  stage: 'deploy'
  when: manual
  script:
    - ./performance-test.sh
  artifacts:
    when: always
    paths:
      - out/

execute:
  stage: 'deploy'
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TYPE == "loadtest"
  script:
    - k6 run --out json=results.json scripts/main.js
  artifacts:
    when: always
    paths:
      - results.json
  tags:
    - 4cpu-4gb # more cpu, quicker testing

execute-performance:
  stage: 'deploy'
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TYPE == "performancetest"
  script:
    - ./performance-test.sh
  artifacts:
    when: always
    paths:
      - out/