sudo: required
language: node_js

os:
  - linux


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

services:
  - docker

addons:
  sonarcloud:
    organization: "open-cluster-management"
    token:
      secure: "uEOFg1jLhE+q4C1uu2woPC2pqMrNN4M4/LVT9TRAaW9pdd7glsfPQBidAeeUz9edVGxPzqgG3MiMxlhsbGwj54zTQr3GPwerF+Nig4expHXteMYfIvwhPYPhEr4XOgHexic1zOpNtaUIv2ETKZWYnM9tR1r7OYDaFzi4Sz4DWmPteI8PgpHnf95JVWn8n4p68p69UYYw1t6gLnPcBA2e9mwyzQRDLgfWEX7OZIGm6f1YXYUdvKFUJIyf0g+0eTPibbw+7DgvX1e6UcSKt6zCQCESfxp6XteYg1GbVsHpuHAWpHu8TQj3FUf+3O60DZHrk1QDpXMjbQqNak7wi4gsQSpvhsvNQ/ngV+venIKbn233t1S8gCkAPiG1SVCKhIpDSf9+vHHLkPZ3qzWPpPHmpmqciuSRCfLEsZKSLrb76LAONQF0T/tYhbAHVEv6AJhVMJQ8bZD/cJd7GyPbod5ViTkQzALbxiEgRtLxfsaBVckSOlhHdZs22S1UpwgI8TEPiVijziMgXQ/X1/GlChgpC+qmnWUEm916avByKinWxzZ2ZKXc/0NmOSeS8AXrd3utsp1+WXa6OBeix3VaTXLbbBmU8IqKT5UdOKDeG7kgeUbkLdJM1s+TRLLXS8w+3en7x84U7dqRTV6PzB7xhF/a1Ip6HxN/k0g4D/VGj6/Wze0="


env:
  global:
    # Required
    - OS=linux
    - COMPONENT_TAG_EXTENSION="-${TRAVIS_COMMIT}"
    # Component Specific
    - 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:
  - make init

jobs:
  include:
    - stage: build
      name: "Build the test image and push it"
      script:
        - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then export COMPONENT_TAG_EXTENSION="-PR${TRAVIS_PULL_REQUEST}-${TRAVIS_COMMIT}"; fi;
        - make component/build
        - make component/push
    - stage: unit-test
      name: "Run unit tests"
      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 component/pull 
        - make sonar/js/jest-init
        - make component/test/unit
        - make sonar/js
        # - sonar-scanner --debug
    - 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
        - make security/scans 

    - stage: release-ff
      name: "Push commits to current release branch"
      if: type = push AND branch =~ /^main$/
      script:
        - make
        - 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}
