os: linux
dist: jammy
language: node_js
services: docker
node_js: 20
addons:
  hosts:
    - mariadb.example.com


before_install:
  - git clone https://github.com/mariadb-corporation/connector-test-machine.git


install:
  - |-
    case $TRAVIS_OS_NAME in
      windows)
        powershell -Command Invoke-WebRequest -Uri https://uploader.codecov.io/latest/windows/codecov.exe -Outfile codecov.exe
        ;;
      linux)
        curl -Os https://uploader.codecov.io/latest/linux/codecov
        chmod +x codecov
        ls -lrt
        ;;
    esac
  - |-
    case $TRAVIS_OS_NAME in
      windows)
        choco install -y --force nodejs-lts
        # force refresh path
        export PATH=$(cmd.exe //c "refreshenv > nul & C:\Progra~1\Git\bin\bash -c 'echo \$PATH' ")
        connector-test-machine/launch.bat -t "$srv" -v "$v" -d testn
        ;;
      linux)
        source connector-test-machine/launch.sh -t "$srv" -v "$v" -d testn -l "$local"  -c "$CLEAR_TEXT" -s "$DISABLE_SSL"
        ;;
    esac

env:
  global:
    - RUN_LONG_TEST=1
    - CLEAR_TEXT=0

stages:
  - Minimal
  - name: Enterprise
    if: type = push AND fork = false
  - Community

jobs:
  fast_finish: true
  allow_failures:
    - env: srv=build
    - env: srv=skysql RUN_LONG_TEST=0
    - env: srv=skysql-ha RUN_LONG_TEST=0
    - env: srv=xpand RUN_LONG_TEST=0
  include:
    - stage: Minimal
      env: srv=mariadb v=10.6 local=1 packet=40
      name: "CS 10.6"
    - env: srv=mariadb-es v=10.6
      name: "ES 10.6"
      if: type = push AND fork = false

    - stage: Enterprise
      env: srv=mariadb-es v=10.4
      name: "ES 10.4"
      if: type = push AND fork = false
    - env: srv=mariadb-es v=10.5
      name: "ES 10.5"
      if: type = push AND fork = false
    - env: srv=mariadb-es-test v=23.08
      name: "ES 23.08"
      if: type = push AND fork = false
    - env: srv=maxscale
      name: "Maxscale"
    - env: srv=skysql RUN_LONG_TEST=0
      name: "SkySQL"
    - env: srv=skysql-ha RUN_LONG_TEST=0
      name: "SkySQL with replication"
    - env: srv=xpand RUN_LONG_TEST=0
      name: "Xpand"

    - stage: Community
      env: srv=mariadb v=10.6
      os: windows
      language: shell
      name: "CS 10.6 - Windows"
    - env: srv=mariadb v=10.4 local=1
      dist: bionic
      node_js: 16
      name: "CS 10.4"
    - env: srv=mariadb v=10.5 local=1 DISABLE_SSL=1
      dist: bionic
      node_js: 16
      name: "CS 10.5"
    - env: srv=mariadb v=10.9 local=1
      name: "CS 10.9"
    - env: srv=mariadb v=10.10 local=1
      name: "CS 10.10 - node.js 18"
      node_js: 18
    - env: srv=mariadb v=10.11 local=1
      name: "CS 10.11"
    - env: srv=mariadb v=11.0 local=1
      name: "CS 11.0"
    - env: srv=mariadb v=11.1 local=1
      name: "CS 11.1"
    - env: srv=mariadb v=10.6 local=1
      name: "CS 10.6 - node.js 14"
      node_js: 14
    - env: srv=mariadb v=10.6 local=1 CLEAR_TEXT=1
      node_js: 16
      name: "CS 10.6 - node.js 16"
    - env: srv=mariadb v=10.6 local=1
      name: "CS 10.6 - node.js 20"
      node_js: 20
    - env: srv=mysql v=5.7
      name: "MySQL 5.7"
    - env: srv=mysql v=8.0
      name: "MySQL 8.0"
    - env: srv=mariadb v=10.6 BENCH=1 local=1
      name: "Benchmarks"
      node_js: 18
      dist: focal
    - env: srv=build
      name: "CS build"

script:
  - npm install
  - npm install nyc -g
  - |-
    case $TRAVIS_OS_NAME in
      windows)
        npm run coverage:test
        ;;
      linux)
        npm run test:lint
        if [ -n "$BENCH" ] ; then
          npm install promise-mysql mysql2
          npm install microtime
          npm run benchmark
        else
          npm run coverage:test
        fi
        ;;
    esac

after_success:
  - if [ -z "$BENCH" ] ; then npm run coverage:report; fi

after_failure:
  - if [ "$srv" == "maxscale" ] ; then docker-compose -f ${COMPOSE_FILE} exec -u root maxscale tail -500 /var/log/maxscale/maxscale.log; fi