dist: bionic
sudo: required
services:
  - xvfb
addons:
  chrome: stable
language: node_js
node_js:
  - '12.18.1'

cache:
  directories:
    - node_modules

branches:
  only:
    - master
    - develop
    - /.*beta.*/

before_install:
  - . ./scripts/ci/job_hooks/before_install.sh

install: echo "no install"

stages:
  - name: Quality and Unit tests
  - name: Publish Docker Registry
    if: (type = push AND tag IS blank) OR type = api
  - name: Release Libraries
    if: branch = master AND type = push
  - name: Release Tag
    if: branch = master AND type = push
  - name: e2e
  - name: Trigger DW
    if: (branch = master OR branch = develop OR (tag =~ .*beta.*)) AND (type = push OR type = api)

env:
  global:
    - API_AOS_HOST=$API_CONTENT_HOST
    - ADMIN_EMAIL=$ADMIN_EMAIL_REMOTE
    - ADMIN_PASSWORD=$ADMIN_PASSWORD_REMOTE

jobs:
  include:
    - stage: Quality and Unit tests
      name: 'Code quality checks'
      script: npm ci && npm run lint

    - stage: Quality and Unit tests
      name: 'Build (without animation)'
      before_script: npx @alfresco/adf-cli update-commit-sha --pointer "HEAD" --pathPackage "$(pwd)"
      script: npm ci && npm run build.e2e
      after_success: ./scripts/ci/utils/artifact-to-s3.sh -a ./dist/app -o "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2"
      cache: false

    - stage: Quality and Unit tests
      name: 'Unit tests: aos'
      script: npm ci && ng test adf-office-services-ext --watch=false
      cache: false

    - stage: Quality and Unit tests
      name: 'Unit tests: aca-shared'
      script: npm ci && ng test aca-shared --watch=false
      cache: false

    - stage: Quality and Unit tests
      name: 'Unit tests: aca-about'
      script: npm ci && ng test aca-about --watch=false
      cache: false

    - stage: Quality and Unit tests
      name: 'Unit tests: aca-settings'
      script: npm ci && ng test aca-settings --watch=false
      cache: false

    - stage: Quality and Unit tests
      name: 'Unit tests: ACA'
      script:
        - npm ci
        - ng test app --code-coverage --watch=false
        - bash <(curl -s https://codecov.io/bash) -X gcov
      cache: false

    - stage: e2e
      name: 'Test Suites: authentication,listViews,navigation,application'
      before_script:
        - ./scripts/ci/job_hooks/before_e2e.sh "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2" "./dist/app" "-a" || travis_terminate 1
      script: ./scripts/ci/jobs/affected-project-with.sh -target e2e -options "--suite=authentication,listViews,navigation,application"
      after_script:
        - ./scripts/ci/job_hooks/after_e2e.sh

    - stage: e2e
      name: 'Test Suites: search'
      before_script:
        - ./scripts/ci/job_hooks/before_e2e.sh "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2" "./dist/app" "-a" || travis_terminate 1
      script: ./scripts/ci/jobs/affected-project-with.sh -target e2e -options "--suite=search"
      after_script:
        - ./scripts/ci/job_hooks/after_e2e.sh

    - stage: e2e
      name: 'Test Suites: pagination'
      before_script:
        - ./scripts/ci/job_hooks/before_e2e.sh "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2" "./dist/app" "-a" || travis_terminate 1
      script: ./scripts/ci/jobs/affected-project-with.sh -target e2e -options "--suite=pagination"
      after_script:
        - ./scripts/ci/job_hooks/after_e2e.sh

    - name: 'Test Suites: actionsAvailableFilesFolders'
      before_script:
        - ./scripts/ci/job_hooks/before_e2e.sh "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2" "./dist/app" "-a" || travis_terminate 1
      script: ./scripts/ci/jobs/affected-project-with.sh -target e2e -options "--suite=actionsAvailableFilesFolders"
      after_script:
        - ./scripts/ci/job_hooks/after_e2e.sh

    - name: 'Test Suites: actionsAvailableLibraries,actionsAvailableNewMenu'
      before_script:
        - ./scripts/ci/job_hooks/before_e2e.sh "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2" "./dist/app" "-a" || travis_terminate 1
      script: ./scripts/ci/jobs/affected-project-with.sh -target e2e -options "--suite=actionsAvailableLibraries,actionsAvailableNewMenu"
      after_script:
        - ./scripts/ci/job_hooks/after_e2e.sh

    - name: 'Test Suites: actionsAvailableSpecialPermissions'
      before_script:
        - ./scripts/ci/job_hooks/before_e2e.sh "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2" "./dist/app" "-a" || travis_terminate 1
      script: ./scripts/ci/jobs/affected-project-with.sh -target e2e -options "--suite=actionsAvailableSpecialPermissions"
      after_script:
        - ./scripts/ci/job_hooks/after_e2e.sh

    - name: 'Test Suites: copyMoveActions'
      before_script:
        - ./scripts/ci/job_hooks/before_e2e.sh "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2" "./dist/app" "-a" || travis_terminate 1
      script: ./scripts/ci/jobs/affected-project-with.sh -target e2e -options "--suite=copyMoveActions"
      after_script:
        - ./scripts/ci/job_hooks/after_e2e.sh

    - name: 'Test Suites: createActions'
      before_script:
        - ./scripts/ci/job_hooks/before_e2e.sh "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2" "./dist/app" "-a" || travis_terminate 1
      script: ./scripts/ci/jobs/affected-project-with.sh -target e2e -options "--suite=createActions"
      after_script:
        - ./scripts/ci/job_hooks/after_e2e.sh

    - name: 'Test Suites: deleteActions'
      before_script:
        - ./scripts/ci/job_hooks/before_e2e.sh "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2" "./dist/app" "-a" || travis_terminate 1
      script: ./scripts/ci/jobs/affected-project-with.sh -target e2e -options "--suite=deleteActions"
      after_script:
        - ./scripts/ci/job_hooks/after_e2e.sh

    - name: 'Test Suites: editActions,favoriteActions'
      before_script:
        - ./scripts/ci/job_hooks/before_e2e.sh "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2" "./dist/app" "-a" || travis_terminate 1
      script: ./scripts/ci/jobs/affected-project-with.sh -target e2e -options "--suite=editActions,favoriteActions"
      after_script:
        - ./scripts/ci/job_hooks/after_e2e.sh

    - name: 'Test Suites: libraryActions'
      before_script:
        - ./scripts/ci/job_hooks/before_e2e.sh "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2" "./dist/app" "-a" || travis_terminate 1
      script: ./scripts/ci/jobs/affected-project-with.sh -target e2e -options "--suite=libraryActions"
      after_script:
        - ./scripts/ci/job_hooks/after_e2e.sh

    - name: 'Test Suites: shareActions'
      before_script:
        - ./scripts/ci/job_hooks/before_e2e.sh "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2" "./dist/app" "-a" || travis_terminate 1
      script: ./scripts/ci/jobs/affected-project-with.sh -target e2e -options "--suite=shareActions"
      after_script:
        - ./scripts/ci/job_hooks/after_e2e.sh

    - name: 'Test Suites: uploadDownloadActions'
      before_script:
        - ./scripts/ci/job_hooks/before_e2e.sh "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2" "./dist/app" "-a" || travis_terminate 1
      script: ./scripts/ci/jobs/affected-project-with.sh -target e2e -options "--suite=uploadDownloadActions"
      after_script:
        - ./scripts/ci/job_hooks/after_e2e.sh

    - name: 'Test Suites: viewer,infoDrawer,extensions'
      before_script:
        - ./scripts/ci/job_hooks/before_e2e.sh "$S3_DBP_FOLDER/alfresco-content-app.tar.bz2" "./dist/app" "-a" || travis_terminate 1
      script: ./scripts/ci/jobs/affected-project-with.sh -target e2e -options "--suite=viewer,infoDrawer,extensions"
      after_script:
        - ./scripts/ci/job_hooks/after_e2e.sh

    - stage: Publish Docker Registry
      name: Publish Docker Registry
      script: ./scripts/travis/deploy/publish.sh "app"

    - stage: Release Tag
      script: ./scripts/travis/release/git-tag.sh

    - stage: Trigger DW
      script: ./scripts/trigger-travis.sh --pro --branch $TRAVIS_BRANCH Alfresco alfresco-digital-workspace-app $TRAVIS_ACCESS_TOKEN

notifications:
  slack:
    on_pull_requests: false
    rooms:
      secure: 'qcTP/+rhVweMSZZAQMPz4sW7boS8XC0RX1SPYgg7hIfxBr9747WpRLkJ1sirkVaXI/6XfYAyl42CTfPmTuJxIC+co/NSnEDknwVsnKZd0O/ykTpo+mxIN4BTZX8dm+gELR5IEYQPs+Yki3ZnD9b+0mCK1yD8JallKCQeE2U9BhzZhP/Fn0ce35EulybNp3QQDaox0XC+7gadMdxlvK8mzP1scw76wRLtx25QLxxV+OwEw0bzyh8y3onfjHfnoDcUQWRTNdnjapzmgf1LNdC202A5kwp5sJggfSDr+ActRqaMvv4BbMsFpdan34B6zPQJfyZL1r8IB8O8BEKcAaOUVcTjnZAOom8kHS8F07/mo5xnNYmV8oNX2/egr1CiG4U0EAGF2XGqM+vetYnF88LTEzy84kVxmSwKGVfzlGOyTplMXJ1iCENndtfWm1AXhAFj5RSsSAZg6IStTM+mcpnC75moEwQtj8bTenwehHz1HQAjQX7xeTQo27SxDc7oqp1ReyXCllMjKxckjVGmp2j6yxn1Jl55kivBj57vluLtEtziOGluVELP5E2fV0VAuErNhnjLm4LJARVN76PQaTOXYwATVVJJDhb/77TesvxQsr3VfiROEKm7QB7IDFjghjLLisSX67JQ5+7K/qMlqf9+9hNw4n0v1eMylVjt+gyxspc='
    on_failure: always
    on_success: change
    template:
      - 'Repo `%{repository_slug}` *%{result}* build (<%{build_url}|#%{build_number}>) for commit (<%{compare_url}|%{commit}>) on branch `%{branch}`.'
      - 'Author: %{author} Execution time: *%{duration}*'
      - 'Message: %{message}'

