2018-06-07 12:16:27 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2018-06-06 18:09:48 +02:00
|
|
|
import re
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
import sys
|
2018-06-06 18:33:53 +02:00
|
|
|
from hashlib import sha256
|
2018-06-06 18:09:48 +02:00
|
|
|
from github import Github
|
|
|
|
import json
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="Make a new ripme release on github")
|
|
|
|
parser.add_argument("-f", "--file", help="Path to the version of ripme to release")
|
|
|
|
parser.add_argument("-t", "--token", help="Your github personal access token")
|
|
|
|
parser.add_argument("-d", "--debug", help="Run in debug mode", action="store_true")
|
2018-06-06 18:33:53 +02:00
|
|
|
parser.add_argument("-n", "--non-interactive", help="Do not ask for any input from the user", action="store_true")
|
2018-06-06 18:09:48 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2018-06-07 12:25:49 +02:00
|
|
|
try:
|
|
|
|
input = raw_input
|
|
|
|
except NameError:
|
|
|
|
pass
|
|
|
|
|
2018-06-06 18:09:48 +02:00
|
|
|
|
|
|
|
# Make sure the file the user selected is a jar
|
|
|
|
def isJar(filename):
|
|
|
|
if debug:
|
|
|
|
print("Checking if {} is a jar file".format(filename))
|
|
|
|
return filename.endswith("jar")
|
|
|
|
|
|
|
|
|
2018-06-06 18:33:53 +02:00
|
|
|
# Returns true if last entry to the "changeList" section of ripme.json is in the format of $number.$number.$number: and
|
|
|
|
# false if not
|
2018-06-06 18:09:48 +02:00
|
|
|
def isValidCommitMessage(message):
|
|
|
|
if debug:
|
|
|
|
print("Checking if {} matchs pattern ^\d+\.\d+\.\d+:".format(message))
|
|
|
|
pattern = re.compile("^\d+\.\d+\.\d+:")
|
|
|
|
return re.match(pattern, message)
|
|
|
|
|
|
|
|
|
2018-06-06 18:33:53 +02:00
|
|
|
ripmeJson = json.loads(open("ripme.json").read())
|
|
|
|
fileToUploadPath = args.file
|
|
|
|
InNoninteractiveMode = args.non_interactive
|
|
|
|
commitMessage = ripmeJson.get("changeList")[0]
|
2018-06-07 12:07:03 +02:00
|
|
|
releaseVersion = ripmeJson.get("latestVersion")
|
2018-06-06 18:09:48 +02:00
|
|
|
debug = args.debug
|
2018-06-07 10:48:43 +02:00
|
|
|
accessToken = args.token
|
2018-06-07 12:07:03 +02:00
|
|
|
repoOwner = "ripmeapp"
|
|
|
|
repoName = "ripme"
|
2018-06-06 18:09:48 +02:00
|
|
|
|
2018-06-06 18:33:53 +02:00
|
|
|
if not os.path.isfile(fileToUploadPath):
|
|
|
|
print("[!] Error: {} does not exist".format(fileToUploadPath))
|
2018-06-06 18:09:48 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2018-06-06 18:33:53 +02:00
|
|
|
if not isJar(fileToUploadPath):
|
|
|
|
print("[!] Error: {} is not a jar file!".format(fileToUploadPath))
|
2018-06-06 18:09:48 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if not isValidCommitMessage(commitMessage):
|
2018-06-06 18:33:53 +02:00
|
|
|
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 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
|
|
|
|
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))
|
2018-06-07 12:15:14 +02:00
|
|
|
sys.exit(1)
|
2018-06-06 18:33:53 +02:00
|
|
|
|
2018-06-07 10:48:43 +02:00
|
|
|
# Ask the user to review the information before we precede
|
2018-06-06 18:33:53 +02:00
|
|
|
# This only runs in we're in interactive mode
|
|
|
|
if not InNoninteractiveMode:
|
2018-06-07 12:07:03 +02:00
|
|
|
print("File path: {}".format(fileToUploadPath))
|
2018-06-06 18:33:53 +02:00
|
|
|
print("Release title: {}".format(commitMessage))
|
2018-06-07 12:07:03 +02:00
|
|
|
print("Repo: {}/{}".format(repoOwner, repoName))
|
2018-06-07 10:48:43 +02:00
|
|
|
input("\nPlease review the information above and ensure it is correct and then press enter")
|
|
|
|
|
|
|
|
print("Accessing github using token")
|
2018-06-07 12:07:03 +02:00
|
|
|
g = Github(accessToken)
|
|
|
|
|
|
|
|
|
|
|
|
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")
|