Skip to content

Commit

Permalink
Add check to keep releases.json in sync with the firmware binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-sanderson committed Aug 7, 2024
1 parent 6aaced4 commit 40773fe
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/check_releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ jobs:
- uses: actions/setup-python@v4
- run: python check_releases.py

releases-json-integrity-check:
name: releases.json integrity check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check releases.json files changes
run: ./scripts/run-releases-json-for-all-devices.sh

releases-revision-checks:
name: Releases revision Checks
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions firmware/t3b1/releases.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
90 changes: 90 additions & 0 deletions scripts/check-firmware-presence-in-releases-json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env bash

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

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

if [[ $# -ne 1 ]]
then
echo "must provide 1 argument. $# provided"
exit 1
fi

DEVICE=$1

extract_filenames_from_json() {
local json_file="$1"

# Filter out
# a) 'null' from missing .url_bitcoinonly for older firmwares
# b) super-old firmwares

jq -r '.[] | select(.url) | .url, .url_bitcoinonly' "$json_file" | xargs -n 1 basename | sort | uniq \
| grep -vFf <(cat << EOF
null
trezor-1.0.0.bin
trezor-1.1.0.bin
trezor-1.2.0.bin
trezor-1.2.1.bin
trezor-1.3.0.bin
trezor-1.3.1.bin
trezor-1.3.2.bin
trezor-1.3.3.bin
trezor-1.3.4.bin
trezor-1.3.5.bin
trezor-t1b1-1.0.0.bin
trezor-t1b1-1.1.0.bin
trezor-t1b1-1.2.0.bin
trezor-t1b1-1.2.1.bin
trezor-t1b1-1.3.0.bin
trezor-t1b1-1.3.1.bin
trezor-t1b1-1.3.2.bin
trezor-t1b1-1.3.3.bin
trezor-t1b1-1.3.4.bin
trezor-t1b1-1.3.5.bin
EOF
)
}

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
}

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

exit 1
fi
}

json_file=$PARENT_PATH"/../firmware/"$DEVICE/"releases.json"
directory=$PARENT_PATH"/../firmware/"$DEVICE

echo "Checking directory: $directory"

compare_files "$json_file" "$directory"
13 changes: 13 additions & 0 deletions scripts/run-releases-json-for-all-devices.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

DEVICE_PATHS=$(find firmware -maxdepth 1 -type d ! -name 'translations' ! -name 'README.md' ! -name 'firmware')

for FILE in $DEVICE_PATHS;
do
DEVICE_MODEL=$(basename "$FILE")
if ! ./scripts/check-firmware-presence-in-releases-json.sh "$DEVICE_MODEL" ; then
exit 1
fi;

echo
done

0 comments on commit 40773fe

Please sign in to comment.