sudo: required
services:
  - docker
  - xvfb

language: node_js
node_js:
  - "14"

git:
  submodules: false

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

addons:
  sonarcloud:
    organization: "open-cluster-management"
    token:
      secure: "bVqGaU7lSi2Tzi7MaCqsf1FihMmlb9GhLicMY3/KPgvKMJ/nIgIX030rz2PDBeGuWdq7bqMNe2Vekfw8sqotJDPmudYfKbUx7DqNSakBlEcwegELDEIMjqslslK9sgqUaiCy4S6eNTS0ogBtRCLkL1s6p2e9IMHD7GQXajjxZu6p6o+iCa5g3g09P0IANUk5HDE1dg6OcOQTtvLUlGzcpeA0WRx7e4pORn8pCF+id4HA/iChW2u2adMErd8xR9J2KCPic9E5jU6vKm0caTK6eFcyWDcgd22uWYqcgNy+RN4zqyDS+YZrIPAEHcpKALbdOQHWw/Nb35YwY9T6YN6Cp3BCKva9nx/JxqJmgMn2LTzzGnaJxAcHyhhEvAu0qO9S+DVuXoQCtumcx5+j372CcMheFMYGjiXztTycTGS6cmpT+9FtptV4jy5Fyr3rykOQs1LrpL9Q9FZ5pu/snjdyFD8VVrDvhBUVRyrp5SHzQFPsmHT+BLP7tPvwcQ4ZKRM8usoFXs8wPDB9fGiem0JFFI3qKYtw/n2KMhsLHDsUEEunRwEuImt/jR/BQWsmgHF8BVXHMTgvN+pEbpwmRCeT2pjcA1OyuRJ6oQyO3uFLroM3sXEha0be9hL/241kFFpAf2eXdBLbPA1MxOqqUjE9YUV7PDTBk78eWeXfRhTlAi0="

env:
  global:
    - COMPONENT_TAG_EXTENSION="-${TRAVIS_COMMIT}"
    - 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:
  - unit-test
  - build
  - test-e2e
  - release-ff
  - publish

before_script:
  - make init

jobs:
  include:
    - stage: unit-test
      name: "Run linting, sonar scan"
      script:
        - make component/test/unit
        - sonar-scanner
    - stage: build
      if: type = pull_request OR (type = push AND branch =~ /^release-[0-9]+\..*$/)
      name: "Build and push kui-web-terminal image"
      before_install:
        - make test-module
      script:
        - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then export COMPONENT_TAG_EXTENSION="-PR${TRAVIS_PULL_REQUEST}-${TRAVIS_COMMIT}"; fi;
        - make component/build
        - make component/push
        - make security/scans
        - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then make component/push COMPONENT_VERSION=$(git log -1 --pretty="%aN" | sed 's/[^a-zA-Z0-9]*//g') COMPONENT_TAG_EXTENSION=""; fi;
    - stage: test-e2e
      name: "Run functional tests"
      if: type = pull_request
      addons:
        firefox: latest
      before_install:
        - make test-module
      script:
        - 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: 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}
        - travis_wait 15 sleep 900
        - rm -rf pipeline
        - make pipeline-manifest/update COMPONENT_NAME=kui-web-terminal-tests PIPELINE_MANIFEST_COMPONENT_SHA256=${TRAVIS_COMMIT} PIPELINE_MANIFEST_COMPONENT_REPO=${TRAVIS_REPO_SLUG} PIPELINE_MANIFEST_BRANCH=${TRAVIS_BRANCH}
