|
| 1 | +name: Build Examples with Arduino CLI |
| 2 | + |
| 3 | +# Triggers the workflow on push or pull request events |
| 4 | +on: [push, pull_request] |
| 5 | + |
| 6 | +jobs: |
| 7 | + build: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + if: "!contains(github.event.head_commit.message, 'ci skip')" |
| 10 | + |
| 11 | + strategy: |
| 12 | + matrix: |
| 13 | + example: |
| 14 | + [ |
| 15 | + examples/single_sensor/, |
| 16 | + examples/simple_logging/, |
| 17 | + examples/simple_logging_LearnEnviroDIY/, |
| 18 | + examples/DRWI_CitSci/, |
| 19 | + examples/DRWI_LTE/, |
| 20 | + examples/DRWI_NoCellular/, |
| 21 | + examples/double_logger/, |
| 22 | + examples/baro_rho_correction/, |
| 23 | + examples/data_saving/, |
| 24 | + examples/logging_to_MMW/, |
| 25 | + examples/logging_to_ThingSpeak/, |
| 26 | + ] |
| 27 | + # arduino-platform: ['EnviroDIY:avr', 'arduino:avr', 'arduino:samd', 'adafruit:samd'] |
| 28 | + fqbn: |
| 29 | + [ |
| 30 | + 'EnviroDIY:avr:envirodiy_mayfly', |
| 31 | + 'arduino:avr:mega', |
| 32 | + 'arduino:samd:mzero_bl', |
| 33 | + 'adafruit:samd:adafruit_feather_m0', |
| 34 | + 'SODAQ:samd:sodaq_autonomo', |
| 35 | + ] |
| 36 | + |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v2 |
| 39 | + |
| 40 | + - name: Set environment variable for library installation source |
| 41 | + run: | |
| 42 | + if [[ -z "${GITHUB_HEAD_REF}" ]]; then |
| 43 | + echo "::debug::Push to commit ${GITHUB_SHA}" |
| 44 | + echo "LIBRARY_INSTALL_ZIP=https://github.com/${GITHUB_REPOSITORY}/archive/${GITHUB_SHA}.zip" >> $GITHUB_ENV |
| 45 | + else |
| 46 | + echo "::debug::Pull Request from the ${GITHUB_HEAD_REF} branch" |
| 47 | + echo "LIBRARY_INSTALL_ZIP=https://github.com/${GITHUB_REPOSITORY}/archive/${GITHUB_HEAD_REF}.zip" >> $GITHUB_ENV |
| 48 | + fi |
| 49 | +
|
| 50 | + # We use the `arduino/setup-arduino-cli` action to install and |
| 51 | + # configure the Arduino CLI on the system. |
| 52 | + - name: Setup Arduino CLI |
| 53 | + uses: arduino/setup-arduino-cli@v1 |
| 54 | + |
| 55 | + - name: Restore or Cache Arduino Platforms and Libraries |
| 56 | + uses: actions/cache@v2.1.5 |
| 57 | + id: cache_arduino |
| 58 | + with: |
| 59 | + path: home/arduino |
| 60 | + # if nothing in the dependencies.json file has changed, then it will |
| 61 | + # be a "cache hit" and we can restore libraries from cache and not |
| 62 | + # download them. If it has changed we have to re-download. |
| 63 | + key: ${{ hashFiles('./continuous_integration/dependencies.json') }} |
| 64 | + |
| 65 | + # Install cores and library dependencies for the Arduino CLI, iff no cache |
| 66 | + - name: Install the Arduino libraries |
| 67 | + if: steps.cache_arduino.outputs.cache-hit != 'true' |
| 68 | + run: | |
| 69 | + chmod +x continuous_integration/install-deps-arduino-cli.sh |
| 70 | + sh continuous_integration/install-deps-arduino-cli.sh |
| 71 | +
|
| 72 | + # Install ModularSensors for the Arduino CLI |
| 73 | + - name: Install the testing version of Modular Sensors for the Arduino CLI |
| 74 | + run: | |
| 75 | + echo "::debug::Deleting any archived zips" |
| 76 | + rm -f home/arduino/downloads/ModularSensors.zip |
| 77 | + echo "::debug::Downloading library zip" |
| 78 | + curl -L --retry 15 --retry-delay 0 ${{ env.LIBRARY_INSTALL_ZIP }} --create-dirs -o home/arduino/downloads/ModularSensors.zip |
| 79 | + echo "::debug::Unzipping the library" |
| 80 | + unzip -o home/arduino/downloads/ModularSensors.zip -d home/arduino/downloads/ -x "*.git/*" "continuous_integration/*" "docs/*" "examples/*" |
| 81 | + echo "::debug::Ensuring no old directories exist" |
| 82 | + rm -r -f home/arduino/user/libraries/ModularSensors |
| 83 | + echo "::debug::Creating a new directory for the testing version of Modular sensors" |
| 84 | + mkdir -p home/arduino/user/libraries/ModularSensors |
| 85 | + echo "::debug::Moving the unzipped library to the new directory" |
| 86 | + if [[ -z "${GITHUB_HEAD_REF}" ]]; then |
| 87 | + mv home/arduino/downloads/ModularSensors-${GITHUB_SHA}/* home/arduino/user/libraries/ModularSensors |
| 88 | + else |
| 89 | + mv home/arduino/downloads/ModularSensors-${GITHUB_HEAD_REF}/* home/arduino/user/libraries/ModularSensors |
| 90 | + fi |
| 91 | + echo "::debug::Updating the library index" |
| 92 | + arduino-cli --config-file continuous_integration/arduino_cli.yaml lib update-index |
| 93 | + echo "::debug::Listing libraries detected by the Arduino CLI" |
| 94 | + arduino-cli --config-file continuous_integration/arduino_cli.yaml lib list |
| 95 | + echo "::debug::Listing the contents of the Arduino library directory" |
| 96 | + ls home/arduino/user/libraries |
| 97 | +
|
| 98 | + - name: Set appropriate build flags for Arduino CLI |
| 99 | + run: | |
| 100 | + echo "::group::Setting build flags" |
| 101 | + echo "::debug::Setting build flags for ${{ matrix.fqbn }}" |
| 102 | + if [ ${{ matrix.fqbn }} = 'EnviroDIY:avr:envirodiy_mayfly' ]; then |
| 103 | + echo "EXTRA_BUILD_FLAGS=-DNEOSWSERIAL_EXTERNAL_PCINT" >> $GITHUB_ENV |
| 104 | + fi |
| 105 | + if [ ${{ matrix.fqbn }} = 'arduino:avr:mega' ]; then |
| 106 | + echo "EXTRA_BUILD_FLAGS=-DNEOSWSERIAL_EXTERNAL_PCINT" >> $GITHUB_ENV |
| 107 | + fi |
| 108 | + if [ ${{ matrix.fqbn }} = 'arduino:samd:mzero_bl' ]; then |
| 109 | + echo "EXTRA_BUILD_FLAGS=-DNEOSWSERIAL_EXTERNAL_PCINT -DARDUINO_SAMD_ZERO -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804d -DUSBCON" >> $GITHUB_ENV |
| 110 | + fi |
| 111 | + if [ ${{ matrix.fqbn }} = 'adafruit:samd:adafruit_feather_m0' ]; then |
| 112 | + echo "EXTRA_BUILD_FLAGS=-DNEOSWSERIAL_EXTERNAL_PCINT -DARDUINO_SAMD_ZERO -DARM_MATH_CM0PLUS -DADAFRUIT_FEATHER_M0 -D__SAMD21G18A__ -DUSB_VID=0x239A -DUSB_PID=0x800B -DUSBCON -DUSB_CONFIG_POWER=100" >> $GITHUB_ENV |
| 113 | + fi |
| 114 | + if [ ${{ matrix.fqbn }} = 'SODAQ:samd:sodaq_autonomo' ]; then |
| 115 | + echo "EXTRA_BUILD_FLAGS=-DNEOSWSERIAL_EXTERNAL_PCINT -DVERY_LOW_POWER -D__SAMD21J18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804d -DUSBCON" >> $GITHUB_ENV |
| 116 | + fi |
| 117 | + echo "::endgroup::" |
| 118 | +
|
| 119 | + - name: Compile examples using the Arduino CLI |
| 120 | + env: |
| 121 | + BUILD_EXAMPLE: ${{ matrix.example }} |
| 122 | + run: | |
| 123 | + echo "::debug::Running Arduino CLI for ${{ matrix.example }}" |
| 124 | + arduino-cli --config-file continuous_integration/arduino_cli.yaml compile --clean --build-property "build.extra_flags=$EXTRA_BUILD_FLAGS" --fqbn ${{ matrix.fqbn }} $BUILD_EXAMPLE |
| 125 | +
|
| 126 | + - name: Uninstall testing version of Modular Sensors before caching |
| 127 | + run: arduino-cli --config-file continuous_integration/arduino_cli.yaml lib uninstall ModularSensors |
0 commit comments