language: node_js
node_js:
  - "10"

os:
  - linux

cache:
  directories:
    - node_modules

stages:
  - test
  - pack
  - name: deploy
    if: (type = push) AND branch =~ ^(master|v\d+\.\d+)$

install:
  - npm install


jobs:
  include:
    - stage: test
      script:
        - node --version
        - npm --version
        - echo "Testing Started ..."
        - npm test
        - echo "Testing Finished"

    - stage: pack
      script:
        - echo "NPM Pack Testing Started ..."
        - npm version
        - npm run test:pack
        - echo "NPM Pack Testing Finished."

    - stage: deploy
      script:
        - echo "NPM Deploying Started ..."
        - npm version
        - if ./scripts/development-release.ts; then ./scripts/package-publish-config-tag-next.ts; fi
        - npm run dist
        - echo "NPM Building Finished."

      deploy:
        provider: npm
        email: zixia@zixia.net
        api_key: "$NPM_TOKEN"
        skip_cleanup: true
        on:
          all_branches: true

notifications:
  webhooks:
    urls:
      - https://webhooks.gitter.im/e/41a19fbf1d54a04e5217
    on_success: always  # options: [always|never|change] default: always
    on_failure: always  # options: [always|never|change] default: always
    on_start: never     # options: [always|never|change] default: always
  email:
    on_success: change
    on_failure: change
