dist: trusty
sudo: false

language: node_js
cache: npm

addons:
  ssh_known_hosts: ssh-oncletom.alwaysdata.net
  apt:
    packages:
      - libxml2-utils

node_js: v10
env:
- npm_version=6
  DEBUG=tape-spawn
  SHARP_IGNORE_GLOBAL_LIBVIPS=1

# before_install:
# - npm i -g npm@${npm_version}
before_install:
- npm config --global set prefer-offline true

install:
- npm ci
- npm run install:all

script:
- ./bin/cli.js --help
- npm test
- make build-html
- make build-odt
- xmllint --noout dist/book.fodt 2>&1

before_deploy:
- openssl aes-256-cbc -K $encrypted_5256f0527d52_key -iv $encrypted_5256f0527d52_iv -in deploykey_ed25519.enc -out /tmp/deploykey -d
- eval "$(ssh-agent -s)" && chmod 600 /tmp/deploykey && ssh-add /tmp/deploykey
- git-lfs pull
- make build-docbook

deploy:
  - provider: script
    skip-cleanup: true
    local-dir: dist
    script: rsync -r --delete-after --quiet $TRAVIS_BUILD_DIR/dist/ oncletom@ssh-oncletom.alwaysdata.net:~/node.js/v1/
    on:
      branch: master
  - provider: script
    skip-cleanup: true
    local-dir: dist
    script: rsync -r --delete-after --quiet $TRAVIS_BUILD_DIR/dist/ oncletom@ssh-oncletom.alwaysdata.net:~/node.js/v2/
    on:
      branch: v2
  - provider: releases
    prerelease: false
    skip-cleanup: true
    api-key: "$GH_TOKEN"
    file-glob: true
    file: dist/book.*
    on:
      tags: true
      all-branches: true
      condition: $TRAVIS_BRANCH =~ ^v1.
  - provider: releases
    prerelease: true
    skip-cleanup: true
    api-key: "$GH_TOKEN"
    file-glob: true
    file: dist/book.*
    on:
      tags: true
      all-branches: true
      condition: $TRAVIS_BRANCH =~ ^v2.
  - provider: npm
    tag: latest
    skip-cleanup: true
    on:
      tags: true
      all-branches: true
      condition: $TRAVIS_BRANCH =~ ^v1.
    email: "hi@oncletom.io"
    api-key: "$NPM_TOKEN"
  - provider: npm
    tag: next
    skip-cleanup: true
    on:
      tags: true
      all-branches: true
      condition: $TRAVIS_BRANCH =~ ^v2.
    email: "hi@oncletom.io"
    api-key: "$NPM_TOKEN"
