Skip to content

Commit 36f2408

Browse files
Check for and handle parse errors
1 parent c6232df commit 36f2408

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ There is a `warnings` option to set how warnings are handled, and more options t
116116
|`warning-no-image`|A missing `file` field in the `image` subsection of the `info` section|
117117
|`warning-no-pins`|No pins found in definition file|
118118
|`warning-dupe`|More than one pin that share the same `pin` field in a single mapping|
119+
|`warning-parse`|An error parsing a connector definition file|
119120

120121
Listed below are the possible values for these fields.
121122

@@ -196,6 +197,7 @@ WARNING_NO_CONNECTORS
196197
WARNING_NO_IMAGE
197198
WARNING_NO_PINS
198199
WARNING_DUPE
200+
WARNING_PARSE
199201
COLS
200202
PRINT_COLS
201203
INFO_COL

action.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ inputs:
5050
"notice" to warn on the Actions page,
5151
or "error" to fail the workflow step.
5252
default: "unset"
53+
warning-parse:
54+
required: false
55+
description: |
56+
Set to "skip" to skip to the next mapping file,
57+
"notice" to warn on the Actions page,
58+
or "error" to fail the workflow step.
59+
default: "unset"
5360
columns:
5461
required: true
5562
description: |
@@ -88,6 +95,7 @@ runs:
8895
WARNING_NO_IMAGE: ${{ inputs.warning-no-image }}
8996
WARNING_NO_CONNECTORS: ${{ inputs.warning-no-connectors }}
9097
WARNING_DUPE: ${{ inputs.warning-dupe }}
98+
WARNING_PARSE: ${{ inputs.warning-parse }}
9199
COLS: ${{ inputs.columns }}
92100
PRINT_COLS: ${{ inputs.print-columns }}
93101
INFO_COL: ${{ inputs.info-column }}

main.sh

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# env WARNING_NO_IMAGE
1010
# env WARNING_NO_PINS
1111
# env WARNING_DUPE
12+
# env WARNING_PARSE
1213
# same options as WARNINGS
1314

1415
if [ "$DEBUG" = "true" ]; then
@@ -18,6 +19,7 @@ if [ "$DEBUG" = "true" ]; then
1819
echo "WARNING_NO_IMAGE: $WARNING_NO_IMAGE"
1920
echo "WARNING_NO_PINS: $WARNING_NO_PINS"
2021
echo "WARNING_DUPE: $WARNING_DUPE"
22+
echo "WARNING_PARSE: $WARNING_PARSE"
2123
fi
2224

