|
| 1 | +# LibraryBuild.yml |
| 2 | +# Github workflow script to test compile all examples of an Arduino library repository. |
| 3 | +# |
| 4 | +# Copyright (C) 2020 Armin Joachimsmeyer |
| 5 | +# https://github.com/ArminJo/Github-Actions |
| 6 | +# License: MIT |
| 7 | +# |
| 8 | +# Before being able to push to my .github\workflows directories, |
| 9 | +# I had to create a new personal token with workflow enabled at https://github.com/settings/tokens |
| 10 | + |
| 11 | +# This is the name of the workflow, visible on GitHub UI. |
| 12 | +name: LibraryBuild |
| 13 | +on: [push, pull_request] # see: https://help.github.com/en/actions/reference/events-that-trigger-workflows#pull-request-event-pull_request |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: ${{ matrix.arduino-boards-fqbn }} - test compiling examples |
| 18 | + |
| 19 | + runs-on: ubuntu-latest # I picked Ubuntu to use shell scripts. |
| 20 | + |
| 21 | + env: |
| 22 | + # Space separated list without double quotes around the list. |
| 23 | + # If you need a library with a space in its name, like Adafruit NeoPixel or Adafruit INA219, you must use double quotes |
| 24 | + # around the name and have at least 2 entries, where the first must be without double quotes! You may use Servo as dummy entry. |
| 25 | + REQUIRED_LIBRARIES: EspSoftwareSerial |
| 26 | + |
| 27 | + # Global color definitions for output colors |
| 28 | + RED: '\033[0;31m' |
| 29 | + GREEN: '\033[0;32m' |
| 30 | + YELLOW: '\033[1;33m' |
| 31 | + BLUE: '\033[0;34m' |
| 32 | + |
| 33 | + strategy: |
| 34 | + matrix: |
| 35 | + # The matrix will produce one job for each configuration parameter of type `arduino-boards-fqbn` |
| 36 | + # In the Arduino IDE, the fqbn is printed in the first line of the verbose output for compilation as parameter -fqbn=... for the "arduino-builder -dump-prefs" command |
| 37 | + # |
| 38 | + # Examples: arduino:avr:uno, arduino:avr:leonardo, arduino:avr:nano, arduino:avr:mega |
| 39 | + # arduino:sam:arduino_due_x, arduino:samd:arduino_zero_native" |
| 40 | + # ATTinyCore:avr:attinyx5:chip=85,clock=1internal, digistump:avr:digispark-tiny, digistump:avr:digispark-pro |
| 41 | + # STM32:stm32:GenF1:pnum=BLUEPILL_F103C8 |
| 42 | + # esp8266:esp8266:huzzah:eesz=4M3M,xtal=80, esp32:esp32:featheresp32:FlashFreq=80 |
| 43 | + # You may add a suffix behind the fqbn with "|" to specify one board for e.g. different compile options like arduino:avr:uno|trace |
| 44 | + ############################################################################################################# |
| 45 | + arduino-boards-fqbn: |
| 46 | + - arduino:avr:uno |
| 47 | + - arduino:avr:leonardo |
| 48 | + - arduino:avr:mega |
| 49 | + - arduino:sam:arduino_due_x |
| 50 | + - esp8266:esp8266:huzzah:eesz=4M3M,xtal=80 |
| 51 | + - esp32:esp32:featheresp32:FlashFreq=80 |
| 52 | + - STM32:stm32:GenF1:pnum=BLUEPILL_F103C8 |
| 53 | + |
| 54 | + # Choose the right platform for the boards we want to test. (maybe in the future Arduino will automatically do this for you). |
| 55 | + # This works like this: when the fqbn is "arduino:avr:uno" the variable `platform` is set to "arduino:avr". |
| 56 | + # Just take the first 2 token of the fqbn - this cannot be automatically done by GitHub workflow :-( |
| 57 | + # You may exclude specific examples for a board with examples-exclude: Use a space separated list. |
| 58 | + ############################################################################################################# |
| 59 | + include: |
| 60 | + - arduino-boards-fqbn: arduino:avr:uno |
| 61 | + platform: arduino:avr |
| 62 | + |
| 63 | + - arduino-boards-fqbn: arduino:avr:leonardo |
| 64 | + platform: arduino:avr |
| 65 | + |
| 66 | + - arduino-boards-fqbn: arduino:avr:mega |
| 67 | + platform: arduino:avr |
| 68 | + |
| 69 | + - arduino-boards-fqbn: arduino:sam:arduino_due_x |
| 70 | + platform: arduino:sam |
| 71 | + examples-exclude: Example5_LCDDemo # No SoftwareSerial available. Space separated list of (unique substrings of) example names to exclude in build |
| 72 | + |
| 73 | + - arduino-boards-fqbn: esp8266:esp8266:huzzah:eesz=4M3M,xtal=80 |
| 74 | + platform: esp8266:esp8266 |
| 75 | + |
| 76 | + - arduino-boards-fqbn: esp32:esp32:featheresp32:FlashFreq=80 |
| 77 | + platform: esp32:esp32 |
| 78 | + |
| 79 | + - arduino-boards-fqbn: STM32:stm32:GenF1:pnum=BLUEPILL_F103C8 |
| 80 | + platform: STM32:stm32 |
| 81 | + |
| 82 | +###################################################### |
| 83 | +# End of configuration, start of fixed script section |
| 84 | +###################################################### |
| 85 | + |
| 86 | + # Do not cancel all jobs / architectures if one job fails |
| 87 | + fail-fast: false |
| 88 | + |
| 89 | + # This is the list of steps this job will run. |
| 90 | + steps: |
| 91 | + |
| 92 | + # First of all, we clone the repo using the `checkout` action. |
| 93 | + - name: Checkout |
| 94 | + uses: actions/checkout@master |
| 95 | + |
| 96 | + # We use the `arduino/setup-arduino-cli` action to install and |
| 97 | + # configure the Arduino CLI on the system. |
| 98 | + - name: Setup Arduino CLI |
| 99 | + |
| 100 | + |
| 101 | + - name: Link this repository as Arduino library |
| 102 | + run: | |
| 103 | + mkdir -p $HOME/Arduino/libraries |
| 104 | + ln -s $PWD $HOME/Arduino/libraries/. |
| 105 | +
|
| 106 | + - name: Install platform from build matrix |
| 107 | + env: |
| 108 | + FQBN: ${{ matrix.arduino-boards-fqbn }} |
| 109 | + run: | |
| 110 | + arduino-cli core update-index |
| 111 | + if [ "${{ matrix.platform }}" == "" ]; then echo -e ""$RED"ERROR: platform missing for board ${FQBN%|*}. Check your matrix.includes entries"; exit 1; fi |
| 112 | + if [[ ${{ matrix.platform }} != *"arduino"* && ! -f ./arduino-cli.yaml ]]; then echo -e ""$RED"Non Arduino platform ${{ matrix.platform }} requested, but file arduino-cli.yaml is missing."; exit 1; fi |
| 113 | + arduino-cli core install ${{ matrix.platform }} # for each job / board one platform is installed |
| 114 | + arduino-cli board listall |
| 115 | + if [ ${{ matrix.platform }} == "esp32:esp32" ]; then pip install pyserial; fi |
| 116 | +
|
| 117 | + - name: List installed boards with their FQBN |
| 118 | + run: | |
| 119 | + arduino-cli board listall |
| 120 | + # ls -l $HOME/.arduino15/packages/ # I see only arduino and one of the Attiny cores but not all 3 together |
| 121 | + # echo -e HOME=\"$HOME\" # /home/runner |
| 122 | + # echo PWD=$PWD # /home/runner/work/Github-Actions-Test/Github-Actions-Test |
| 123 | + # which arduino-cli # /opt/hostedtoolcache/arduino-cli/0.9.0/x64/arduino-cli |
| 124 | +
|
| 125 | + - name: Install libraries |
| 126 | + run: if [[ "$REQUIRED_LIBRARIES" != "" ]]; then arduino-cli lib install ${{ env.REQUIRED_LIBRARIES }}; fi |
| 127 | + |
| 128 | + # Finally, we compile the sketch, using the FQBN that was set in the build matrix. |
| 129 | + - name: Compile all examples |
| 130 | + env: |
| 131 | + FQBN: ${{ matrix.arduino-boards-fqbn }} |
| 132 | + BUILD_PROPERTIES: ${{ toJson(matrix.examples-build-properties) }} |
| 133 | + run: | |
| 134 | + BUILD_PROPERTIES=${BUILD_PROPERTIES#\{} # remove "{" |
| 135 | + # if matrix.examples-build-properties are specified, create an associative shell array |
| 136 | + if [[ $BUILD_PROPERTIES != "null" ]]; then declare -A PROP_MAP="( $(echo $BUILD_PROPERTIES | sed -E 's/"(\w*)": *([^,}]*)[,}]/\[\1\]=\2/g' ) )"; fi |
| 137 | + echo -e "Compiling examples for board ${{ matrix.arduino-boards-fqbn }} \n" |
| 138 | + EXAMPLES=($(find . -name "*.ino")) |
| 139 | + for example in "${EXAMPLES[@]}"; do # Loop over all example directories |
| 140 | + EXAMPLE_NAME=$(basename $(dirname $example)) |
| 141 | + if [[ "${{ matrix.examples-exclude }}" == *"$EXAMPLE_NAME"* ]]; then |
| 142 | + echo -e "Skipping $EXAMPLE_NAME \xe2\x9e\x9e" # Right arrow |
| 143 | + else |
| 144 | + # check if there is an entry in the associative array and create a compile parameter |
| 145 | + echo -n "Compiling $EXAMPLE_NAME " |
| 146 | + if [[ "${PROP_MAP[$EXAMPLE_NAME]}" != "" ]]; then echo -n "with ${PROP_MAP[$EXAMPLE_NAME]} "; fi |
| 147 | + build_stdout=$(arduino-cli compile --verbose --warnings all --fqbn ${FQBN%|*} --build-properties compiler.cpp.extra_flags="${PROP_MAP[$EXAMPLE_NAME]}" $(dirname $example) 2>&1); |
| 148 | + if [ $? -ne 0 ]; then |
| 149 | + echo -e ""$RED"\xe2\x9c\x96" # If ok output a green checkmark else a red X and the command output. |
| 150 | + exit_code=1 |
| 151 | + echo -e "$build_stdout \n" |
| 152 | + else |
| 153 | + echo -e ""$GREEN"\xe2\x9c\x93" |
| 154 | + fi |
| 155 | + fi |
| 156 | + done |
| 157 | + exit $exit_code |
| 158 | + shell: bash {0} # Needed to avoid an exit at first error |
0 commit comments