diff --git a/scripts/check-firmware-presence-in-releases-json.sh b/scripts/check-firmware-presence-in-releases-json.sh index 8f89552..6a5837f 100755 --- a/scripts/check-firmware-presence-in-releases-json.sh +++ b/scripts/check-firmware-presence-in-releases-json.sh @@ -14,14 +14,12 @@ fi DEVICE=$1 -extract_filenames_from_json() { +extract_file_paths_from_json() { local json_file="$1" - # Filter out - # a) 'null' from missing .url_bitcoinonly for older firmwares - # b) super-old firmwares + # Filter out 'null' from missing .url_bitcoinonly for older firmwares - jq -r '.[] | select(.url) | .url, .url_bitcoinonly' "$json_file" | xargs -n 1 basename | sort | uniq \ + jq -r '.[] | select(.url) | .url, .url_bitcoinonly' "$json_file" | xargs -n1 --no-run-if-empty | sort | uniq \ | grep -vF "null" } @@ -35,26 +33,32 @@ compare_files() { local json_file="$1" local directory="$2" - expected_files=$(extract_filenames_from_json "$json_file") - actual_files=$(list_files_in_directory "$directory") - - missing_files=$(comm -23 <(echo "$expected_files") <(echo "$actual_files")) - extra_files=$(comm -13 <(echo "$expected_files") <(echo "$actual_files")) - - if [[ -z "$missing_files" && -z "$extra_files" ]]; then - echo -e "${GREEN}All files are present and accounted for.${NC}" - else - if [[ -n "$missing_files" ]]; then - echo -e "${RED}Missing files:" - echo "$missing_files" | awk '{print " " $0}' - echo -e "${NC}" - fi - if [[ -n "$extra_files" ]]; then - echo -e "${RED}Extra files in directory:" - echo "$extra_files" | awk '{print " " $0}' - echo -e "${NC}" - fi + # TEST 1: All files in releases.json exist + files_in_releases_json=$(extract_file_paths_from_json "$json_file") + + for file in $files_in_releases_json; do + file_to_test="$directory/../../../$file" + if [ ! -e "$file_to_test" ]; then + echo -e "${RED}File does not exist: $file_to_test${NC}" + all_exist=false + fi + done + + if ! $all_exist ; then + exit 1 + fi + + # TEST 2: All files in directory are in releases.json + + actual_files=$(list_files_in_directory "$directory") # All files in the directory + full_path_actual_files=$(for i in $actual_files; do echo "data/firmware/${DEVICE}/${i}"; done) # Prefixed to match the expected format in releases.json + extra_files=$(comm -13 <(echo "$files_in_releases_json") <(echo "$full_path_actual_files")) + + if [[ -n "$extra_files" ]]; then + echo -e "${RED}Extra files in directory:" + echo "$extra_files" | awk '{print " " $0}' + echo -e "${NC}" exit 1 fi }