language: go
go_import_path: github.com/operator-framework/operator-sdk
sudo: required

cache:
  directories:
    - $HOME/.cache/go-build

go:
- 1.10.3

# The `x_base_steps` top-level key is unknown to travis,
# so we can use it to create a bunch of common build step
# YAML anchors which we use in our build jobs.
x_base_steps:
  # before_install for jobs that require dep
  - &dep_before_install
    before_install:
      - curl -Lo dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && chmod +x dep && sudo mv dep /usr/local/bin/
      - travis_retry dep ensure -v
  # before_install for jobs that require go builds and do not run for doc-only changes
  - &go_before_install
    before_install:
      # hack/ci/check-doc-only-update.sh needs to be sourced so
      # that it can properly exit the test early with success
      - source hack/ci/check-doc-only-update.sh
      - curl -Lo dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && chmod +x dep && sudo mv dep /usr/local/bin/
      - travis_retry dep ensure -v

  # Base go, ansbile, and helm job
  - &test
    stage: test
    env: CLUSTER=openshift
    <<: *go_before_install
    install:
      - make install
      - hack/ci/setup-openshift.sh
    after_success:
      - echo "Build succeeded, operator was generated, memcached operator is running on $CLUSTER, and unit/integration tests pass"
    after_failure:
      - echo "Build failed, operator failed to generate, memcached operator is not running on $CLUSTER, or unit/integration tests failed"
      - kubectl get all --all-namespaces
      - kubectl get events --all-namespaces --field-selector=type=Warning
    services:
      - docker

  # Base deploy job
  - &deploy
    stage: deploy
    if: type != pull_request AND ( tag IS present OR branch = master OR commit_message =~ /\[travis deploy\]/ )
    <<: *go_before_install
    install: make install
    before_script:
      - git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
      - git fetch --unshallow --tags
    after_success:
      - echo "Image build succeeded, and docker image tagged and pushed to repository"
    after_failure:
      - echo "Image build, docker image tagging, or docker image pushing to repository failed"
    services:
      - docker

jobs:
  include:
    # Build and test go
    - <<: *test
      name: Go on OpenShift
      script: make test/ci-go ARGS="-v"

    # Build and test ansible
    - <<: *test
      name: Ansible on OpenShift
      before_script: sudo pip install ansible
      script: make test/ci-ansible

    # Build and test helm
    - <<: *test
      name: Helm on OpenShift
      script: make test/ci-helm

    # Run the unit, sanity, and markdown tests
    - stage: test
      name: Unit, Sanity, and Markdown Tests
      # Currently, prow/api-ci tests all PRs that target master; use travis for post merge testing and non-master PRs
      if: type != pull_request OR branch != master
      <<: *dep_before_install
      script: make test/sanity test/unit test/markdown
      after_success: echo 'Tests Passed'
      after_failure: echo 'Failure in unit, sanity, or markdown test'

    # Build and deploy ansible-operator docker image
    - <<: *deploy
      name: Docker image for ansible-operator
      script:
        - make image/build/ansible
        - make image/push/ansible

    # Build and deploy helm-operator docker image
    - <<: *deploy
      name: Docker image for helm-operator
      script:
        - make image/build/helm
        - make image/push/helm

    # Build and deploy scorecard-proxy docker image
    - <<: *deploy
      name: Docker image for scorecard-proxy
      script:
        - make image/build/scorecard-proxy
        - make image/push/scorecard-proxy
