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

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
  artifacts:
    name: "Build project ${CI_COMMIT_REF_NAME}-${CI_JOB_ID}"
    paths:
        - build/
    expire_in: 1 day

vitest_unit-tests:
  stage: test
  script:
    - npm run test:unit