#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

# build Apache Thrift on Travis CI - https://travis-ci.com/

#
# Docker Integration
# see: build/docker/README.md
#

sudo: required
# https://docs.travis-ci.com/user/reference/linux
dist: focal
language: cpp

services:
  - docker

install:
  # https://docs.travis-ci.com/user/common-build-problems/#build-times-out-because-no-output-was-received
  # adding `travis_wait` because kerl building in the docker file takes >10 min for building erlang
  # without printing to stdout, resulting in build failures
  - if [[ `uname` == "Linux" ]]; then travis_wait 40 build/docker/refresh.sh; fi

stages:
  - docker    # docker images
  - thrift    # thrift build jobs

env:
  global:
    - SCRIPT="cmake.sh"
    - BUILD_ARG=""
    - BUILD_ENV="-e CC=gcc -e CXX=g++ -e THRIFT_CROSSTEST_CONCURRENCY=4"
    - DISTRO=ubuntu-focal
    - BUILD_LIBS="CPP C_GLIB JAVA PYTHON TESTING TUTORIALS"  # only meaningful for CMake builds
    - TRAVIS_BUILD_STAGE=test
    # DOCKER_REPO (this works for all builds as a source for docker images - you can override for fork builds in your Travis settings)
    - DOCKER_REPO="thrift/thrift-build"
    # DOCKER_USER (provide in your Travis settings if you want to build and update docker images once, instead of on every job)
    # DOCKER_PASS (same)

jobs:
  include:
    # ========================= stage: docker =========================
    - script: true
      env:
        - JOB="Docker Build ubuntu-focal 20.04 LTS"
        - DISTRO=ubuntu-focal
        - TRAVIS_BUILD_STAGE=docker
    - script: true
      env:
        - JOB="Docker Build ubuntu-jammy 22.04 LTS"
        - DISTRO=ubuntu-jammy
        - TRAVIS_BUILD_STAGE=docker
    - script: true
      env:
        - JOB="Docker Build ubuntu-noble 24.04 LTS"
        - DISTRO=ubuntu-noble
        - TRAVIS_BUILD_STAGE=docker

    # ========================= stage: thrift =======================
    # ------------------------- phase: cross ------------------------
    - stage: thrift
      script: build/docker/run.sh
      env:
        - JOB="Cross Language Tests (Binary Protocol)"
        - SCRIPT="cross-test.sh"
        - BUILD_ARG="-'(binary)'"

    - stage: thrift
      script: build/docker/run.sh
      env:
        - JOB="Cross Language Tests (Header, JSON Protocols)"
        - SCRIPT="cross-test.sh"
        - BUILD_ARG="-'(header|json)'"

    - stage: thrift
      script: build/docker/run.sh
      env:
        - JOB="Cross Language Tests (Compact and Multiplexed Protocols)"
        - SCRIPT="cross-test.sh"
        - BUILD_ARG="-'(compact|multiplexed)'"

    # ------------------------- phase: sca --------------------------
    # QA jobs for code analytics and metrics
    - stage: thrift
      script: build/docker/run.sh
      env:
        - JOB="Static Code Analysis"
        - SCRIPT="sca.sh"

    # C and C++ undefined behavior.
    # A binary crashes if undefined behavior occurs and produces a stack trace.
    # python is disabled, see: THRIFT-4360
    - script: build/docker/run.sh
      env:
        - JOB="UBSan"
        - SCRIPT="ubsan.sh"
        - BUILD_ARG="--without-python --without-py3"

    # ------------------------- phase: autotools --------------------
    # TODO: Remove them once migrated to CMake

    # TODO fix the missing python2 deps or get rid of python2
    # - script: build/docker/run.sh
    #   env:
    #     - JOB="Autotools (Ubuntu Jammy)"
    #     - DISTRO=ubuntu-jammy
    #     - SCRIPT="autotools.sh"

    - script: build/docker/run.sh
      env:
        - JOB="Autotools (Ubuntu Focal)"
        - DISTRO=ubuntu-focal
        - SCRIPT="autotools.sh"

    # ------------------------- phase: cmake ------------------------
    - script: build/docker/run.sh
      env:
        - JOB="CMake"
        - BUILD_ARG="-DCMAKE_BUILD_TYPE=Debug"

    - script: build/docker/run.sh
      env:
        - JOB="CMake"
        - BUILD_ARG="-DCMAKE_BUILD_TYPE=Release"

    # ------------------------- phase: dist -------------------------
    - script: build/docker/run.sh
      env:
        - JOB="make dist"
        - SCRIPT="make-dist.sh"

    - script: build/docker/run.sh
      env:
        - JOB="Debian Packages"
        - SCRIPT="dpkg.sh"

    # ------------------------- phase: coverity ---------------------
    # We build the coverity scan build once monthly using a travis cron job
    - if: (env(COVERITY_SCAN_NOTIFICATION_EMAIL) IS present) AND (branch IN (master)) AND (type IN (cron))
      script: build/docker/run.sh
      env:
        - JOB="Coverity Scan"
        - SCRIPT="covscan.sh"

    # ------------------------- phase: swift ------------------------
    # We lint the podspec
    - os: osx
      osx_image: xcode11.3
      language: swift
      script:
        - gem update cocoapods
        - pod lib lint --allow-warnings --swift-version=5.1
      env:
        - JOB="pod lib lint"

  ### ------------------------- phase: osx --------------------------
  # disabled due to the time delays it imposes on build jobs
  # - os: osx
  #   osx_image: xcode9
  #   script: build/docker/scripts/autotools.sh

