From 7d20b3927d8a45e012bef64025b798c6c53f7d64 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Mon, 11 Jun 2018 09:22:44 -0400 Subject: [PATCH 1/3] release script now makes sure update file is named ripme.jar; added --test option for dry runs --- release.py | 34 ++++++++++++++++++++++++---------- releaseTests.py | 0 2 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 releaseTests.py diff --git a/release.py b/release.py index 3dcd3210..9b199bf6 100644 --- a/release.py +++ b/release.py @@ -15,9 +15,11 @@ 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("-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("--test", help="Perform a dry run", action="store_true") args = parser.parse_args() try: + # This binds input to raw_input on python2, we do this because input acts like eval on python2 input = raw_input except NameError: pass @@ -38,9 +40,20 @@ def isValidCommitMessage(message): pattern = re.compile("^\d+\.\d+\.\d+:") return re.match(pattern, message) +# Checks if the update has the name ripme.jar, if not it renames the file +# Returns the update file path +def renameFile(path): + if not path.endswith("ripme.jar"): + print("Specified file is not named ripme.jar, renaming") + # os.sep is the path separator for the os this is being run on + os.rename(path, path.split(os.sep)[0] + os.sep + "ripme.jar") + return path.split(os.sep)[0] + os.sep + "ripme.jar" + return path + + ripmeJson = json.loads(open("ripme.json").read()) -fileToUploadPath = args.file +fileToUploadPath = renameFile(args.file) InNoninteractiveMode = args.non_interactive commitMessage = ripmeJson.get("changeList")[0] releaseVersion = ripmeJson.get("latestVersion") @@ -63,11 +76,12 @@ if not isValidCommitMessage(commitMessage): ripmeUpdate = open(fileToUploadPath, mode='rb').read() +# The actual hash of the file on disk +actualHash = sha256(ripmeUpdate).hexdigest() + # The hash that we expect the update to have expectedHash = ripmeJson.get("currentHash") -# The actual hash of the file on disk -actualHash = sha256(ripmeUpdate).hexdigest() # 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 @@ -85,12 +99,12 @@ if not InNoninteractiveMode: print("Repo: {}/{}".format(repoOwner, repoName)) input("\nPlease review the information above and ensure it is correct and then press enter") -print("Accessing github using token") -g = Github(accessToken) +if args.test: + print("Accessing github using token") + g = Github(accessToken) + print("Creating release") + release = g.get_user(repoOwner).get_repo(repoName).create_git_release(releaseVersion, commitMessage, "") -print("Creating release") -release = g.get_user(repoOwner).get_repo(repoName).create_git_release(releaseVersion, commitMessage, "") - -print("Uploading file") -release.upload_asset(fileToUploadPath, "ripme.jar") + print("Uploading file") + release.upload_asset(fileToUploadPath, "ripme.jar") diff --git a/releaseTests.py b/releaseTests.py new file mode 100644 index 00000000..e69de29b From 80e63aa291592b30baf31522d8f2fb7b87f412d9 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Mon, 11 Jun 2018 19:10:09 -0400 Subject: [PATCH 2/3] [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 --- release.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/release.py b/release.py index 9b199bf6..04ad7e08 100644 --- a/release.py +++ b/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("-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("--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() try: @@ -40,8 +41,10 @@ def isValidCommitMessage(message): pattern = re.compile("^\d+\.\d+\.\d+:") return re.match(pattern, message) + # Checks if the update has the name ripme.jar, if not it renames the file # Returns the update file path +# TODO handle files that aren't in sub dirs def renameFile(path): if not path.endswith("ripme.jar"): print("Specified file is not named ripme.jar, renaming") @@ -51,7 +54,6 @@ def renameFile(path): return path - ripmeJson = json.loads(open("ripme.json").read()) fileToUploadPath = renameFile(args.file) 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)) sys.exit(1) -ripmeUpdate = open(fileToUploadPath, mode='rb').read() -# The actual hash of the file on disk -actualHash = sha256(ripmeUpdate).hexdigest() +if not args.skip_hash_check: + if debug: + print("Reading file {}".format(fileToUploadPath)) + ripmeUpdate = open(fileToUploadPath, mode='rb').read() -# The hash that we expect the update to have -expectedHash = ripmeJson.get("currentHash") + # The actual hash of the file on disk + 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 -# cause ripme to refuse to install the update for all users who haven't disabled update hash checking -if expectedHash != actualHash: - print("[!] Error: expected hash of file and actual hash differ") - print("[!] Expected hash is {}".format(expectedHash)) - print("[!] Actual hash is {}".format(actualHash)) - sys.exit(1) - + # 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 + if expectedHash != actualHash: + print("[!] Error: expected hash of file and actual hash differ") + print("[!] Expected hash is {}".format(expectedHash)) + print("[!] Actual hash is {}".format(actualHash)) + sys.exit(1) +else: + print("[*] WARNING: SKIPPING HASH CHECK") # Ask the user to review the information before we precede # This only runs in we're in interactive mode if not InNoninteractiveMode: @@ -99,7 +105,7 @@ if not InNoninteractiveMode: print("Repo: {}/{}".format(repoOwner, repoName)) 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") g = Github(accessToken) @@ -108,3 +114,5 @@ if args.test: print("Uploading file") release.upload_asset(fileToUploadPath, "ripme.jar") +else: + print("Not uploading release being script was run with --test flag") From d2d59e73cdac1d1c15135dad5b3931f2478ba6ec Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Mon, 11 Jun 2018 19:10:36 -0400 Subject: [PATCH 3/3] Remove empty file --- releaseTests.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 releaseTests.py diff --git a/releaseTests.py b/releaseTests.py deleted file mode 100644 index e69de29b..00000000