1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-14 03:30:02 +00:00
trezor-firmware/ci/prepare_ui_artifacts.py
2020-01-03 15:07:46 +00:00

31 lines
792 B
Python

import hashlib
import shutil
from pathlib import Path
def _hash_files(files):
hasher = hashlib.sha256()
for file in sorted(files):
with open(file, "rb") as f:
content = f.read()
hasher.update(content)
return hasher.digest().hex()
def _compare_hash(test_dir, hash):
with open(test_dir / "hash.txt", "r") as f:
content = f.read()
assert hash == content
fixture_root = Path().cwd() / "../tests/ui_tests/fixtures"
for test_dir in fixture_root.iterdir():
if test_dir.is_dir():
recorded_dir = test_dir / "recorded"
if recorded_dir.exists():
hash = _hash_files(recorded_dir.iterdir())
_compare_hash(test_dir, hash)
shutil.make_archive("tmp/" + hash, "zip", recorded_dir)