# Copyright Contributors to the Open Cluster Management project

os:
  - linux

language: go
go:
  - 1.16.x

services:
  - docker

addons:
  sonarcloud:
    organization: "open-cluster-management"
    token:
      secure: "MI3WWiJuh38YtX43/r/rp9FzYt3DWMLsKbCYVheNnrG0u7xo8tfX8/o9LND0oJeKV7LEUnLfY3p1VKeRrTKPL+Oh/KuEM/wG0NoZoYt68muutYzk7JfCi0f2p90CxVYlPGU6AZkvJzRRA+VXDKUQVW9/zQGNjFILivnMjtfkhPurYxqP/GTwjOd/vJbpjYfwNvM/CeznLzSzFWfYexJq93L9txfirdj5EhkmUnQqYnsJaplCxO9ZtC70Yd4xfMgDUVoIiK4AWGPiXoQcdSR4b8bEQrVWwjaz4lxPtF0c0hwKfnRXz9pZM71oMmZTzgCUF5P2IZaorr7VPUBikApoi5xoowIDuFjGAnlqUqGlrPHy9Rgbl1cgBXTiva0G7es+EeNkLUgNqwCAMZQxnOcjjwO4ZZ9/G179NDvJ9MPX7yHFzyk6muC4Y3Gs3MuH85PyYh9QlgWTYvU43ZUhhu1sEcjb/zDiY0c8X0KK6ZPofDKXji1ckfRNRhFunTJeyYFLwW1qZdftkiIhWYT6K70W8aZaxJv3Wr8/IjmgxvYubje5gyt+xCqqNGbtOGpN38UiCnBNdCj42RFUjRRj92QMMxnsGCkr2k3LhKqQkpZ9L4tX+Ookn+7diSAIB2bD/EXMc5fkhDzWEOaKkZSpA0HKoZc4a+R6Rcegz2WO4nu7+yc="

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

env:
  global:
    # Required
    - OS=linux
    - COMPONENT_TAG_EXTENSION="-${TRAVIS_COMMIT}"

    # Component Specific
    - COMPONENT_DEPLOY_COMMAND=${TRAVIS_BUILD_DIR}/build/deploy-to-cluster.sh
    - COMPONENT_INIT_COMMAND=${TRAVIS_BUILD_DIR}/build/install-dependencies.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

stages:
  - build
  - unit-test
  - test-e2e
  - release-ff
  - publish

before_script:
  # Bootstrap the build harness.
  - make
  # Set the image tag differently for PRs.
  - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then export COMPONENT_TAG_EXTENSION="-PR${TRAVIS_PULL_REQUEST}-${TRAVIS_COMMIT}"; fi;


jobs:
  include:
    - stage: build
      name: "Build the image and run unit tests"
      script:
        - make component/build
        - make component/push
    - 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 component/pull && make component/test/e2e    
    - stage: unit-test
      name: "Run unit tests"
      script:
        # Bootstrap the build harness, pull test image, and run unit tests.  
        - make component/test/unit
        - make security/scans
        - make sonar/go  

    - stage: release-ff
      name: "Push commits to current release branch"
      if: type = push AND branch =~ /^main$/
      script:
        - make release-ff

    - 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 pipeline-manifest/update PIPELINE_MANIFEST_COMPONENT_SHA256=${TRAVIS_COMMIT} PIPELINE_MANIFEST_COMPONENT_REPO=${TRAVIS_REPO_SLUG} PIPELINE_MANIFEST_BRANCH=${TRAVIS_BRANCH}
