image: node:alpine # Much smaller than other variants, faster and more resource effective

cache:
  key: "${CI_COMMIT_REF_SLUG}" # Branch-specific cache keys to have separate caches across branches.
  paths:
    - node_modules/
    - build/

stages:
  - install
  - build
  - test
  - lint

install_dependencies:
  stage: install
  script:
    - npm ci
  cache:
    key: ${CI_COMMIT_REF_SLUG}
    paths:
        - node_modules/
    policy: push

build_project:
  stage: build
  script:
    - npm ci
    - npm run build
  dependencies:
    - install_dependencies
  cache:
    key: "${CI_COMMIT_REF_SLUG}"
    paths:
      - node_modules/
    policy: pull

vitest_unit-tests:
  stage: test
  script:
    - npm ci
    - npm run test:unit
  dependencies:
    - install_dependencies
  cache:
    key: ${CI_COMMIT_REF_SLUG}
    paths:
        - node_modules/
    policy: pull

eslint_run-lint:
  stage: lint
  script:
    - npm ci
    - npm run lint
  dependencies:
    - install_dependencies
  cache:
    key: ${CI_COMMIT_REF_SLUG}
    paths:
        - node_modules/
    policy: pull
  allow_failure: true