---
services: docker

env:
  # Package install on all OSes.
  - distro: centos7
    playbook: test.yml
    ruby_version: 2.0.0
    ruby_path_prefix: /usr
  - distro: ubuntu1604
    playbook: test.yml
    ruby_version: 2.3.1
    ruby_path_prefix: /usr
  - distro: ubuntu1404
    playbook: test.yml
    ruby_version: 1.9.3
    ruby_path_prefix: /usr
  - distro: debian8
    playbook: test.yml
    ruby_version: 2.1.5
    ruby_path_prefix: /usr

  # Source install on latest OSes.
  - distro: centos7
    playbook: test-source.yml
    ruby_version: 2.3.0
    ruby_path_prefix: /usr/local
  - distro: ubuntu1604
    playbook: test-source.yml
    ruby_version: 2.3.0
    ruby_path_prefix: /usr/local

script:
  # Configure test script so we can run extra tests after playbook is run.
  - export container_id=$(date +%s)
  - export cleanup=false

  # Download test shim.
  - wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
  - chmod +x ${PWD}/tests/test.sh

  # Run tests.
  - ${PWD}/tests/test.sh

  # Make sure ruby is installed and at the correct version.
  - 'docker exec --tty ${container_id} env TERM=xterm which ruby'
  - 'docker exec --tty ${container_id} env TERM=xterm test -x ${ruby_path_prefix}/bin/ruby'

  - 'docker exec --tty ${container_id} env TERM=xterm ruby --version'
  - 'docker exec --tty ${container_id} env TERM=xterm ${ruby_path_prefix}/bin/ruby --version | grep -qF ${ruby_version}'

  # Make sure bundler is installed.
  - 'docker exec --tty ${container_id} env TERM=xterm ls -lah /usr/local/bin'
  - 'docker exec --tty ${container_id} env TERM=xterm which bundle'

  # Make sure user installed gems are available.
  - |
    if [ "${distro}" != "ubuntu1404" ]; then
      docker exec --tty ${container_id} env TERM=xterm bash --login -c "which sass"
    fi

after_failure:
  - 'docker exec --tty ${container_id} env TERM=xterm which ruby'
  - 'docker exec --tty ${container_id} env TERM=xterm ruby --version'

notifications:
  webhooks: https://galaxy.ansible.com/api/v1/notifications/