
os:
  - linux

language: go
go:
  - "1.15"

services:
  - docker

branches:
  only:
    - master
    - dev
    - /^[0-9]+\..*$/
    - /^v[0-9]+\..*$/
    - /^release-[0-9]+\..*$/

addons:
  sonarcloud:
    organization: "open-cluster-management"
    token:
      secure: "rn5yfUBpR6kOlnYbwcnWQNgUPKwboU0MLb4oxPaqb6El00I439KFuFIdl2QsBH/f8Js0O4a3iX9P6R+vHJoPpiCynKFgnHfTWCyHMD+L1gsuf5irVmyoHOK8x8UjkiTH8Djxz06qJKbEEZaiFYXBwHwrGUApJ4kD/6Jpd/S3mcDZ9fJkr9HqC+xtiWTfLBQToj4qkP3rDZGslGR6RXRyHaJ/h/mr6mm7ogOPIgKTjxn8/9jybe1rteP4pX9vXwdiCKQXUYyttGT8dlBFfmpMJ973qLpPPR3vApWxSDGqUoC5zg7PMYW+ThM9ihcb70PFeFVZyPTE4qdSoOKjWrEa2KNeasYp9U8lmhja7ZrfpYqp1BBJLEljezteEk4w5snLlcVE/dd1iBxmRGA3yKFqW4vUYUk8Sxma/lsPVgYgf9L5hWz8B1oUkAwDkAe+miUTA9JTLHXpmy3/kZkx6cQ6MBGR9ANXI/ifrgf3OC43+Icittl5p/wShhKEZ2BlIc4vxBgV+a8uRe8qy1BxhHj9WB0wB7m+uB+XS0lTQkKVOxX4dWyZxpJTkimRueewSVSG06UjQF/vV9UniE8Jb9pWj69ZAPpFFCr+AUmqxMmHd9b9/Emr7TWGtBuP7rkdRSqLBJcq1p4730+PfdgbwtX2C2Wu2iqUkiDJvvPKTC2HD08="

env:
  global:
    # Required
    - OS=linux

    # Component Specific
    - COMPONENT_INIT_COMMAND=${TRAVIS_BUILD_DIR}/build/install-dependencies.sh
    - COMPONENT_DEPLOY_COMMAND=${TRAVIS_BUILD_DIR}/build/deploy-to-cluster.sh
    - COMPONENT_BUILD_COMMAND=${TRAVIS_BUILD_DIR}/build/build.sh
    - COMPONENT_UNIT_TEST_COMMAND=${TRAVIS_BUILD_DIR}/build/run-unit-tests.sh
    - COMPONENT_E2E_TEST_COMMAND=${TRAVIS_BUILD_DIR}/build/run-e2e-tests.sh

# define stages
stages:
  - lint
  - build
  - unit-test
  - test-e2e
  - publish

jobs:
  include:
    - stage: lint
      name: "Run code lint"
      if: type = pull_request
      script: bash ${TRAVIS_BUILD_DIR}/build/run-code-lint.sh
    - stage: build
      name: "Build the image and run unit tests"
      script:
        - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then export COMPONENT_TAG_EXTENSION="-PR${TRAVIS_PULL_REQUEST}-${TRAVIS_COMMIT}"; fi;
        - |
          make
          make component/build
          make component/push
          make security/scans
    - stage: unit-test
      name: "Run unit test"
      script:
        # Set the image tag differently for PRs
        - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then export COMPONENT_TAG_EXTENSION="-PR${TRAVIS_PULL_REQUEST}-${TRAVIS_COMMIT}"; fi;
        # Bootstrap the build harness, pull test image, and run unit tests.
        - |
          make
          make component/test/unit
          make sonar/go
    - stage: test-e2e
      name: "Deploy the image to a cluster and run e2e tests"
      if: type = pull_request
      script:
        #Check out a clusterpool, set up oc, deploy, run e2e tests, and return clusterpool cluster
        - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then export COMPONENT_TAG_EXTENSION="-PR${TRAVIS_PULL_REQUEST}-${TRAVIS_COMMIT}"; fi;
        - |
          make
          make component/pull
          make component/test/e2e
    - stage: publish
      name: "Publish the image to quay with an official version/sha tag and publish entry to integration pipeline stage"
      if: type = push AND branch =~ /^release-[0-9]+\..*$/
      script:
        - |
          make
          make pipeline-manifest/update PIPELINE_MANIFEST_COMPONENT_SHA256=${TRAVIS_COMMIT} PIPELINE_MANIFEST_COMPONENT_REPO=${TRAVIS_REPO_SLUG} PIPELINE_MANIFEST_BRANCH=${TRAVIS_BRANCH}
          make release-community-operator
