|
| 1 | +name: Hil unity library checks |
| 2 | + |
| 3 | +# on which event should we start push, pull request or schedule dispatches |
| 4 | +on: |
| 5 | + - push |
| 6 | + - pull_request |
| 7 | + |
| 8 | +env: |
| 9 | + TEST_VERSION: 1.0.0 |
| 10 | + |
| 11 | +# This template runes multiple workflows |
| 12 | +jobs: |
| 13 | + |
| 14 | + |
| 15 | + ############################################################################# |
| 16 | + # This action sets common variables for the flow and |
| 17 | + # identifies the libs to compile |
| 18 | + setup: |
| 19 | + |
| 20 | + # we run this on self hosted runner, use labels to be more specific |
| 21 | + # add specific names if there are some, otherwise self-hosted, X64, Linux are the default ones |
| 22 | + runs-on: |
| 23 | + - self-hosted |
| 24 | + - X64 |
| 25 | + - Linux |
| 26 | + |
| 27 | + steps: |
| 28 | + # checkout the latest github action code |
| 29 | + - name: Checkout actions |
| 30 | + uses: actions/checkout@v4 |
| 31 | + |
| 32 | + # checkout the latest arduino-cli compiler |
| 33 | + - name: Setup Arduino CLI |
| 34 | + uses: arduino/setup-arduino-cli@master |
| 35 | + |
| 36 | + # Update the arduino code. Attention this does not setup XMC packages as this are set inside the self hosted runner |
| 37 | + # the arduino board support packages can be updated automatically |
| 38 | + # the XMC board support package is only linked inside the self hosted runner, which allows |
| 39 | + # to use none official and beta versions |
| 40 | + # arduino-cli core install "infineon:xmc" |
| 41 | + - name: Install/Update Arduino Platform |
| 42 | + run: | |
| 43 | + arduino-cli core update-index |
| 44 | + arduino-cli core install "arduino:avr" |
| 45 | +
|
| 46 | + # Fetch variables and move them to the GITHUB_OUTPUT and fetch HIL information |
| 47 | + - id: startup |
| 48 | + run: | |
| 49 | + # switch on the HIL |
| 50 | + cd /opt/runner_support/ |
| 51 | + REPO="$(basename "$GITHUB_REPOSITORY")" |
| 52 | + ./py_checkusb.py --switch repo --namelist $REPO --onoff on |
| 53 | +
|
| 54 | + # set the hil-unity-checks |
| 55 | + hil=$(./py_checkusb.py --readyaml $GITHUB_WORKSPACE/tests/Unity/hil-unity-checklist.yaml --json) |
| 56 | + echo "hil=${hil}" >> $GITHUB_OUTPUT |
| 57 | +
|
| 58 | + # fetch unity libraries |
| 59 | + readarray -t data < <(echo $hil | jq -r '.|keys[]') |
| 60 | + export dev=$(jq --compact-output --null-input '$ARGS.positional' --args -- "${data[@]}") |
| 61 | + echo "devices=${dev}" >> $GITHUB_OUTPUT |
| 62 | + echo "devices=${dev}" |
| 63 | +
|
| 64 | + # Connect the GITHUB_OUTPUT to the variables and the workflow output mechanism |
| 65 | + outputs: |
| 66 | + hil: ${{ steps.startup.outputs.hil }} |
| 67 | + devices: ${{ steps.startup.outputs.devices }} |
| 68 | + |
| 69 | + |
| 70 | + ############################################################################# |
| 71 | + # This step allows HIL (Hardware in the loop), therefore |
| 72 | + # is searches for the given board/sensor combination and tries to find the actual port |
| 73 | + # on the self hosted runner. (see documentation for the board2port finder) |
| 74 | + flash: |
| 75 | + |
| 76 | + # We need a successful build before we can run the deploy |
| 77 | + needs: [setup] |
| 78 | + |
| 79 | + # we run this on self hosted runner, use labels to be more specific |
| 80 | + # add specific names if there are some, otherwise self-hosted, X64, Linux are the default ones |
| 81 | + runs-on: |
| 82 | + - self-hosted |
| 83 | + - X64 |
| 84 | + - Linux |
| 85 | + |
| 86 | + # do not stop if a single job fails |
| 87 | + continue-on-error: true |
| 88 | + |
| 89 | + strategy: |
| 90 | + |
| 91 | + # the code to flash |
| 92 | + matrix: |
| 93 | + # the serials of the hardware boards |
| 94 | + device: ${{ fromJson(needs.setup.outputs.devices) }} |
| 95 | + |
| 96 | + # These are the steps which should run for each combination of fqbn and lib code |
| 97 | + steps: |
| 98 | + # checkout the latest github action code |
| 99 | + - name: Checkout actions |
| 100 | + uses: actions/checkout@v4 |
| 101 | + |
| 102 | + # setup environment |
| 103 | + - name: Environment |
| 104 | + run: | |
| 105 | + cd $HOME |
| 106 | + rm -rf ~/.arduino15/packages/Infineon/hardware/xmc/* |
| 107 | + ln -s $GITHUB_WORKSPACE ~/.arduino15/packages/Infineon/hardware/xmc/$TEST_VERSION |
| 108 | +
|
| 109 | + hil=${{ toJson(needs.setup.outputs.hil) }} |
| 110 | + REPO="$(basename "$GITHUB_REPOSITORY")" |
| 111 | + DEVICE="$(basename ${{ matrix.device }} )" |
| 112 | + LIBRARY=$(echo $hil | jq ".\"${DEVICE}\"" -r --compact-output) |
| 113 | + FQBN=`tr '.' ':' <<<"${DEVICE}"` |
| 114 | +
|
| 115 | + echo "repo=$REPO" >> $GITHUB_ENV |
| 116 | + echo "device=$DEVICE" >> $GITHUB_ENV |
| 117 | + echo "version=$TEST_VERSION" >> $GITHUB_ENV |
| 118 | + echo "library=$LIBRARY" >> $GITHUB_ENV |
| 119 | + echo "fqbn=$FQBN" >> $GITHUB_ENV |
| 120 | +
|
| 121 | + echo "Repo " $REPO |
| 122 | + echo "Device " $DEVICE |
| 123 | + echo "Library " $LIBRARY |
| 124 | + echo "FQBN " $FQBN |
| 125 | + echo "Version " ${TEST_VERSION} |
| 126 | +
|
| 127 | + # Build the test code with make and flash it to the board |
| 128 | + # runs via nested loops: |
| 129 | + # - first loop over the libraries mentioned for a device in the yaml file |
| 130 | + # - selects the serial ids and ports for all devices connected with this device and library |
| 131 | + # - second loop over the examples mentioned below the selected device for a library in the yaml file |
| 132 | + # - third loop over the tests mentioned below the selected example for a device and library in the yaml file |
| 133 | + # - fourth loop over the make commands mentioned below the selected test for a device, example and library in the yaml file |
| 134 | + |
| 135 | + - name: Build |
| 136 | + run: | |
| 137 | + export TMPDIR=$HOME/tmp |
| 138 | + mkdir -p $TMPDIR |
| 139 | + rm -rf $HOME/artefact |
| 140 | + mkdir -p $HOME/artefact |
| 141 | +
|
| 142 | + lib=${{ toJson(env.library) }} |
| 143 | + readarray -t LIBS < <(echo ${lib} | jq ".|keys[]" -r --compact-output) |
| 144 | +
|
| 145 | + # loop over all libs in the unity test yaml |
| 146 | + for LIB in "${LIBS[@]}"; do |
| 147 | + cd /opt/runner_support/ |
| 148 | + readarray -t SERIALS < <(echo $(./py_checkusb.py --type ${LIB} --json) | jq ".\"${LIB}\".\"${{ env.device }}\"|keys[]" -r) |
| 149 | +
|
| 150 | + # check if we have one or more serial numbers for this lib or stop here |
| 151 | + if [[ -z $SERIALS ]]; then |
| 152 | + echo "No serial or library information found" |
| 153 | + exit 0 |
| 154 | + fi |
| 155 | +
|
| 156 | + # loop over all serials and fetch the ports |
| 157 | + declare -a PORTS |
| 158 | + for SERIAL in "${SERIALS[@]}"; do |
| 159 | + PORTS+=($(/opt/runner_support/find_usb.sh $SERIAL)) |
| 160 | + done |
| 161 | +
|
| 162 | + # loop over all examples for one library |
| 163 | + readarray -t EXAMPLES < <(echo $lib | jq ".\"${LIB}\"|keys[]" -r --compact-output) |
| 164 | + for EXAMPLE in "${EXAMPLES[@]}"; do |
| 165 | + echo "==============================================================================================================" |
| 166 | + echo "Run for EXAMPLE: ${EXAMPLE} under LIB: ${LIB}" |
| 167 | + echo "==============================================================================================================" |
| 168 | +
|
| 169 | + # loop over all tests for one example and compile7flash the devices |
| 170 | + readarray -t TESTS < <(echo $lib | jq ".\"${LIB}\".\"${EXAMPLE}\"[]" -r --compact-output) |
| 171 | + for ((idx=0; idx<${#TESTS[@]}; ++idx)); do |
| 172 | + cd $GITHUB_WORKSPACE/tests/Unity/ |
| 173 | + echo "==============================================================================================================" |
| 174 | + echo "Run on index $idx for TEST: ${TESTS[idx]} under EXAMPLE: ${EXAMPLE} and LIB: ${LIB}" |
| 175 | + echo "==============================================================================================================" |
| 176 | + make FQBN=${{ env.fqbn }} PORT=${PORTS[idx]} UNITY_PATH=/opt/runner_support/Unity_github ${TESTS[idx]} |
| 177 | + mkdir -p ~/artefact/${LIB}/${EXAMPLE}/${TESTS[idx]}/ |
| 178 | + mv ./build/build/* ~/artefact/${LIB}/${EXAMPLE}/${TESTS[idx]}/. |
| 179 | + echo "==============================================================================================================" |
| 180 | + done # end of TEST loop flash |
| 181 | +
|
| 182 | + # loop over all tests for one example and monitor the serial output |
| 183 | + for ((idx=0; idx<${#TESTS[@]}; ++idx)); do |
| 184 | + echo "==============================================================================================================" |
| 185 | + echo "Monitor on index $idx for TEST: ${TESTS[idx]} under EXAMPLE: ${EXAMPLE} and LIB: ${LIB}" |
| 186 | + timeout 1m \ |
| 187 | + /opt/runner_support/py_console.py \ |
| 188 | + --port ${PORTS[idx]} \ |
| 189 | + --baud 115200 \ |
| 190 | + --report ~/artefact/${LIB}/${EXAMPLE}/${TESTS[idx]}/${{ env.device }}/report.json |
| 191 | + |
| 192 | + echo "==============================================================================================================" |
| 193 | + done # end of TEST loop monitor |
| 194 | +
|
| 195 | + done # end of EXAMPLE loop |
| 196 | + done # end of LIB loop |
| 197 | +
|
| 198 | + # Upload the compiled HEX files to the GitHub server |
| 199 | + - name: Artefact |
| 200 | + uses: actions/upload-artifact@v4 |
| 201 | + with: |
| 202 | + name: ${{ env.device }} |
| 203 | + path: ~/artefact/* |
| 204 | + if-no-files-found: ignore |
| 205 | + |
| 206 | + |
| 207 | + ############################################################################# |
| 208 | + # Switch off the HIL after all tests are done |
| 209 | + post: |
| 210 | + |
| 211 | + # we run this no matter if before fails |
| 212 | + if: always() |
| 213 | + # wait on first setup run before starting main function |
| 214 | + needs: [setup, flash] |
| 215 | + |
| 216 | + # we run this on self hosted runner, use labels to be more specific |
| 217 | + # add specific names if there are some, otherwise self-hosted, X64, Linux are the default ones |
| 218 | + runs-on: |
| 219 | + - self-hosted |
| 220 | + - X64 |
| 221 | + - Linux |
| 222 | + |
| 223 | + steps: |
| 224 | + - name: Switch off HIL |
| 225 | + run: | |
| 226 | + cd /opt/runner_support/ |
| 227 | + REPO="$(basename "$GITHUB_REPOSITORY")" |
| 228 | + ./py_checkusb.py --switch repo --namelist $REPO --onoff off |
| 229 | +
|
0 commit comments