include:
  - project: sre/ci-building-blocks
    file: nodejs.yml
    ref: 3.4.0

unit tests:
  extends: .unit tests
  timeout: 10 minutes
  tags:
    - tiny-hetzner

integration tests:
  extends: unit tests
  services:
    - redis:latest
  script:
    - yarn --non-interactive --no-progress -s
    - yarn integration --ci --coverage

deploy preview with prefix:
  extends: .auto-deploy-preview-chart
  script:
    - !reference [.setup-k8s, script]
    - !reference [.customize-k8s, script]
    - !reference [.create-image-pull-secrets, script]
    - envsubst < .gitlab/preview-prefix/values-template.yaml > tmp-values.yaml
    - envsubst < .gitlab/preview-prefix/kubernetes-resources.yaml > tmp-resources.yaml
    - !reference [.login-registry-ro, script]
    - kubectl apply -f tmp-resources.yaml
    - helm dep up helm/core-ui-middleware
    - helm upgrade -i preview-prefix helm/core-ui-middleware -f tmp-values.yaml --wait --timeout=$ROLLOUT_TIMEOUT
  environment: null

.smoketest-rules:
  rules:
    - if: $CI_COMMIT_REF_NAME =~ /^(\d+\.\d+\.\d+)$/
      when: never
    - if: $CI_COMMIT_REF_NAME =~ /^(main|master)$/
      variables:
        TAG_NAME: "latest"
    - if: $CI_COMMIT_REF_NAME
      variables:
        TAG_NAME: "$CI_COMMIT_REF_SLUG"

ui smoketests:
  image: registry.gitlab.open-xchange.com/frontend/ui/e2e:latest
  extends:
    - .e2e-codeceptjs-preview
    - .smoketest-rules
  variables:
    PROVISIONING_URL: https://appsuite-main.dev.oxui.de/
  tags:
    - e2e-hetzner
  timeout: 15 minutes
  before_script:
    - !reference [.e2e-codeceptjs-preview, before_script]
    - unset SUITE_SERVICE_URL
    - export E2E_ADMIN_PW=$ADMIN_PW
    - export LAUNCH_URL=https://$PREVIEW_APP_NAME.dev.oxui.de/
    - echo "LAUNCH_URL=$LAUNCH_URL"
  script:
    - yarn e2e-rerun @smoketest

ui smoketests with prefix:
  image: registry.gitlab.open-xchange.com/frontend/ui/e2e:latest
  extends:
    - .e2e-codeceptjs-preview
    - .smoketest-rules
  variables:
    PROVISIONING_URL: https://appsuite-main.dev.oxui.de/
  tags:
    - e2e-hetzner
  timeout: 15 minutes
  before_script:
    - !reference [.e2e-codeceptjs-preview, before_script]
    - unset SUITE_SERVICE_URL
    - export E2E_ADMIN_PW=$ADMIN_PW
    - export LAUNCH_URL=https://$PREVIEW_APP_NAME-prefix.dev.oxui.de/appsuite/
    - echo "LAUNCH_URL=$LAUNCH_URL"
  script:
    - yarn e2e-rerun @smoketest