2325
SCRIPTDIR=$(dirname "$0")
@@ -52,31 +54,34 @@ if [ $(echo "$CONNECTORS" | grep -v ^$ | wc -l) -eq 0 ]; then
5254
fi
5355
5456
FILES=$(for f in $CONNECTORS; do
55-
ORDER=$(yq e '.info.order' "$f")
56-
echo "$f $ORDER"
57+
ORDER=$(yq e '.info.order' "$f")
58+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $f"
59+
echo "$f $ORDER"
5760
done)
5861
CONNECTORS=$(echo "$FILES" | sort -k2 | cut -d ' ' -f 1)
5962
6063
# Make a temp directory for symlinks to actual files.
6164
mkdir -p pinoutstmp
6265
66+
6367
for c in $CONNECTORS; do
6468
echo "Processing: $c"
65-
if [ $(yq e '.pins.[].pin' "$c" | wc -c) -lt 1 ]; then
66-
if ! handle_warning "$WARNING_NO_PINS" "WARNING: No pins found in definition $c"; then continue; fi
67-
fi
69+
PINCNT=$(yq e '.pins.[].pin' "$c" | wc -c)
70+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $c" || continue
71+
[ "$PINCNT" -gt 0 ] || handle_warning "$WARNING_NO_PINS" "WARNING: No pins found in definition $c" || continue
6872
DUPES=$(yq e '.pins.[].pin' "$c" | grep -v "null" | sort | uniq -d | tr -d '\n')
69-
if [ -n "$DUPES" ]; then
70-
if ! handle_warning "$WARNING_DUPE" "WARNING: Duplicate pins in $c: $DUPES"; then continue; fi
71-
fi
73+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $c" || continue
74+
[ -z "$DUPES" ] || handle_warning "$WARNING_DUPE" "WARNING: Duplicate pins in $c: $DUPES" || continue
7275
POSDUPES=$(yq e '.info.pins.[].pin' "$c" | grep -v "null" | sort | uniq -d | tr -d '\n')
76+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $c" || continue
7377
POSDUPES+=$(yq e '.info.image.pins.[].pin' "$c" | grep -v "null" | sort | uniq -d | tr -d '\n')
74-
if [ -n "$POSDUPES" ]; then
75-
if ! handle_warning "$WARNING_DUPE" "WARNING: Duplicate pin positionss in $c: $POSDUPES"; then continue; fi
76-
fi
78+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $c" || continue
79+
[ -z "$POSDUPES" ] || handle_warning "$WARNING_DUPE" "WARNING: Duplicate pin positionss in $c: $POSDUPES" || continue
7780
# Get the directory and title, if they exist
7881
DIRECTORY=$(yq e '.info.directory' "$c")
82+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $c" || continue
7983
TITLE=$(yq e '.info.title' "$c")
84+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $c" || continue
8085
# Build the temp path, removing leading ./ and /
8186
DIR="pinoutstmp/"$(dirname "$c" | sed -e 's/^\.\///' -e 's/^\///')
8287
# If we have a directory field
@@ -149,35 +154,41 @@ for c in $CONNECTORS; do
149154
if [ "$DEBUG" = "true" ]; then
150155
echo "File Name: $NAME"
151156
fi
152-
if [ "$(yq e '.info.cid' "$c")" == "null" ]; then
153-
if ! handle_warning "$WARNING_NO_CID" "WARNING: Missing yaml cid field in info section of $c"; then continue; fi
154-
fi
157+
CID=$(yq e '.info.cid' "$c")
158+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $c" || continue
159+
[ "$CID" != "null" ] || handle_warning "$WARNING_NO_CID" "WARNING: Missing yaml cid field in info section of $c" || continue
155160
IMG=$(yq e '.info.image.file' "$c")
156-
if [ $? -ne 0 ] || [ "$IMG" = "null" ]; then
161+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $c" || continue
162+
if [ "$IMG" = "null" ]; then
157163
IMP=$(yq e '.info.image.import' "$c")
158-
if [ $? -ne 0 ] || [ "$IMP" = "null" ]; then
159-
if ! handle_warning "$WARNING_NO_IMAGE" "WARNING: $c missing image"; then continue; fi
164+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $c" || continue
165+
if [ "$IMP" = "null" ]; then
166+
handle_warning "$WARNING_NO_IMAGE" "WARNING: $c missing image" || continue
160167
else
161168
IMG=$(yq e '.image.file' "$(dirname "$c")/$IMP")
169+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $c" || continue
162170
echo "Image: $IMG"
163171
cp "$(dirname $(dirname "$c")/$IMP)/$IMG" "$DIR"
164172
yq --inplace ea '.info.image = .image | select(fi == 0)' "$c" "$(dirname "$c")/$IMP"
173+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $c" || continue
165174
fi
166175
else
167176
echo "Image: $IMG"
168177
cp "$(dirname "$c")/$IMG" "$DIR"
169178
# Patch legacy YAMLs by moving .info.pins to .info.image.pins
170179
yq --inplace e '.info.image.pins = .info.pins' "$c"
180+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $c" || continue
171181
yq --inplace e 'del(.info.pins)' "$c"
182+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $c" || continue
172183
fi
184+
JSON=$(yq -o=json e "$c")
185+
[ $? -eq 0 ] || handle_warning "$WARNING_PARSE" "WARNING: parse error in definition $c" || continue
173186
if [ -f "$DIR/index.html" ]; then
174-
bash "$SCRIPTDIR"/append.sh "$(yq -o=json e "$c")" "$DIR/index.html"
187+
bash "$SCRIPTDIR"/append.sh "$JSON" "$DIR/index.html"
175188
else
176-
bash "$SCRIPTDIR"/gen.sh "$(yq -o=json e "$c")" "$DIR/index.html"
177-
fi
178-
if [ $? -ne 0 ]; then
179-
if ! handle_warning "unset" "WARNING: Failed to generate or append to pinout"; then continue; fi
189+
bash "$SCRIPTDIR"/gen.sh "$JSON" "$DIR/index.html"
180190
fi
191+
[ $? -eq 0 ] || handle_warning "unset" "WARNING: Failed to generate or append to pinout" || continue
181192
done
182193
183194
# Delete all symbolic links and empty directories from the temp dir.
@@ -190,7 +201,7 @@ find pinoutstmp -type d -empty -delete
190201
find pinouts/ -type f -name 'index.html' -print0 | while IFS= read -r -d '' f; do
191202
DUPES=$(grep "cid\": " "$f" | uniq -d | tr -d '\n')
192203
if [ -n "$DUPES" ]; then
193-
if ! handle_warning "$WARNING_DUPE" "WARNING: Duplicate cids in $f: $DUPES"; then continue; fi
204+
handle_warning "$WARNING_DUPE" "WARNING: Duplicate cids in $f: $DUPES" || continue
194205
fi
195206
done
196207

0 commit comments

Comments
 (0)