Skip to content

Commit fb000cc

Browse files
committed
test
1 parent 148f9b6 commit fb000cc

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

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

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,36 +80,39 @@ jobs:
8080
# Function to validate a URL field (supports single values and arrays)
8181
check_valid_url() {
8282
local field="$1"
83-
local required="${2:-optional}" # Default to "optional" if no second parameter is provided
84-
local value=$(echo "$metadata" | yq ".$field" || true)
83+
local field_type="${2:-single_value}" # Default to "single_value" if no second parameter is provided
84+
local required="${3:-optional}" # Default to "optional" if no third parameter is provided
8585
86-
# If field is missing or empty
87-
if [[ -z "$value" ]]; then
88-
if [[ "$required" == "required" ]]; then
89-
echo "::error file=$metadata_file::'$field' is required but missing"
90-
((errors++))
86+
if [[ "$field_type" == "single_value" ]]; then
87+
local value=$(echo "$metadata" | yq ".$field" || true)
88+
89+
# If field is missing or empty
90+
if [[ -z "$value" ]]; then
91+
if [[ "$required" == "required" ]]; then
92+
echo "::error file=$metadata_file::'$field' is required but missing"
93+
((errors++))
94+
fi
95+
return 0 # Skip validation if it's optional and missing
9196
fi
92-
return 0 # Skip validation if it's optional and missing
93-
fi
97+
else
98+
local array=$(echo "$metadata" | yq -r ".$field | .[]" || echo "")
99+
local non_empty_entries=0
94100
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
101+
for url in $array; do
102+
if [[ -z "$url" ]]; then
103103
continue
104-
fi
105-
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++))
104+
else
105+
if [[ "$url" =~ ^(https?:\/\/[a-zA-Z0-9.-]+(\.[a-zA-Z]{2,})+(:[0-9]{1,5})?(\/.*)?)$ ]]; then
106+
((non_empty_entries++))
107+
else
108+
echo "::error file=$metadata_file::'$field' contains an invalid URL: $url"
109+
((errors++))
110+
fi
108111
fi
109112
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+
114+
if [[ "$required" == "required" && "$non_empty_entries" -eq 0 ]]; then
115+
echo "::error file=$metadata_file::'$field' is required but missing"
113116
((errors++))
114117
fi
115118
fi
@@ -128,7 +131,7 @@ jobs:
128131
check_valid_url "demo_video_url"
129132
check_valid_url "documentation_url"
130133
check_valid_url "changelog_url"
131-
check_valid_url "screenshots"
134+
check_valid_url "screenshots" "array"
132135
133136
# Validate date format (YYYY-MM)
134137
release_date=$(echo "$metadata" | yq '.release_date')

0 commit comments

Comments
 (0)