language: cpp

matrix:
  include:
    - os: linux
      compiler: gcc
      cache: apt
      dist: xenial

env:
  global:
    - PROJECT_NAME=PortaPack-HAVOC
    - SHORT_COMMIT_HASH=`git rev-parse --short HEAD`
    - VERSION_STRING=nightly-$SHORT_COMMIT_HASH
    - BUILD_DATE="`date +%Y-%m-%d`"
    - BUILD_NAME="$PROJECT_NAME-$BUILD_DATE-$SHORT_COMMIT_HASH"
    - ARTEFACT_BASE=$TRAVIS_BUILD_DIR/artefacts/
    - ARTEFACT_PATH=$ARTEFACT_BASE/$BUILD_NAME

notifications:
  irc:
    channels:
      - "chat.freenode.net#portapack"
    template:
      - "%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message}"
      - "Change view : %{compare_url}"
      - "Build details : %{build_url}"
      # TODO: The "build_number.1" in this URL is almost certainly wrong, but correct value not available from Travis?
      - "Firmware download : https://jboone.github.io/portapack-havoc-nightly/"

before_install:
  - sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa -y
  - sudo apt-get update -q
  - sudo apt-get install gcc-arm-embedded -y

script:
  # TODO: Introduce top-level Makefile, this is lame.
  - sed -e "s/\#set(VERSION.*/set(VERSION \"$VERSION_STRING\")/" -i".bak" CMakeLists.txt
  - mkdir build/
  - pushd build/
  - cmake ..
  - make firmware
  - popd

after_success:
  - mkdir -p $ARTEFACT_PATH
  # Copy firmware to firmware-bin directory
  - cd $TRAVIS_BUILD_DIR/build
  - cp firmware/portapack-h1-havoc.bin $ARTEFACT_PATH/
  - cp hackrf/firmware/hackrf_usb/hackrf_usb.dfu $ARTEFACT_PATH/
  - cd $TRAVIS_BUILD_DIR
  - cp LICENSE $ARTEFACT_PATH/
  # Build the archive
  - cd $ARTEFACT_BASE
  - tar -cJvf $ARTEFACT_BASE/$BUILD_NAME.tar.xz $BUILD_NAME
  - md5sum --binary $BUILD_NAME.tar.xz >MD5SUMS
  - sha256sum --binary $BUILD_NAME.tar.xz >SHA256SUMS

addons:
  apt:
    packages:
      - coreutils
      - tar
      - sed
      - cmake
      - dfu-util

deploy:
  provider: script
  skip-cleanup: true
  script: bash $TRAVIS_BUILD_DIR/tools/deploy-nightly.sh
  on:
    branch: master
