@@ -85,17 +85,26 @@ for repo in "${repos[@]}"; do
85
85
86
86
# TODO also check for required keys and/or types?
87
87
# the canonicalMetadataFile doesn't have too many categories since it is the source of categories
88
- # all other metadata.json files must not be more than maxCategories
88
+ # all other metadata.json files must not be more than maxCategories or have categories that aren't in the canonical set
89
89
if [ " $repoFile " != " $canonicalMetadataFile " ]; then
90
- if tooManyCategories=" $( jq --raw-output '
90
+ export repoFile
91
+ if errorText=" $( jq -r --slurpfile canonical " $canonicalMetadataFile " '
91
92
.hub.categories
92
- | length
93
- | if . > (env.maxCategories | tonumber) then
94
- .
95
- else empty end
93
+ | (
94
+ length
95
+ | if . > (env.maxCategories | tonumber) then
96
+ "error: \(env.repoFile): too many categories: \(.) (max \(env.maxCategories))"
97
+ else empty end
98
+ ),
99
+ (
100
+ . - $canonical[0].hub.categories
101
+ | if length > 0 then
102
+ "error: \(env.repoFile): unknown categories \(.)"
103
+ else empty end
104
+ )
96
105
' " $repoFile " ) " ; then
97
- if [ -n " $tooManyCategories " ]; then
98
- echo >&2 " error: $repoFile : too many categories: $tooManyCategories (max $maxCategories ) "
106
+ if [ -n " $errorText " ]; then
107
+ echo >&2 " $errorText "
99
108
(( failures++ )) || :
100
109
fi
101
110
else
@@ -104,20 +113,6 @@ for repo in "${repos[@]}"; do
104
113
continue
105
114
fi
106
115
fi
107
-
108
- # check for categories that aren't in the canonical set
109
- if extraCategories=" $( jq -c --slurpfile canonical " $canonicalMetadataFile " '
110
- .hub.categories - $canonical[0].hub.categories
111
- ' " $repoFile " ) " ; then
112
- if [ " $extraCategories " != ' []' ]; then
113
- echo >&2 " error: $repoFile : unkown categories: $extraCategories "
114
- (( failures++ )) || :
115
- fi
116
- else
117
- echo >&2 " error parsing '$repoFile '; invalid JSON?"
118
- (( failures++ )) || :
119
- continue
120
- fi
121
116
done
122
117
123
118
exit " $failures "
0 commit comments