From 3a5cce43cc8c094276214bf6c7c55010d14d0e6b Mon Sep 17 00:00:00 2001 From: Joey Payne Date: Thu, 26 Nov 2015 19:03:52 -0700 Subject: [PATCH] Updated bash scripts to automatically upload files to github. --- build_command_line_linux.bash | 2 ++ build_mac.bash | 2 ++ build_windows.bat | 2 ++ upload_release.py | 68 +++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 upload_release.py diff --git a/build_command_line_linux.bash b/build_command_line_linux.bash index ecc3171..f67b606 100755 --- a/build_command_line_linux.bash +++ b/build_command_line_linux.bash @@ -18,3 +18,5 @@ rm Web2ExeLinux/files/error.log Web2ExeLinux/files/last_project_path.txt Web2Exe zip -r -9 Web2ExeLinux-CMD.zip Web2ExeLinux-CMD/* zip -r -9 Web2ExeLinux-${VERSION}.zip Web2ExeLinux + +python upload_release.py diff --git a/build_mac.bash b/build_mac.bash index fe0194a..6206646 100755 --- a/build_mac.bash +++ b/build_mac.bash @@ -30,3 +30,5 @@ rm -rf build dist /Applications/Keka.app/Contents/Resources/keka7z a -r Web2ExeMac-CMD.zip Web2ExeMac-CMD /Applications/Keka.app/Contents/Resources/keka7z a -r Web2ExeMac-${VERSION}.zip Web2Executable.app + +python upload_release.py diff --git a/build_windows.bat b/build_windows.bat index ee9102c..a602ca3 100755 --- a/build_windows.bat +++ b/build_windows.bat @@ -24,3 +24,5 @@ cd command_line_builds 7z a ..\Web2ExeWin-CMD.zip -tzip -r * cd .. 7z a Web2Exe-Setup.zip Web2Exe-Setup.exe + +call python upload_release.py diff --git a/upload_release.py b/upload_release.py new file mode 100644 index 0000000..ac12049 --- /dev/null +++ b/upload_release.py @@ -0,0 +1,68 @@ +#!/usr/bin/python + +import requests +import json +from pprint import pprint +from glob import glob + +from semantic_version import Version +import getpass +import sys + +def main(): + + version = "" + with open('files/version.txt') as f: + version = f.read().strip() + + base_url = 'https://api.github.com/repos/jyapayne/Web2Executable/releases' + + req = requests.get(base_url+'/tags/'+version) + + update = False + rel_id = None + upload_url = None + + github_user = raw_input('Github user:') + + password = getpass.getpass('Password:') + + if req.status_code == 200: + json_data = json.loads(req.text) + tag = json_data.get('tag_name', '') + cur_ver = Version(tag[1:-1]) + new_ver = Version(version[1:-1]) + if new_ver <= cur_ver: + update = True + rel_id = json_data['id'] + upload_url = json_data['upload_url'].replace('{?name,label}', '') + + if not update: + data = {'tag_name': version, + 'target_commitish': 'master', + 'name': 'Web2Executable ' + version} + post_res = requests.post(base_url, data=json.dumps(data), auth=(github_user, password)) + if post_res.status_code == 201: + json_data = json.loads(post_res.text) + upload_url = json_data['upload_url'].replace('{?name,label}', '') + rel_id = json_data['id'] + else: + print 'Authentication failed!' + + if rel_id: + zip_files = glob('*.zip') + for zip_file in zip_files: + with open(zip_file, 'rb') as zipf: + file_data = zipf.read() + print 'Uploading file {}...'.format(zip_file) + data = {'name': zip_file} + headers = {'Content-Type': 'application/zip'} + r = requests.post(upload_url, params=data, data=file_data, headers=headers, auth=(github_user, password)) + if r.status_code == 201: + print 'Success!' + else: + print 'Error:', r.text + + +if __name__ == '__main__': + main()