sudo: required
language: go

go:
- 1.11.x

services:
- docker

addons:
  apt:
    packages:
    - docker-ce

script:
- set -e
- make test-fmt
- make test-codegen
- go test -race -coverprofile=coverage.txt -covermode=atomic ./pkg/controller/
- make build

after_success:
- if [ -z "$DOCKER_USER" ]; then
    echo "PR build, skipping image push";
  else
    BRANCH_COMMIT=${TRAVIS_BRANCH}-$(echo ${TRAVIS_COMMIT} | head -c7);
    docker tag stefanprodan/flagger:latest quay.io/stefanprodan/flagger:${BRANCH_COMMIT};
    echo $DOCKER_PASS | docker login -u=$DOCKER_USER --password-stdin quay.io;
    docker push quay.io/stefanprodan/flagger:${BRANCH_COMMIT};
  fi
- if [ -z "$TRAVIS_TAG" ]; then
    echo "Not a release, skipping image push";
  else
    docker tag stefanprodan/flagger:latest quay.io/stefanprodan/flagger:${TRAVIS_TAG};
    echo $DOCKER_PASS | docker login -u=$DOCKER_USER --password-stdin quay.io;
    docker push quay.io/stefanprodan/flagger:$TRAVIS_TAG;
  fi
- bash <(curl -s https://codecov.io/bash)
- rm coverage.txt

deploy:
- provider: script
  skip_cleanup: true
  script: curl -sL http://git.io/goreleaser | bash
  on:
    tags: true
