Skip to content

Commit

Permalink
fix: rework the algorithm so it takes the from releases.json into an …
Browse files Browse the repository at this point in the history
…account, this allows a cross-directory links

fix: binary missing in 2 directory + fix inconsistend url in releases.json

fix: rework the algorithm so it takes the  from releases.json into an account, this allows a cross-directory links
  • Loading branch information
peter-sanderson authored and vdovhanych committed Oct 7, 2024
1 parent a2e0827 commit 9950ae4
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions scripts/check-firmware-presence-in-releases-json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

PARENT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit ; pwd -P )

GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

Expand All @@ -14,47 +13,52 @@ 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"
}

list_files_in_directory() {
local dir="$1"
find "$dir" -type f -name "*.bin" -exec basename {} \; | sort \
| grep -v "trezor-inter-" | grep -v "trezor-t1tb-inter-" # filer out Intermediary firmwares
| grep -v "trezor-inter-" | grep -v "trezor-t1tb-inter-" # Filter out Intermediary firmwares
}

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")

all_exist=true
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
}
Expand Down

0 comments on commit 9950ae4

Please sign in to comment.