
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: "DfjueWGZbl0QccIpiJ9KPWycoG3Med1qRfAG4jJL1Qar0K5UQskW8QTweCAYBzoDTDm2XBuzSepoTojTAc98GoCRTG5F/rlYU4h8ZpE8Bgnprj7EWWWZ5jfdMJbiSlzKxA0Xu5XJTTR+fu2rBm0lYJ8MBjDGJGMqO7hue5/dFnSuztmIHm7UsDnV/tTjE2d1ovQg+fy/Sv7Z22QToK1q+RbYX7/mBmfL2otQZ6VAYbzCl67dPr2v99E4SrR4x6jB4kbmaFRnwcsE4q+UNX/Z02tCyfh6tumAK0r35Jpy66avc1ricgegLzVfMhb19IA+6tl4oeWhXf349ftyZVvDb6PQDuvRQWQAJNevK/6G1TIklpBl3W2Msdmv1lCNOeTsVid1EBoVpzTxidfWx58UBVDzZHIGnr5GQI0YTB4nMyTSTnHGop+JNFrMXvaK+/U42L6dMG1yyWplIcTPWMHutQeuj43NgA1CjeszRtkt4gVYlYNRoaaHI2mCl84iX9xZeHgvFasBbtqoCT+W/vN17zbcnaMP8/mtEbWEkY7//jG1FyhHPNdVE9T2vKsfMoSU6kBWYJykHUCiurwRKX2xsxiuDvpV3Qwb7KSxMKvrIo1YAHtHZaoT/w8sBNsZCGH4VK3dwk4KMLufoi+jGNA3gf4wVN86Z0i5pjJpH6bH6Bw="

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
