# Pipeline structure:
#
# 1/ Tests: Run unit tests, coverage analysis and pylint on
#       - Linux, Python 3.5
#       - Linux, Python 3.6
#       - Linux, Python 3.7
#       - Linux, Python 3.8-dev
#       - macOS, Python 3.6
#
# 2/ Artifact deployment:
#     - For tags x.y.z:
#         - Upload Python package to https://pypi.org/project/termtosvg
#         - Upload website to gh-pages branch on GitHub
#
#     - For other tags:
#         - Upload Python package to https://test.pypi.org/project/termtosvg
#         - Upload website to gh-pages-staging branch on GitHub
#
#     For all tags, add manual pages to the corresponding GitHub release
#     (https://github.com/nbedos/termtosvg/releases)

language: python
jobs:
  allow_failures:
  - python: 3.8-dev
  include:
  - stage: Test
    python: 3.5
    install:
    - make install
    script:
    - make tests

  - stage: Test
    python: 3.6
    install:
    - make install
    script:
    - make tests

  - stage: Test
    python: 3.7
    dist: xenial
    sudo: true
    install:
    - make install
    script:
    - make tests

  - stage: Test
    python: 3.8-dev
    dist: xenial
    sudo: true
    install:
    - make install
    script:
    - make tests

  - stage: Test
    os: osx
    language: generic
    install:
    - make -e install
    script:
    - make -e tests
    env:
    - PIP=pip3
    - PYTHON=python3

  - stage: Build and deploy
    name: Build and deploy Python package (production)
    if: tag =~ ^[0-9]+\.[0-9]+\.[0-9]+$
    python: 3.6
    script:
    - make man
    addons:
      apt_packages:
      - pandoc
    deploy:
    - provider: releases
      skip_cleanup: true
      api_key: "$GITHUB_TOKEN"
      name: $TRAVIS_TAG
      file_glob: true
      file: man_*.tar.gz
      draft: true
      on:
        tags: true
    - provider: pypi
      user: nbedos
      password:
        secure: qJ+wi2PwEDeiJHhRie7FgxoZcfFBGxogGAEXT0SCfGpyLKe2RHmrUm9endsWm7b7fXS4Cc5sR/wJxeH1nrwawC6HAcFt4VAP3rKloXpxTNKDgi1Rqv/XVIE/FQu3JPoS7YS1tx/bEvX3R22s0e8til82aK9IIutlsIhps7kZi/HXNI64gF54AjnO939bNWTJIU7dQ4S7PuBLdv3mqbWJtA0ix0nzH3c1KbxfMCPt+ogcPBumP/Pm7Jwr97WWedvFXm6xHYOeBYdlMIlxCyRURGPwD1at/ArEYMsmHbq530ocfnIxqyy2/E+tpOF8T6UfS22O3KsQX+9LSbwhvVTWabzMQx/pvlFBIEG3zQDjzNwJPn3o8JmAtyZwujl5bZx9tKpmoU0UovquyAVr0d5ETS6X3gwWlhvHsZ6fJLIhWAlwskWZE0U1x1H44gVj8FgH6iUEsYzEw1+QSywA+5B2WkHWRp0eVnpHAnC74cnPNEgEEIj6KYbaKsR9T8OS1Ut0a254RKzd1XvIFF4p8NIdEc/9YBziEouSsO+SrzKyUDmFgqKLBXyU6gIPXzGO29z+0BHskhDA8kHIUiC6lsEFedE+oWT2MgcsiXVctluGqQ7yGo0yaKPkW88syJnYm7G4nQs3+xZ2VW8hgGpU/tibOHuUezTqdIga2m58c6cbKaE=
      skip_cleanup: true
      skip_existing: true
      distributions: "sdist bdist_wheel"
      on:
        tags: true

  - stage: Build and deploy
    name: Build and deploy Python package (staging)
    if: tag IS present AND ( NOT tag =~ ^[0-9]+\.[0-9]+\.[0-9]+$ )
    python: 3.6
    script:
    - make man
    addons:
      apt_packages:
      - pandoc
    deploy:
    - provider: releases
      skip_cleanup: true
      api_key: "$GITHUB_TOKEN"
      name: $TRAVIS_TAG
      file_glob: true
      file: man_*.tar.gz
      draft: true
      on:
        tags: true
    - provider: pypi
      user: nbedos
      password:
        secure: uQm7cTyqbLLQwrKw2mzFLN3seGqeaTQxtB7BWO2JElR/NM+XUThGljIzy/WZ9E2YUTylR3x3Rr+EwEooergS+BaSVEnx0Zr27NZ6tdCPPkVXoPUiQXqy1c7XTEJsaTQ1y/LRu3jZPzO8p9J9ierBGipHvEgNN0cy+g7u+tZ29h7IDhLhFeaDyK8/ZIyxhj4weU0xP+LWQX2FsBQahK0n3qN/Jg0sB0ja2ffbga6QQNFwQ1/088UFuW8L8QmfefUDMzWhtIjiVJAXs3WH7QF/t0DHIjyNfQvHJL9Aoc8bnnmGxhlQISIo0lJChVQf4lEPuQQxhEfhq1jLQt/R1zINKzBN52ouQh2ZSeqUong2vDrnAZ+6zHA2uSX1XkaZ7rk+NtYG9OO9Lsx7Z8EKQFjFvPAD5MgwHPGNkKOT0nu3q+Cim5q1XjFxO7FbDAXPLBbULCbLgP1cufVUYM/4/3BWVXrmycKx4Kg5l2XTNEjYN0Cnrjq0dKLyqDO76MR4Ni2AcS/MubzHH/SSASfU5vHnadH1ZZcjFTEAJ+fJiENu0OGiry6aQj5ExcA+6ExwL+Ta6/1C4v21W5Sbgt7axBxnuJviHU2WsWGGC5J4QANSkTN6WbJF5FQMZmNKF0ntqIKuhvpn5c14yDoQI6ZlOgUCIz81TxE8bsJ6bV53wzLIOoQ=
      skip_cleanup: true
      skip_existing: true
      distributions: "sdist bdist_wheel"
      server: https://test.pypi.org/legacy/
      on:
        tags: true

  - stage: Build and deploy
    name: Build and deploy website (production)
    if: tag =~ ^[0-9]+\.[0-9]+\.[0-9]+$
    python: 3.6
    install:
    - make install
    script:
    - make html
    deploy:
    - provider: pages
      skip_cleanup: true
      github-token: "$GITHUB_TOKEN"
      keep-history: true
      local-dir: docs
      target-branch: gh-pages
      verbose: true
      on:
        tags: true

  - stage: Build and deploy
    name: Build and deploy website (staging)
    if: tag IS present AND ( NOT tag =~ ^[0-9]+\.[0-9]+\.[0-9]+$ )
    python: 3.6
    install:
    - make install
    script:
    - make html
    deploy:
    - provider: pages
      skip_cleanup: true
      github-token: "$GITHUB_TOKEN"
      keep-history: true
      local-dir: docs
      target-branch: gh-pages-staging
      verbose: true
      on:
        tags: true

