[release.py] Fixed bug that caused releases to be uploaded only during dry runs; Added --skip-hash-check flag to skip the hash check; Minor formatting improvements
This commit is contained in:
parent
7d20b3927d
commit
80e63aa291
40
release.py
40
release.py
@ -15,7 +15,8 @@ parser.add_argument("-f", "--file", help="Path to the version of ripme to releas
|
|||||||
parser.add_argument("-t", "--token", help="Your github personal access token")
|
parser.add_argument("-t", "--token", help="Your github personal access token")
|
||||||
parser.add_argument("-d", "--debug", help="Run in debug mode", action="store_true")
|
parser.add_argument("-d", "--debug", help="Run in debug mode", action="store_true")
|
||||||
parser.add_argument("-n", "--non-interactive", help="Do not ask for any input from the user", action="store_true")
|
parser.add_argument("-n", "--non-interactive", help="Do not ask for any input from the user", action="store_true")
|
||||||
parser.add_argument("--test", help="Perform a dry run", action="store_true")
|
parser.add_argument("--test", help="Perform a dry run (Do everything but upload new release)", action="store_true")
|
||||||
|
parser.add_argument("--skip-hash-check", help="Skip hash check (This should only be used for testing)", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -40,8 +41,10 @@ def isValidCommitMessage(message):
|
|||||||
pattern = re.compile("^\d+\.\d+\.\d+:")
|
pattern = re.compile("^\d+\.\d+\.\d+:")
|
||||||
return re.match(pattern, message)
|
return re.match(pattern, message)
|
||||||
|
|
||||||
|
|
||||||
# Checks if the update has the name ripme.jar, if not it renames the file
|
# Checks if the update has the name ripme.jar, if not it renames the file
|
||||||
# Returns the update file path
|
# Returns the update file path
|
||||||
|
# TODO handle files that aren't in sub dirs
|
||||||
def renameFile(path):
|
def renameFile(path):
|
||||||
if not path.endswith("ripme.jar"):
|
if not path.endswith("ripme.jar"):
|
||||||
print("Specified file is not named ripme.jar, renaming")
|
print("Specified file is not named ripme.jar, renaming")
|
||||||
@ -51,7 +54,6 @@ def renameFile(path):
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ripmeJson = json.loads(open("ripme.json").read())
|
ripmeJson = json.loads(open("ripme.json").read())
|
||||||
fileToUploadPath = renameFile(args.file)
|
fileToUploadPath = renameFile(args.file)
|
||||||
InNoninteractiveMode = args.non_interactive
|
InNoninteractiveMode = args.non_interactive
|
||||||
@ -74,23 +76,27 @@ if not isValidCommitMessage(commitMessage):
|
|||||||
print("[!] Error: {} is not a valid commit message as it does not start with a version".format(fileToUploadPath))
|
print("[!] Error: {} is not a valid commit message as it does not start with a version".format(fileToUploadPath))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
ripmeUpdate = open(fileToUploadPath, mode='rb').read()
|
|
||||||
|
|
||||||
# The actual hash of the file on disk
|
if not args.skip_hash_check:
|
||||||
actualHash = sha256(ripmeUpdate).hexdigest()
|
if debug:
|
||||||
|
print("Reading file {}".format(fileToUploadPath))
|
||||||
|
ripmeUpdate = open(fileToUploadPath, mode='rb').read()
|
||||||
|
|
||||||
# The hash that we expect the update to have
|
# The actual hash of the file on disk
|
||||||
expectedHash = ripmeJson.get("currentHash")
|
actualHash = sha256(ripmeUpdate).hexdigest()
|
||||||
|
|
||||||
|
# The hash that we expect the update to have
|
||||||
|
expectedHash = ripmeJson.get("currentHash")
|
||||||
|
|
||||||
# Make sure that the hash of the file we're uploading matches the hash in ripme.json. These hashes not matching will
|
# Make sure that the hash of the file we're uploading matches the hash in ripme.json. These hashes not matching will
|
||||||
# cause ripme to refuse to install the update for all users who haven't disabled update hash checking
|
# cause ripme to refuse to install the update for all users who haven't disabled update hash checking
|
||||||
if expectedHash != actualHash:
|
if expectedHash != actualHash:
|
||||||
print("[!] Error: expected hash of file and actual hash differ")
|
print("[!] Error: expected hash of file and actual hash differ")
|
||||||
print("[!] Expected hash is {}".format(expectedHash))
|
print("[!] Expected hash is {}".format(expectedHash))
|
||||||
print("[!] Actual hash is {}".format(actualHash))
|
print("[!] Actual hash is {}".format(actualHash))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print("[*] WARNING: SKIPPING HASH CHECK")
|
||||||
# Ask the user to review the information before we precede
|
# Ask the user to review the information before we precede
|
||||||
# This only runs in we're in interactive mode
|
# This only runs in we're in interactive mode
|
||||||
if not InNoninteractiveMode:
|
if not InNoninteractiveMode:
|
||||||
@ -99,7 +105,7 @@ if not InNoninteractiveMode:
|
|||||||
print("Repo: {}/{}".format(repoOwner, repoName))
|
print("Repo: {}/{}".format(repoOwner, repoName))
|
||||||
input("\nPlease review the information above and ensure it is correct and then press enter")
|
input("\nPlease review the information above and ensure it is correct and then press enter")
|
||||||
|
|
||||||
if args.test:
|
if not args.test:
|
||||||
print("Accessing github using token")
|
print("Accessing github using token")
|
||||||
g = Github(accessToken)
|
g = Github(accessToken)
|
||||||
|
|
||||||
@ -108,3 +114,5 @@ if args.test:
|
|||||||
|
|
||||||
print("Uploading file")
|
print("Uploading file")
|
||||||
release.upload_asset(fileToUploadPath, "ripme.jar")
|
release.upload_asset(fileToUploadPath, "ripme.jar")
|
||||||
|
else:
|
||||||
|
print("Not uploading release being script was run with --test flag")
|
||||||
|
Loading…
Reference in New Issue
Block a user