language: node_js
node_js: 
  - "14"
  - "16"
  - "18"

cache:
  directories:
    - node_modules
  yarn: true

install:
  - yarn

stages:
  - test
  - build
  - deploy

jobs:
  include:
    - stage: test
      script:
        - yarn lint
        - yarn test
    
    - stage: build
      script:
        - yarn build
    
    - stage: deploy
      if: tag IS present
      script:
        - yarn build
      deploy:
        provider: npm
        email: "jianguo@nutpi.net"
        api_key: "${NPM_TOKEN}"
        skip_cleanup: true
        on:
          tags: true
          branch: main
branches:
  only:
    - main