Skip to content

Commit 2402478

Browse files
committed
test
1 parent 148f9b6 commit 2402478

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

.github/workflows/validate-new-plugin-metadata.yml

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,37 +81,54 @@ jobs:
8181
check_valid_url() {
8282
local field="$1"
8383
local required="${2:-optional}" # Default to "optional" if no second parameter is provided
84-
local value=$(echo "$metadata" | yq ".$field" || true)
84+
local value
85+
value=$(echo "$metadata" | yq -r ".$field" || true)
8586
8687
# If field is missing or empty
87-
if [[ -z "$value" ]]; then
88+
if [[ -z "$value" || "$value" == "null" ]]; then
8889
if [[ "$required" == "required" ]]; then
8990
echo "::error file=$metadata_file::'$field' is required but missing"
9091
((errors++))
9192
fi
9293
return 0 # Skip validation if it's optional and missing
9394
fi
9495
95-
# Handle arrays of URLs (e.g., screenshots)
96-
# Check if the field is an array using yq length check
97-
is_array=$(echo "$metadata" | yq -r ".${field} | length")
98-
99-
if [[ "$is_array" =~ ^[0-9]+$ && "$is_array" -gt 0 ]]; then
100-
# Iterate properly over array elements
101-
for url in $(echo "$metadata" | yq -r ".$field[]" || true); do
102-
if [[ -z "$url" ]]; then # Skip empty values inside arrays
103-
continue
96+
# Check if the field is an array
97+
local field_type
98+
field_type=$(echo "$metadata" | yq -r ".$field | type")
99+
100+
if [[ "$field_type" == "!!seq" ]]; then
101+
# Check if the array is completely empty (length == 0)
102+
local array_length
103+
array_length=$(echo "$metadata" | yq -r ".$field | length")
104+
105+
if [[ "$array_length" -eq 0 ]]; then
106+
echo "DEBUG: '$field' is an empty array, skipping validation."
107+
if [[ "$required" == "required" ]]; then
108+
echo "::error file=$metadata_file::'$field' is required but missing"
109+
((errors++))
110+
fi
111+
return 0
112+
fi
113+
114+
# Extract array values while removing empty strings and nulls
115+
urls=$(echo "$metadata" | yq -r ".$field | map(select(. != null and . != \"\")) | .[]?" || true)
116+
117+
# DEBUGGING: Print extracted values before validation
118+
echo "DEBUG: Extracted URLs for '$field':"
119+
echo "$urls" | cat -A # Helps visualize hidden characters
120+
121+
# Iterate over non-empty elements in the array
122+
echo "$urls" | while IFS= read -r url; do
123+
if [[ -z "$url" ]]; then
124+
continue # Explicitly skip any remaining empty values
104125
fi
126+
echo "DEBUG: Validating URL: '$url'"
105127
if [[ ! "$url" =~ ^https?:\/\/[a-zA-Z0-9.-]+(\.[a-zA-Z]{2,})+(:[0-9]{1,5})?(\/.*)?$ ]]; then
106-
echo "::error file=$metadata_file::'$field' contains an invalid URL: $url"
107-
((errors++))
128+
echo "::error file=$metadata_file::'$field' contains an invalid URL: $url"
129+
((errors++))
108130
fi
109131
done
110-
else
111-
if [[ ! "$value" =~ ^https?:\/\/[a-zA-Z0-9.-]+(\.[a-zA-Z]{2,})+(:[0-9]{1,5})?(\/.*)?$ ]]; then
112-
echo "::error file=$metadata_file::'$field' is not a valid URL"
113-
((errors++))
114-
fi
115132
fi
116133
}
117134

0 commit comments

Comments
 (0)