Switch from base64 to sha256 for asset names

GH doesn't like '=' either and also requires a file extension or it will add one.
This commit is contained in:
Christoph Reiter 2020-08-11 20:12:09 +02:00
parent 2d178562ac
commit 8d30e2cfd2

View File

@ -17,7 +17,7 @@ import shlex
import time import time
import tempfile import tempfile
import shutil import shutil
import base64 from hashlib import sha256
# After which overall time it should stop building (in seconds) # After which overall time it should stop building (in seconds)
BUILD_TIMEOUT = 18000 BUILD_TIMEOUT = 18000
@ -107,9 +107,7 @@ def upload_asset(type_: str, path: os.PathLike, replace=True):
path = str(path) path = str(path)
basename = os.path.basename(path) basename = os.path.basename(path)
# GitHub will throw out charaters like '~', so we have to encode asset_name = get_gh_asset_name(basename)
# and store the real name in the label
asset_name = base64.b64encode(basename.encode()).decode()
asset_label = basename asset_label = basename
if replace: if replace:
@ -313,11 +311,17 @@ def get_buildqueue():
return pkgs return pkgs
def get_gh_asset_name(basename):
# GitHub will throw out charaters like '~' or '='. It also doesn't like
# when there is no file extension and will try to add one
return sha256(str(basename).encode("utf-8")).hexdigest() + ".bin"
def get_asset_filename(asset): def get_asset_filename(asset):
if not asset.label: if not asset.label:
return asset.name return asset.name
else: else:
assert base64.b64decode(asset.name.encode()).decode() == asset.label assert get_gh_asset_name(asset.label) == asset.name
return asset.label return asset.label