Add SHA256 hash also to Windows and MacOS releases. Fix #64

This commit is contained in:
Federico Terzi 2019-10-12 10:16:34 +02:00
parent 888e329d49
commit f0643d39c1
3 changed files with 25 additions and 0 deletions

View File

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

View File

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

View File

@ -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()