# This file is used to configure the Travis CI tests of MCUdude_corefiles

# Although sudo is no longer required by arduino-ci-script since the 1.0.0 release, for some reason setting "sudo: false" causes the Travis CI build time to significantly increase so this setting is left as "sudo: required"
sudo: required


env:
  global:
    # The Arduino IDE will be installed at ${APPLICATION_FOLDER}/arduino
    - APPLICATION_FOLDER="${HOME}/arduino-ide"
    - SKETCHBOOK_FOLDER="${HOME}/Arduino"


install:
  # Check for tabs
  - "if grep --line-number --recursive --binary-files=without-match --exclude-dir=.git --exclude-dir=travis-ci/arduino-ci-script --regexp=$'\t' .; then echo 'Tab found.'; false; fi"

  # Check for non-Unix line endings
  - "if grep --files-with-matches --recursive --binary-files=without-match --exclude-dir=.git --exclude-dir=travis-ci/arduino-ci-script --regexp=$'\r$' .; then echo 'Non-Unix EOL detected.'; false; fi"

  # Install the script used to simplify use of Travis CI for testing Arduino projects
  - source "${TRAVIS_BUILD_DIR}/travis-ci/arduino-ci-script/arduino-ci-script.sh"

  # These functions can be used to get verbose output for debugging the script
  # set_script_verbosity can be set to values from 0 - 2 (verbosity off - maximum verbosity)
  #- set_script_verbosity 1
  # Setting set_verbose_output_during_compilation to true is the same as File > Preferences > Show verbose output during > compilation (check) in the Arduino IDE
  #- set_verbose_output_during_compilation "true"

  - set_application_folder "$APPLICATION_FOLDER"
  - set_sketchbook_folder "$SKETCHBOOK_FOLDER"

  # The oldest version of the Arduino IDE that MightyCore's platform.txt is compatible with is 1.6.2 but that IDE version has a bug that interferes with other installations of the IDE so I'm starting from 1.6.3
  - install_ide "1.6.3" "newest"

  # Install MightyCore
  - install_package "https://github.com/MCUdude/MightyCore/archive/master.zip"
  # Replace the core with the current version from this repository
  - rm --force --recursive --verbose "${SKETCHBOOK_FOLDER}/hardware/MightyCore-master/avr/cores/MCUdude_corefiles/*"
  - cp --force --recursive --verbose "$TRAVIS_BUILD_DIR"/* "${SKETCHBOOK_FOLDER}/hardware/MightyCore-master/avr/cores/MCUdude_corefiles"

  # MegaCore
  - install_package "https://github.com/MCUdude/MegaCore/archive/master.zip"
  - rm --force --recursive --verbose "${SKETCHBOOK_FOLDER}/hardware/MegaCore-master/avr/cores/MCUdude_corefiles/*"
  - cp --force --recursive --verbose "$TRAVIS_BUILD_DIR"/* "${SKETCHBOOK_FOLDER}/hardware/MegaCore-master/avr/cores/MCUdude_corefiles"

  # MajorCore
  - install_package "https://github.com/MCUdude/MajorCore/archive/master.zip"
  - rm --force --recursive --verbose "${SKETCHBOOK_FOLDER}/hardware/MajorCore-master/avr/cores/MCUdude_corefiles/*"
  - cp --force --recursive --verbose "$TRAVIS_BUILD_DIR"/* "${SKETCHBOOK_FOLDER}/hardware/MajorCore-master/avr/cores/MCUdude_corefiles"

  # MiniCore
  - install_package "https://github.com/MCUdude/MiniCore/archive/master.zip"
  - rm --force --recursive --verbose "${SKETCHBOOK_FOLDER}/hardware/MiniCore-master/avr/cores/MCUdude_corefiles/*"
  - cp --force --recursive --verbose "$TRAVIS_BUILD_DIR"/* "${SKETCHBOOK_FOLDER}/hardware/MiniCore-master/avr/cores/MCUdude_corefiles"


script:
  # build_sketch arguments: sketch name, fqbn, allow failure, IDE version/list/range
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MightyCore-master:avr:1284:pinout=standard,variant=modelP,BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MightyCore-master:avr:644:pinout=standard,variant=modelP,BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MightyCore-master:avr:324:pinout=standard,variant=modelP,BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MightyCore-master:avr:164:pinout=standard,variant=modelP,BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MightyCore-master:avr:32:pinout=standard,BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MightyCore-master:avr:16:pinout=standard,BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MightyCore-master:avr:8535:pinout=standard,BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"

  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MegaCore-master:avr:2561:BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MegaCore-master:avr:2560:pinout=mega_pinout,BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MegaCore-master:avr:1281:BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MegaCore-master:avr:1280:pinout=mega_pinout,BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MegaCore-master:avr:640:pinout=mega_pinout,BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MegaCore-master:avr:128:BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MegaCore-master:avr:64:BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"

  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MajorCore-master:avr:162:BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MajorCore-master:avr:8515:BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"

  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MiniCore-master:avr:328:variant=modelP,BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MiniCore-master:avr:168:variant=modelP,BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MiniCore-master:avr:88:variant=modelP,BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MiniCore-master:avr:48:variant=modelP,BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"
  - build_sketch "${APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "MiniCore-master:avr:8:BOD=2v7,LTO=Os,clock=16MHz_external" "false" "all"


after_script:
  # Determine user name and repository name from TRAVIS_REPO_SLUG so the configuration will automatically adjust to forks
  - USER_NAME="$(echo "$TRAVIS_REPO_SLUG" | cut -d'/' -f 1)"
  - REPOSITORY_NAME="$(echo "$TRAVIS_REPO_SLUG" | cut -d'/' -f 2)"
  # Commit a report of the job results to a folder named with the build number in the MCUdude_corefiles branch of the CI-reports repository
  - publish_report_to_repository "$REPORT_GITHUB_TOKEN" "https://github.com/${USER_NAME}/CI-reports.git" "$REPOSITORY_NAME" "build_$(printf "%05d\n" "${TRAVIS_BUILD_NUMBER}")" "false"

  # Print a tab separated report of all sketch verification results to the log
  - display_report


notifications:
  email:
    on_success: never
    on_failure: always
