version: 2

jobs:
  build_pkgs:
    docker:
      - image: joaander/conda-build:20170905

    steps:
      - run:
          name: "Configure conda"
          command: "conda config --add channels mila-udem"
      - checkout
      - run:
          name: "Checkout Merge Commit"
          command: |
            if [[ -n "${CIRCLE_PR_NUMBER}" ]]
            then
                git fetch -u origin "+refs/pull/${CIRCLE_PR_NUMBER}/merge:pr/${CIRCLE_PR_NUMBER}/merge"
                git checkout -qf "pr/${CIRCLE_PR_NUMBER}/merge"
            fi
      - run:
          name: "Build Recipe"
          command: |
            export THEANO_VERSION=`python -c 'import versioneer; print(versioneer.get_version())'`
            conda build --py 2.7 conda
            conda build --py 3.5 conda
            conda build --py 3.6 conda
      - run:
          name: "Upload Tagged Versions"
          command: |
            if [[ -n "${CIRCLE_TAG}" ]]
            then
                anaconda -t $BINSTAR_TOKEN upload --user=mila-udem /opt/conda/conda-bld/linux-64/theano*
            fi
      - store_artifacts:
          path: /opt/conda/conda-bld/linux-64

workflows:
  version: 2
  build_and_test:
    jobs:
      - build_pkgs:
          filters:
            tags:
              only: /.*/