@@ -80,36 +80,56 @@ 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+ # Extract array from YAML
99+ local raw_array
100+ raw_array=$(echo "$metadata" | yq -r ".$field | .[]" || echo "")
101+
102+ mapfile -t array <<< "$raw_array"
94103
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
104+ # Count total entries, including empty ones
105+ local all_entries=$(echo "$metadata" | yq -r ".$field | length" || echo "0")
106+
107+ # Count empty entries correctly
108+ local empty_entries=0
109+ for entry in "${array[@]}"; do
110+ if [[ -z "$entry" ]]; then
111+ ((empty_entries++))
104112 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++))
113+ done
114+
115+ echo "Total array length (including empty): $all_entries"
116+ echo "Empty string entries: $empty_entries"
117+
118+ local non_empty_entries=0
119+
120+ for url in "${array[@]}"; do
121+ if [[ -n "$url" ]]; then
122+ if [[ "$url" =~ ^(https?:\/\/[a-zA-Z0-9.-]+(\.[a-zA-Z]{2,})+(:[0-9]{1,5})?(\/.*)?)$ ]]; then
123+ ((non_empty_entries++))
124+ else
125+ echo "::error file=$metadata_file::'$field' contains an invalid URL: $url"
126+ ((errors++))
127+ fi
108128 fi
109129 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 "
130+
131+ if [[ "$required " == "required" && "$non_empty_entries" -eq 0 ]]; then
132+ echo "::error file=$metadata_file::'$field' is required but missing "
113133 ((errors++))
114134 fi
115135 fi
@@ -128,7 +148,7 @@ jobs:
128148 check_valid_url "demo_video_url"
129149 check_valid_url "documentation_url"
130150 check_valid_url "changelog_url"
131- check_valid_url "screenshots"
151+ check_valid_url "screenshots" "array"
132152
133153 # Validate date format (YYYY-MM)
134154 release_date=$(echo "$metadata" | yq '.release_date')
0 commit comments