|
| 1 | +#! /bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +usage="help text here" |
| 6 | +buildlog=$1 |
| 7 | + |
| 8 | +if [ $# -eq 0 ]; then |
| 9 | + echo "$usage" |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | + |
| 13 | +error() { |
| 14 | + error_code="$1" |
| 15 | + error_message="$2" |
| 16 | + |
| 17 | + hint="$error_code: $error_message" |
| 18 | + notice="See https://zmk.dev/docs/troubleshooting/ for help." |
| 19 | + |
| 20 | + # Markup with annotations for GitHub actions if necessary |
| 21 | + if [ "$GITHUB_ACTIONS" = true ]; then |
| 22 | + hint="::error::$output" |
| 23 | + notice="::notice::Build failed. $notice" |
| 24 | + fi |
| 25 | + |
| 26 | + echo -e "$hint\n" |
| 27 | + echo "$notice" |
| 28 | +} |
| 29 | + |
| 30 | +if [ ! -f "$buildlog" ]; then |
| 31 | + error M01 "Build log not found at '$buildlog'" |
| 32 | + exit 2 |
| 33 | +fi |
| 34 | + |
| 35 | +# # Provide helpful GitHub annotations if build fails: |
| 36 | +# echo "::notice::Build failed. See https://zmk.dev/docs/troubleshooting/ for help." |
| 37 | + |
| 38 | +# Check that a given sed command ($1) returns a match when run over the |
| 39 | +# build.log. Store the output of sed for further parsing. |
| 40 | +match() { |
| 41 | + output="$(sed -nE "$1" "$buildlog")" |
| 42 | + test -n "$output" |
| 43 | +} |
| 44 | + |
| 45 | +# Provide annotation for errors due to incorrect keycodes (e.g. `&kp ENTRE`) |
| 46 | +# Error: nice_nano.dts.pre.tmp:74.137-138 syntax error |
| 47 | +if match 's/^.+ (\S+\.dts.pre.tmp):([0-9]+)\.([0-9]+).+ syntax error.*$/\1 \2 \3/p'; then |
| 48 | + read dts_file line_pos char_pos <<< "$output" |
| 49 | + line=$(sed -n ${line_pos}p "build/zephyr/${dts_file}") |
| 50 | + value=$(cut -c${char_pos}- <<< "$line" | cut -f1 -d\ ) |
| 51 | + error E101 "Unable to parse \"${value}\" from line: ${line}" |
| 52 | +fi |
| 53 | + |
| 54 | +# Provide annotation for errors due to missing parameters (e.g. `&mt LALT`): |
| 55 | +# zephyr/include/generated/devicetree_unfixed.h:1415:44: error: 'DT_N_S_keymap_S_base_layer_P_bindings_IDX_1_PH_P_label' undeclared here (not in a function) |
| 56 | +if match 's/^.+error: .DT_N_S_keymap_S_(.+)_P_bindings_IDX_([0-9])_PH_P_label. undeclared here.+$/\1 \2/p'; then |
| 57 | + read layer index <<< "$output" |
| 58 | + error E102 "Problem with index ${index} on layer \"${layer}\"." |
| 59 | +fi |
| 60 | + |
| 61 | +# Provide annotation for generic error messages such as: |
| 62 | +# nice_nano.dts.pre.tmp:734.14-741.5: ERROR (phandle_references): /keymap/base_layer: Reference to non-existent node or label "kc" |
| 63 | +if match 's/^.+dts\.pre\.tmp\S+ ERROR (.+)$/\1/p'; then |
| 64 | + error E103 "${output}" |
| 65 | +fi |
0 commit comments