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
  • Loading branch information
peter-sanderson committed Oct 7, 2024
1 parent db7a383 commit fe1eee1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions firmware/2/releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"bootloader_version": [2, 1, 6],
"firmware_revision": "632b9561559b7ab6824bb7eeac072874e07b7b82",
"translations": ["cs-CZ", "de-DE", "es-ES", "fr-FR"],
"url": "data/firmware/2/trezor-2.8.1.bin",
"url": "data/firmware/t2t1/trezor-t2t1-2.8.1-bitcoinonly.bin",
"fingerprint": "d3af84a212d32785449ca6575e3cf2a641920b353a82dec9f059083ea5d4b149",
"changelog": "* Fixed displaying of a progress indicator for the formatting operation.\n* Improve precision of PIN validation countdown.\n* Solana: Improved support for AToken Create operation.",
"url_bitcoinonly": "data/firmware/2/trezor-2.8.1-bitcoinonly.bin",
"url_bitcoinonly": "data/firmware/t2t1/trezor-t2t1-2.8.1-bitcoinonly.bin",
"fingerprint_bitcoinonly": "38ab127fcf4263a18a3b07593301fdd2c6a1a96360b62c131adb849b5d18fae3",
"changelog_bitcoinonly": "* Fixed displaying of a progress indicator for the formatting operation.\n* Improve precision of PIN validation countdown."
},
Expand Down
3 changes: 0 additions & 3 deletions firmware/2/trezor-2.8.1-bitcoinonly.bin

This file was deleted.

3 changes: 0 additions & 3 deletions firmware/2/trezor-2.8.1.bin

This file was deleted.

31 changes: 23 additions & 8 deletions scripts/check-firmware-presence-in-releases-json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 -n1 --no-run-if-empty basename | sort | uniq \
jq -r '.[] | select(.url) | .url, .url_bitcoinonly' "$json_file" | xargs -n1 --no-run-if-empty | sort | uniq \
| grep -vF "null"
}

Expand All @@ -35,11 +33,28 @@ compare_files() {
local json_file="$1"
local directory="$2"

expected_files=$(extract_filenames_from_json "$json_file")
# 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")
full_path_actual_files=$(for i in $actual_files; do echo "data/firmware/${DEVICE}/${i}"; done)

missing_files=$(comm -23 <(echo "$expected_files") <(echo "$actual_files"))
extra_files=$(comm -13 <(echo "$expected_files") <(echo "$actual_files"))
extra_files=$(comm -13 <(echo "$files_in_releases_json") <(echo "$full_path_actual_files"))

if [[ -z "$missing_files" && -z "$extra_files" ]]; then
echo -e "${GREEN}All files are present and accounted for.${NC}"
Expand Down

0 comments on commit fe1eee1

Please sign in to comment.