os: linux
dist: bionic
language: python

services:
  - mongodb

before_install:
  - sudo apt-get install -y xmlsec1

install:
  - pip install tox
  - pip install tox-travis

script:
  - tox

jobs:
  allow_failures:
    - python: 3.10-dev
    - python: pypy3
  include:
    - python: 3.6
    - python: 3.7
    - python: 3.8
    - python: 3.9
    - python: 3.10-dev
    - python: pypy3

    - stage: Expose env-var information
      script: |
        cat <<EOF
        TRAVIS_BUILD_ID: $TRAVIS_BUILD_ID
        TRAVIS_BUILD_STAGE_NAME: $TRAVIS_BUILD_STAGE_NAME
        TRAVIS_BUILD_NUMBER: $TRAVIS_BUILD_NUMBER
        TRAVIS_BUILD_WEB_URL: $TRAVIS_BUILD_WEB_URL

        TRAVIS_JOB_ID: $TRAVIS_JOB_ID
        TRAVIS_JOB_NAME: $TRAVIS_JOB_NAME
        TRAVIS_JOB_NUMBER: $TRAVIS_JOB_NUMBER
        TRAVIS_JOB_WEB_URL: $TRAVIS_JOB_WEB_URL

        TRAVIS_DIST: $TRAVIS_DIST
        TRAVIS_OS_NAME: $TRAVIS_OS_NAME
        TRAVIS_CPU_ARCH: $TRAVIS_CPU_ARCH
        TRAVIS_PYTHON_VERSION: $TRAVIS_PYTHON_VERSION
        TRAVIS_SECURE_ENV_VARS: $TRAVIS_SECURE_ENV_VARS

        TRAVIS_EVENT_TYPE: $TRAVIS_EVENT_TYPE
        TRAVIS_REPO_SLUG: $TRAVIS_REPO_SLUG
        TRAVIS_BRANCH: $TRAVIS_BRANCH
        TRAVIS_COMMIT: $TRAVIS_COMMIT
        TRAVIS_COMMIT_RANGE: $TRAVIS_COMMIT_RANGE
        TRAVIS_TAG: $TRAVIS_TAG
        TRAVIS_PULL_REQUEST: $TRAVIS_PULL_REQUEST
        TRAVIS_PULL_REQUEST_BRANCH: $TRAVIS_PULL_REQUEST_BRANCH
        TRAVIS_PULL_REQUEST_SHA: $TRAVIS_PULL_REQUEST_SHA
        TRAVIS_PULL_REQUEST_SLUG: $TRAVIS_PULL_REQUEST_SLUG
        EOF

    - stage: Deploy new pre-release on PyPI
      if: type = push
      before_install: skip
      install: skip
      script:
        - read -r CURRENT_VERSION <VERSION
        - printf -- '%s-%s\n' "${CURRENT_VERSION}" "${TRAVIS_BUILD_NUMBER}" >VERSION
      deploy:
        - provider: pypi
          distributions: sdist bdist_wheel
          server: "https://test.pypi.org/legacy/"
          skip_cleanup: true
          username: "__token__"
          password: "$PYPI_PRE_RELEASE_TOKEN"
          on:
            repo: IdentityPython/pysaml2

    - stage: Deploy new release on PyPI
      if: type = push AND tag IS present
      before_install: skip
      install: skip
      script: skip
      deploy:
        - provider: pypi
          distributions: sdist bdist_wheel
          username: "__token__"
          password: "$PYPI_RELEASE_TOKEN"
          on:
            repo: IdentityPython/pysaml2
            tags: true

    - stage: Deploy new release on GitHub
      if: type = push AND tag IS present
      before_install: skip
      install: skip
      script: skip
      deploy:
        - provider: releases
          token: "$GITHUB_RELEASE_TOKEN"
          on:
            repo: IdentityPython/pysaml2
            tags: true
