Skip to content

Commit 6a4d020

Browse files
author
Dalton
committed
AUTH-2016 adds sha256 hashes to releases
1 parent 4791ba3 commit 6a4d020

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

github_release.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import argparse
77
import logging
88
import os
9+
import hashlib
910

1011
from github import Github, GithubException, UnknownObjectException
1112

@@ -15,6 +16,30 @@
1516
CLOUDFLARED_REPO = os.environ.get("GITHUB_REPO", "cloudflare/cloudflared")
1617
GITHUB_CONFLICT_CODE = "already_exists"
1718

19+
def get_sha256(filename):
20+
""" get the sha256 of a file """
21+
sha256_hash = hashlib.sha256()
22+
with open(filename,"rb") as f:
23+
for byte_block in iter(lambda: f.read(4096),b""):
24+
sha256_hash.update(byte_block)
25+
return sha256_hash.hexdigest()
26+
27+
28+
def update_or_add_message(msg, name, sha):
29+
"""
30+
updates or builds the github version message for each new asset's sha256.
31+
Searches the existing message string to update or create.
32+
"""
33+
new_text = '{0}: {1}\n'.format(name, sha)
34+
start = msg.find(name)
35+
if (start != -1):
36+
end = msg.find("\n", start)
37+
if (end != -1):
38+
return msg.replace(msg[start:end+1], new_text)
39+
back = msg.rfind("```")
40+
if (back != -1):
41+
return '{0}{1}```'.format(msg[:back], new_text)
42+
return '{0} \n### SHA256 Checksums:\n```\n {1}```'.format(msg, new_text)
1843

1944
def assert_tag_exists(repo, version):
2045
""" Raise exception if repo does not contain a tag matching version """
@@ -120,6 +145,14 @@ def main():
120145
return
121146

122147
release.upload_asset(args.path, name=args.name)
148+
149+
# add the sha256 of the new artifact to the release message body
150+
pkg_hash = get_sha256(args.path)
151+
152+
# update the release body text
153+
msg = update_or_add_message(release.body, args.name, pkg_hash)
154+
release.update_release(version, version, msg)
155+
123156
except Exception as e:
124157
logging.exception(e)
125158
exit(1)

0 commit comments

Comments
 (0)