@@ -80,36 +80,43 @@ 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+ field_type=$(yq ".${field} | type")
99+ echo "The type of '$field' is: $field_type"
100+ mapfile -t array < <(echo "$metadata" | yq -r ".$field | select(.) | .[]" || echo "")
101+ echo "Array: ${array[@]}"
102+
103+ local non_empty_entries=0
94104
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
105+ for url in "${array[@]}"; do
106+ if [[ -z "$url" ]]; then
103107 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++))
108+ else
109+ if [[ "$url" =~ ^(https?:\/\/[a-zA-Z0-9.-]+(\.[a-zA-Z]{2,})+(:[0-9]{1,5})?(\/.*)?)$ ]]; then
110+ ((non_empty_entries++))
111+ else
112+ echo "::error file=$metadata_file::'$field' contains an invalid URL: $url"
113+ ((errors++))
114+ fi
108115 fi
109116 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 "
117+
118+ if [[ "$required " == "required" && "$non_empty_entries" -eq 0 ]]; then
119+ echo "::error file=$metadata_file::'$field' is required but missing "
113120 ((errors++))
114121 fi
115122 fi
@@ -128,9 +135,9 @@ jobs:
128135 check_valid_url "demo_video_url"
129136 check_valid_url "documentation_url"
130137 check_valid_url "changelog_url"
131- check_valid_url "screenshots"
132138
133139 # Validate date format (YYYY-MM)
140+ echo "The release date is: $(echo "$metadata" | yq '.release_date')"
134141 release_date=$(echo "$metadata" | yq '.release_date')
135142 if [[ -z "$release_date" ]]; then
136143 echo "::error file=$metadata_file::'$release_date' is required but missing"
@@ -143,6 +150,7 @@ jobs:
143150 fi
144151
145152 # Validate X account handle format (@username)
153+ echo "The X account handle is: $(echo "$metadata" | yq '.x_account_handle')"
146154 x_account_handle=$(echo "$metadata" | yq '.x_account_handle')
147155 if [[ -z "$x_account_handle" ]]; then
148156 echo "::error file=$metadata_file::'$x_account_handle' is required but missing"
@@ -155,6 +163,7 @@ jobs:
155163 fi
156164
157165 # Validate support contact (must be a valid URL or email)
166+ echo "The support contact is: $(echo "$metadata" | yq '.support_contact')"
158167 support_contact=$(echo "$metadata" | yq '.support_contact')
159168 if [[ -z "$support_contact" ]]; then
160169 echo "::error file=$metadata_file::'$support_contact' is required but missing"
0 commit comments