.setup:
  stage: .pre
  tags:
    - setup
  image: node:${NODE_VERSION}-alpine
  script: sh ./tools/scripts/install-dependencies.sh
  cache:
    key:
      files:
        - yarn.lock
    paths:
      - "**/node_modules/**"
      - .yarn/cache
  rules:
    - if: '$SKIP_SETUP == "true"'
      when: never
    - if: '$CI_COMMIT_REF_PROTECTED == "true" && $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+/'
      when: never
    - if: '$CI_MERGE_REQUEST_EVENT_TYPE == "merge_train"'
      when: never
    - if: '$CI_COMMIT_REF_NAME =~ /^renovate\//'
      when: always
    - if: '$ENFORCE_SETUP == "true"'
      when: always
    - if: '$CI_COMMIT_MESSAGE =~ /\[setup\]/'
      when: always
    - changes:
        - yarn.lock
      when: always

.with_npm_cache:
  image: node:${NODE_VERSION}-alpine
  needs:
    - job: setup
      artifacts: false
      optional: true
  cache:
    key:
      files:
        - yarn.lock
    paths:
      - "**/node_modules/**"
      - .yarn/cache
    policy: pull
  before_script:
    - apk add --no-cache git || apt-get update && apt-get install -y git || true
    - sh ./tools/scripts/install-dependencies.sh
