language: node_js
cache:
  directories:
    - node_modules
node_js:
- '6.9'
services:
  - docker
install: "npm i && npm update"
branches:
  only:
  - master
  - /^v\d+\.\d+(\.\d+)?(-\S*)?$/
env:
  - DOCKER_IMAGE_NAME=swaggerapi/swagger-editor
deploy:
  - provider: npm
    email: apiteam@swagger.io
    skip_cleanup: true
    api_key:
      secure: "Fh8+qozAjs8YxWYntPN/xO3UNpQ+avEzOz4ULzn5lEXbcQgV/v1/e6ABk06HZ9Go9rigYpR2LnxLfP7Tp6ZC4dFE9GR0ota5rkrXlCJi6QktDccyKEvai2cayDW/3nFv4A7yM1xWgTMlQP5cVfZVEWopscWKCIdnZ9QvhTW0TKY="
    on:
      tags: true
      repo: swagger-api/swagger-editor
      node: '6.9'
  - provider: script
    skip_cleanup: true
    script: swagger-editor-dist-package/deploy.sh
    on:
      tags: true
      repo: swagger-api/swagger-editor
      node: '6.9'
  - provider: script
    skip_cleanup: true
    script: "sh build-tools/deploy-docker-hub-tag.sh"
    on:
      tags: true
      repo: swagger-api/swagger-editor
      node: '6.9'
after_success:
  # artifacts from this `npm run build` are used in the deploy step as well
  - |
    if [ $TRAVIS_PULL_REQUEST == "false" ]; then
      npm run build
      if [ $DOCKER_HUB_USERNAME ]; then
          docker login --username=$DOCKER_HUB_USERNAME --password=$DOCKER_HUB_PASSWORD;

          DOCKER_IMAGE_TAG=unstable;

          docker build -t $DOCKER_IMAGE_NAME .;
          docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG;
          docker push $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG;
        fi;
    fi;
