From f0643d39c141df52cbaf85b99d70e9a695d2a500 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 12 Oct 2019 10:16:34 +0200 Subject: [PATCH] Add SHA256 hash also to Windows and MacOS releases. Fix #64 --- ci/build-macos.yml | 1 + ci/build-win.yml | 1 + packager.py | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/ci/build-macos.yml b/ci/build-macos.yml index ea7bee9..d4fd4d9 100644 --- a/ci/build-macos.yml +++ b/ci/build-macos.yml @@ -13,6 +13,7 @@ steps: set -e python packager.py build cp target/packager/mac/espanso-*.gz . + cp target/packager/mac/espanso-*.txt . cp target/packager/mac/espanso.rb . ls -la displayName: "Cargo build and packaging for MacOS" \ No newline at end of file diff --git a/ci/build-win.yml b/ci/build-win.yml index 726a210..cc2fc33 100644 --- a/ci/build-win.yml +++ b/ci/build-win.yml @@ -12,6 +12,7 @@ steps: - script: | python packager.py build copy "target\\packager\\win\\espanso-win-installer.exe" "espanso-win-installer.exe" + copy "target\\packager\\win\\espanso-win-installer-sha256.txt" "espanso-win-installer-sha256.txt" dir displayName: "Build and packaging for Windows" diff --git a/packager.py b/packager.py index 8a0f141..2cc55cd 100644 --- a/packager.py +++ b/packager.py @@ -6,6 +6,7 @@ import hashlib import click import shutil import toml +import hashlib import urllib.request from dataclasses import dataclass @@ -106,6 +107,17 @@ def build_windows(package_info): print("Compiling installer with Inno setup") subprocess.run(["iscc", os.path.abspath(os.path.join(TARGET_DIR, "setupscript.iss"))]) + print("Calculating the SHA256") + sha256_hash = hashlib.sha256() + with open(os.path.abspath(os.path.join(TARGET_DIR, INSTALLER_NAME+".exe")),"rb") as f: + # Read and update hash string value in blocks of 4K + for byte_block in iter(lambda: f.read(4096),b""): + sha256_hash.update(byte_block) + + hash_file = os.path.abspath(os.path.join(TARGET_DIR, "espanso-win-installer-sha256.txt")) + with open(hash_file, "w") as hf: + hf.write(sha256_hash.hexdigest()) + def build_mac(package_info): print("Starting packaging process for MacOS...") @@ -131,6 +143,17 @@ def build_mac(package_info): ]) print(f"Created archive: {archive_target}") + print("Calculating the SHA256") + sha256_hash = hashlib.sha256() + with open(archive_target,"rb") as f: + # Read and update hash string value in blocks of 4K + for byte_block in iter(lambda: f.read(4096),b""): + sha256_hash.update(byte_block) + + hash_file = os.path.abspath(os.path.join(TARGET_DIR, "espanso-mac-sha256.txt")) + with open(hash_file, "w") as hf: + hf.write(sha256_hash.hexdigest()) + print("Processing Homebrew formula template") with open("packager/mac/espanso.rb", "r") as formula_template: content = formula_template.read()