matrix:
  include:
  - python: '2.7'
    sudo: required
    services:
    - docker
    env: DOCKER_IMAGE=quay.io/pypa/manylinux1_x86_64
         DOCKER_DEPLOY='manylinux1_x86_64'
         TRAVIS_PYTHON_VERSION='2.7'
  - python: '2.7'
    sudo: required
    services:
    - docker
    env: DOCKER_IMAGE=quay.io/pypa/manylinux1_i686
         PRE_CMD=linux32
         DOCKER_DEPLOY='manylinux1_i686'
         TRAVIS_PYTHON_VERSION='2.7'
  - python: '2.7'
    sudo: false
    env: DOCKER_DEPLOY=false
         TRAVIS_PYTHON_VERSION='2.7'
  - python: '3.6'
    sudo: false
    env: DOCKER_DEPLOY=false
         TRAVIS_PYTHON_VERSION='3.6'

before_install:
- echo $DOCKER_DEPLOY
- echo $TRAVIS_BRANCH
- echo $TRAVIS_PYTHON_VERSION
- if [[ ("$TRAVIS_BRANCH" != "rc" || "$TRAVIS_BRANCH" != "master") && "$DOCKER_DEPLOY" == "false" || ("$TRAVIS_BRANCH" == "rc" || "$TRAVIS_BRANCH" == "master") && "$DOCKER_DEPLOY" != "false" ]]; then
    if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
      wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
    else
      wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
    fi;
    echo $TRAVIS_PYTHON_VERSION;
    bash miniconda.sh -b -p $HOME/miniconda;
    export PATH="$HOME/miniconda/bin:$PATH";
    conda update --yes conda;
    conda update --all --yes;
    cd python;
    git branch -v;
    git describe --tags --dirty;
    ./get_nanoversion.sh;
    cat __nanoversion__.txt;
    cd ..;
    if [[ "$DOCKER_DEPLOY" != "false" ]]; then
      conda install --yes pip;
    else
      conda install --yes gcc_linux-64;
      conda install --yes pip numpy pyyaml nomkl make cmake;
    fi
  fi
- pwd

install:
- pwd
- if [[ "$DOCKER_DEPLOY" != "false" ]]; then
    if [[ "$TRAVIS_BRANCH" == "rc" ]] || [[ "$TRAVIS_BRANCH" == "master" ]]; then
      docker pull $DOCKER_IMAGE;
      cd python;
      cp -a ../src .;
      docker run --rm -v `pwd`:/io $DOCKER_IMAGE $PRE_CMD /io/build-wheels.sh;
      ls wheelhouse/;
      mkdir dist;
      cp wheelhouse/spglib* dist/;
      ls dist/;
      cd ..;
    fi
  fi

script:
- pwd
- if [[ "$DOCKER_DEPLOY" == "false" ]]; then
    if [[ "$TRAVIS_BRANCH" != "rc" && "$TRAVIS_BRANCH" != "master" ]]; then
      conda install -c conda-forge --yes valgrind;
      mkdir _build && cd _build;
      cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON .. && make spglibtest;
      valgrind --leak-check=yes --error-exitcode=123 ./spglibtest;
      cd ..;
      cd python;
      python setup.py test;
      cd ..;
    fi
  fi

before_deploy:
- cd python

