# This Travis CI config calls scripts that use the following defaults,
# which can (and some should) be overridden in the Travis CI repo
# settings.
#
# Package build `build_docker` script:
# - IMAGE:  dovetailautomata/mk-cross-builder
#   Docker image to pull for build
# - MK_PACKAGE_VERBOSE:  false
#   Build verbosely with `make V=1`
# - JOBS:  2
#   Make parallel jobs, `make -j2`
# - DEBIAN_SUITE:  experimental
#   Debian package suite
# - MAJOR_MINOR_VERSION:  0.1
#   Override Machinekit package base version
# - PKGSOURCE:  ${TRAVIS_REPO}
#   Identifier added to package release suggesting package origin
# - TEST_ARGS:  (empty)
#   For CMD=test only; set as needed for debugging, e.g. `-v tests/hm2-idrom`
# - TEST_DEBUG:  false
#   For CMD=test only; set to `true` to send test debug output to stderr
#
# Package upload `build_upload_packagecloud` script:
# - PACKAGECLOUD_USER, PACKAGECLOUD_TOKEN, PACKAGECLOUD_REPO: no defaults
#   Packagecloud.io user credentials and package repository
# - DEPLOY_BRANCH: master
#   Git branch for which to deploy packages

sudo: required

notifications:
  email:
    on_success: never
    on_failure: always
  webhooks:
    urls:
      - $GITTER_IM_URL
    on_success: change
    on_failure: always
    on_start: never

# Cache:  In $HOME/.ccache; inserts /usr/lib/ccache into $PATH
# https://docs.travis-ci.com/user/caching/#ccache-cache
language: c
cache: ccache

services:
  - docker

env:
  global:
    - IMAGE=${IMAGE:-dovetailautomata/mk-cross-builder}
    - MK_PACKAGE_VERBOSE=${MK_PACKAGE_VERBOSE:-false}
    - JOBS=${JOBS:-2}
    - TEST_DEBUG=false
    - TEST_ARGS=
  matrix:
    # Tests
    # - Reduce total build time by starting longest jobs first
    - TAG=amd64_10   CMD=test
    - TAG=amd64_9    CMD=test
    - TAG=amd64_8    CMD=test
    # Packages
    # - Buster
    - TAG=amd64_10    CMD=deb
    - TAG=i386_10     CMD=deb
    - TAG=armhf_10    CMD=deb
    # - Stretch
    - TAG=amd64_9    CMD=deb
    - TAG=i386_9     CMD=deb
    - TAG=armhf_9    CMD=deb
    # - Jessie
    - TAG=amd64_8    CMD=deb
    - TAG=i386_8     CMD=deb
    - TAG=armhf_8    CMD=deb

addons:
  apt:
    packages:
    - lftp
    - sshpass

before_install:
  # Show environment for debugging purposes
  - env
  # Pull the Docker build image
  - docker pull "${IMAGE}:${TAG}"
  # Clear ccache stats
  - ccache -z
  # Install the packagecloud gem for pushing packages
  - gem install package_cloud

script:
  - scripts/build_docker -i $IMAGE -t $TAG -c $CMD

after_success:
  # Upload packages to packagecloud.io
  - test -z "$PACKAGECLOUD_USER" || gem install package_cloud
  - test -z "$PACKAGECLOUD_USER" || scripts/build_packagecloud_upload
  # Show ccache stats
  - ccache -s
