| 
									
										
										
										
											2023-08-31 08:32:40 +00:00
										 |  |  | #!/bin/bash
 | 
					
						
							| 
									
										
										
										
											2023-09-23 18:33:40 +00:00
										 |  |  | # This script is used to check that the versions are correct and stopping the pipeline if something is wrong. | 
					
						
							| 
									
										
										
										
											2023-08-31 09:07:00 +00:00
										 |  |  | # This is designed to be run on the main pipeline to check that everything is in order before building RetroDECK. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | source automation_tools/version_extractor.sh | 
					
						
							| 
									
										
										
										
											2023-08-31 08:32:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Set the file paths | 
					
						
							| 
									
										
										
										
											2025-01-30 04:36:33 +00:00
										 |  |  | metainfo="net.retrodeck.retrodeck.metainfo.xml" | 
					
						
							| 
									
										
										
										
											2023-08-31 08:32:40 +00:00
										 |  |  | manifest="net.retrodeck.retrodeck.yml" | 
					
						
							|  |  |  | manifest_content=$(cat "$manifest") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | compare_versions() { | 
					
						
							|  |  |  |     local manifest_version_cleaned=$(echo "$1" | sed 's/[a-zA-Z]//g') | 
					
						
							| 
									
										
										
										
											2025-01-30 04:36:33 +00:00
										 |  |  |     local metainfo_version_cleaned=$(echo "$2" | sed 's/[a-zA-Z]//g') | 
					
						
							| 
									
										
										
										
											2023-08-31 08:32:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-30 04:36:33 +00:00
										 |  |  |     if [[ "$manifest_version_cleaned" == "$metainfo_version_cleaned" ]]; then | 
					
						
							| 
									
										
										
										
											2023-08-31 08:32:40 +00:00
										 |  |  |         return 0  # Versions are equal | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     local IFS=. | 
					
						
							|  |  |  |     local manifest_parts=($manifest_version_cleaned) | 
					
						
							| 
									
										
										
										
											2025-01-30 04:36:33 +00:00
										 |  |  |     local metainfo_parts=($metainfo_version_cleaned) | 
					
						
							| 
									
										
										
										
											2023-08-31 08:32:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for ((i=0; i<${#manifest_parts[@]}; i++)); do | 
					
						
							| 
									
										
										
										
											2025-01-30 04:36:33 +00:00
										 |  |  |         if ((manifest_parts[i] > metainfo_parts[i])); then | 
					
						
							| 
									
										
										
										
											2023-08-31 08:32:40 +00:00
										 |  |  |             return 1  # Manifest version is greater | 
					
						
							| 
									
										
										
										
											2025-01-30 04:36:33 +00:00
										 |  |  |         elif ((manifest_parts[i] < metainfo_parts[i])); then | 
					
						
							|  |  |  |             return 2  # Metainfo version is greater | 
					
						
							| 
									
										
										
										
											2023-08-31 08:32:40 +00:00
										 |  |  |         fi | 
					
						
							|  |  |  |     done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 0  # Versions are equal | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-31 09:07:00 +00:00
										 |  |  | repo_version=$(fetch_repo_version) | 
					
						
							| 
									
										
										
										
											2023-08-31 08:32:40 +00:00
										 |  |  | echo -e "Online repository:\t$repo_version" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-31 09:07:00 +00:00
										 |  |  | manifest_version=$(fetch_manifest_version) | 
					
						
							|  |  |  | echo -e "Manifest:\t\t$manifest_version" | 
					
						
							| 
									
										
										
										
											2023-08-31 08:32:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-30 04:36:33 +00:00
										 |  |  | metainfo_version=$(fetch_metainfo_version) | 
					
						
							|  |  |  | echo -e "Metainfo:\t\t$metainfo_version" | 
					
						
							| 
									
										
										
										
											2023-08-31 08:32:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-31 09:07:00 +00:00
										 |  |  | # Additional checks | 
					
						
							| 
									
										
										
										
											2024-07-17 12:18:19 +00:00
										 |  |  | if [[ "$manifest_version" == "main" || "$manifest_version" == "THISBRANCH" || "$manifest_version" == *"cooker"* ]]; then | 
					
						
							|  |  |  |     echo "Manifest version cannot be 'main', 'THISBRANCH', or contain 'cooker'. Please fix it." | 
					
						
							| 
									
										
										
										
											2023-08-31 09:07:00 +00:00
										 |  |  |     exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2023-08-31 08:32:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-30 04:36:33 +00:00
										 |  |  | if [[ "$metainfo_version" != "$manifest_version" ]]; then | 
					
						
							|  |  |  |     echo "Metainfo version is not equal to manifest version. Please fix it." | 
					
						
							| 
									
										
										
										
											2023-08-31 09:07:00 +00:00
										 |  |  |     exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | compare_versions "$repo_version" "$manifest_version" | 
					
						
							| 
									
										
										
										
											2023-08-31 08:32:40 +00:00
										 |  |  | result=$? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [ "$result" -eq 1 ]; then | 
					
						
							| 
									
										
										
										
											2023-08-31 09:07:00 +00:00
										 |  |  |     echo "Repository version is less than manifest version. Please fix it." | 
					
						
							| 
									
										
										
										
											2023-08-31 08:32:40 +00:00
										 |  |  |     exit 1 | 
					
						
							| 
									
										
										
										
											2023-08-31 09:07:00 +00:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo "All checks passed. Well done!" |