notifications:
  email: false

env:
  global:
  - secure: RnDoGS/KhXs4u1ACCVC+TrXWJFrJuBADFGz1WhaIOR/f3P8/ytrj6+g78KvlDLVI/HSK3TN0+c0zgeubq4mEMGE8WnooTV3IH00l4yjTJZ21qp6v4gEj1wH3gaVJzKhddRP4PozMqE5zQG1xs/H4XKLdyrlTMSB9PblejOs2sOv9MwaXPraUCwvPZ+DFDjBCgaWgO/1+X3dF7Y+DOpuvI6ejagPvl5ZJXaoHE1yrzLL6VIOIjtCCd6p9HKeDRFcJuJWBv20yczQMTnUsEon3sWQjIhJEX6ryK6NUhzZjsW8ciUFmiQdYCxnVyK5Nns5hFbBFRtvuYCNuWOEAMm+3ogesWXwJo/dDkj5L/QLaBBuaWhTochU9aSDOAIA8MdkiCsyymYBLVr4ByYvaeAdFaX6xglfOtRsMoAMZm9ZN05QYP5TAe9s0r0XPAH3hdrjURTVm+A2XEXkWNocNcjfVH5gVBk+T68VThW35C4ICSnxW/euFDHkMACzi/iw/jL2WzCBtNjFCNT9tFUQDh9cH/d5F/9gZ/bfEYPg38AFjCUK+WfvoWrPRqiIcr6A7vaq9eHjTAj5vQuaR6kcW3pHKsAHVdSgcdL9j94/xo0Gt8Q+CSqHDVa8aV7CBQApmc9O6FbZkqH3H6U9QVlNDJ5Fybi5hTRc5jn8q/vT1dx/J9X4=
