image: ${CI_REGISTRY}/${CI_IMAGE}

stages:
  - install
  - test
  - build
  - release

cache:
  paths:
    - node_modules/

install_dependencies:
  stage: install
  script:
    - npm install
  artifacts:
    paths:
      - node_modules/
  only:
    - main

lint_test:
  stage: test
  script:
    - npm run lint
  dependencies:
    - install_dependencies
  only:
    - main

unit_test:
  stage: test
  script:
    - npm run test
  dependencies:
    - install_dependencies
  only:
    - main

build:
  stage: build
  script:
    - npm run build
  dependencies:
    - install_dependencies
  artifacts:
    paths:
      - dist/
  only:
    - main

release:
  stage: release
  script:
    - npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
    - npm publish --access public
  only:
    - main
  variables:
    NPM_TOKEN: $NPM_TOKEN