deploy:
# testing pypi
- provider: pypi
  server: https://test.pypi.org/legacy/
  skip_existing: true
  skip_cleanup: true
  user: atztogo
  password:
    secure: "uqsoPpQNbie297e1iDPOHUVqM1HPHeZjIuAutWvVjZF6TpaksDhPNkK9sIE9Wh4sAVLi1wUCtjlMYjC7ElS94tsHwj6+tyxvQtrDmGUWRdf6BjFFZ6CdKBxMJwBQTryCScQGxR81NVlKAzKgZkdrhAxr93kDWmG0thYQrDQO8ihgfxgZUDnZnwarZCiUxwCsT/5VyUv6aRL+epXOUdlPZL2ypiRPlu+9zgwP348OCseh8EtlSLp0uv+K6qOMDVfjQeaEVl0CQIfbkIFMIxPB7xxBNn8pG1aMFJOks6QKo4dq0QhW5eCacPVy/WIQyZ96DNub+zcpFboCIIyWdLO7VFMhyp4PnsqbiTpHLPmImFLWuzaTvCc58Q/QRGRJ3+68kByX/eBWoWgBJED9uX+fSCumfUak+Q9UcVVy/+uh8DJmKlCEWBevk5mVb9evgmLDvpo4q9Vk2U3xv4Cj511PH9JJzcVa3YgznUzLbL93NbSBzlO1/sWYjVp32mPQNekQzOlXCMhqBKkqCIk0Y0INtUNx7v7cA13iEM+QudQQ/sJvCRScNSztYa++W274wo5QxOQeZf5RS8sXzu9bvNvJRpFWsAkyebGVmab597hGgjdVtRMiuaq72+sy45ZCDSSSx0rlEbj6QhYNaSjEqutRBoddTHp7JY1ZT6PKGa/iWPA="
  on:
    repo: atztogo/spglib
    branch: rc
    tags: false
    condition: "$DOCKER_DEPLOY == manylinux1_x86_64 || $DOCKER_DEPLOY == manylinux1_i686"

# testing conda
- provider: script
  skip_cleanup: true
  skip_existing: true
  script: conda/anaconda_deploy.sh rc $ANACONDA_TOKEN $TRAVIS_BRANCH
  on:
    repo: atztogo/spglib
    branch: rc
    tags: false
    condition: "$DOCKER_DEPLOY == false"


# production pypi
- provider: pypi
  skip_cleanup: true
  skip_existing: true
  user: atztogo
  password:
      secure: "sjUxbFSrhflB/NqMwcJCmalmQRX1EN4zgsK2YyY93JEk16aep+5pRyV87Q3Q54L19PGOkTqOrGyvUhwxTHUweo87F2DM1gd695bg0rROcquvhwWxlTuhMhMoUGSxDljgKbEeTvLikFd91JX2Rr/deIZLog/c3z/m55MbgHqGoyR5p1twxqLoUcJHznM8Mnn/KTauVHVQKG/6sVQr/h9AhRB8qI5VRCcrnDqAWoePqkgibWjEKchx/lmgW4TiB15IIvmIVgMxNwUa2q91Lqn3AhZDOcB/TST34yZCx8j1TpLJgAtB8+aRnTdmtfhnPWN8gebVuHJni+EQYsq4sIOiRzsU5qHkCzmW2x6I/kcTTYWYW4KybKorWQcypotTkyDoSfFuhZ93kyMy6QXBdV0/3xskBAbA++Mc93u6KaNMDnBGLb9PoeIT6R6YRNnwDAYBSlJ8lMZoNwVKrPhxI11r15eAK/4NamUHSLORBJWYKw1Z1Ko5wjkMXTSC4y7rC5UD+wrgZCfhB7WBLvatGBA3oD83dmEzMl3zA3wyaegDqHbEzKIFCGX5/eKrVN91hQrvlFkVYwf7YHAcNTvplZi0EGotfuZVsyhHiYSXRrMdF16g/NyZwunMEydafsbbwQatLxMhCMufX+5B1bk8VsmM0QDI9EV3rdvC7vgpnO5KPpY="
  on:
    repo: atztogo/spglib
    branch: master
    tags: false
    condition: "$DOCKER_DEPLOY == manylinux1_x86_64 || $DOCKER_DEPLOY == manylinux1_i686"

# production anaconda
- provider: script
  skip_cleanup: true
  skip_existing: true
  script: conda/anaconda_deploy.sh main $ANACONDA_TOKEN $TRAVIS_BRANCH
  on:
    repo: atztogo/spglib
    branch: master
    tags: false
    condition: "$DOCKER_DEPLOY == false"

after_deploy:
- cd ..
