language: go
# see https://docs.travis-ci.com/user/reference/overview/#Virtualization-environments
# for the detail
# sudo: requried
dist: trusty

go:
  - 1.12.x

env:
  global:
  - GO111MODULE=on
  - secure: u6u0kork1/hWYmQe9Jc0FA5sUdsO3wych8Ud4P3v56gTqAQPFkpM+j5Kco38elhOJFSIOqBN0EQBUNYEC13LW6NuKQl1+Ru/xa1/z14MHcCWxANaZxz2vh7GVGZ4GviA+JRm5G6b3BUlp2yYGOjAFm0gRzSkhYFOap1omCAzjr872/pfEUmyTPEpM+mU7C3x40NtpNbnuZOQpJwHEM0zonhvDxNJpBqAzz9aqcXd6wcYOeJB+52zqxwkbUxitTozGu+RwoGgMbGA4wM+507kH7ckaqqPJB+b149Bb4/e0f0NRKeupBzs5fvEcPlJPAOP0YPBAytC6jp6GFjeNV/cWiextOgONv2L52nq7R6a2k/8ESQnKeYRu9RmNNOOS4Xxi+hbr6heRq+DEiUtpMDVPXSlB9IK0oLZNWe9F2ejllfCC3gSIKrRf79c5z/5fGypWy+VwKviFaedusXF9HtHYvBYeEluXjHnnj3SYytRgPa2pcksSb5rF15ZztGMXfbj236FK8hSUqvHVCf6AMKwm9eFLANP46L+Phgv7A0ORSD1bEpcKokF0j7NyAVoT4r0S9QF60zgfM7LeILe+Qm3nMIx6ud2ckfRHaimpe+aTqDOGlwYUwoSnZKSPgWnI52hc5GkOzmbDdwvQ53qw1WwpbCkCBudNcpZCdC9vI27v38=
  - secure: pikzmLVgZmabRWbhHs2/df/a5Y98QgecnA94iV8wLAIAZnL4wkFSnuOOAdZhFI/XPUm9jbvzfl6B+Q1nlLMlYhcmrxeVC+Q2PdrTbZGKfRXGbmo1S2It1nKImtYn/9pNrvI84XdbWkZIZgJF+/xJLty0+UYskg6+/yfl/WIhfwQnCapQD98FfLlNG1mlnNbtRjX62xVRRb18uwgiTn5i76lGsDjYLsO9ooHpJfQQnBW0kZMwc+UnYIOpMDBhaDLen0FDEr68Q3l3zitHEKTuHjOPMEkfmX+k1C5BkgqBTDacEzftX+QHx8Zna2pLSaiAj4qeeWyInYwH0ZSb0BWp9hoe9v3Hgrkn52zAawhTPmlb3F+NjCq2IjTR8OlNG5TTUT5KDeVVcY3t+IzSjHS7egCCqGHDKYa5AUpVDlraqXkxk3aTqrY70zJB09zM0OkAH/DuScKbFj4Ady6eTbHKNWDmF7W/HgHQ4ju2RCHvgoTya0c51nH1LkoHHvQ0rn/tngjgo/RHx7BQ2tuP8Z//rhuUPEbrdtfOWypXQb1367hQ2B8qO4L/PfhQ1xc99IOzdlabNFV2krVVtRTgHK9zui+d4WqwPZUsjiH+QzaPxd5W7AFBofan4Jd9HPexMAEYKLjurB1R/oiEbOEwhpxsdBOfVRLQoKjgWpEGmxuPvUU=

# before_script:
#   - golint pkg/... cmd/...
#   - go fmt pkg/... cmd/...
#   - go vet pkg/... cmd/...

script:
  - make
  - ./hack/test.sh
  - docker build -f Dockerfile.openshift -t nfvpe/net-attach-def-admission-controller .

deploy:
  # Push images to Dockerhub on tag
  - provider: script
    script: >
      bash -c '
      docker tag nfvpe/net-attach-def-admission-controller nfvpe/net-attach-def-admission-controller:$TRAVIS_TAG;
      docker login -u "$REGISTRY_USER" -p "$REGISTRY_PASS"; 
      docker push nfvpe/net-attach-def-admission-controller; 
      docker push nfvpe/net-attach-def-admission-controller:$TRAVIS_TAG;
      echo done'
    on:
      tags: true
      all_branches: true
      condition: "$TRAVIS_TAG =~ ^v[0-9].*$"
  # Push images to Dockerhub on merge to master
  - provider: script
    on:
      branch: master
    script: >
      bash -c '
      docker tag nfvpe/net-attach-def-admission-controller nfvpe/net-attach-def-admission-controller:snapshot;
      docker login -u "$REGISTRY_USER" -p "$REGISTRY_PASS";
      docker push nfvpe/net-attach-def-admission-controller:snapshot; 
      echo done'
  - provider: script
    on:
      branch: develop
    script: >
      bash -c '
      docker tag nfvpe/net-attach-def-admission-controller nfvpe/net-attach-def-admission-controller:snapshot;
      docker login -u "$REGISTRY_USER" -p "$REGISTRY_PASS";
      docker push nfvpe/net-attach-def-admission-controller:snapshot; 
      echo done'
