Skip to content

Commit 3a5cce4

Browse files
committed
Updated bash scripts to automatically upload files to github.
1 parent 8378130 commit 3a5cce4

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

build_command_line_linux.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ rm Web2ExeLinux/files/error.log Web2ExeLinux/files/last_project_path.txt Web2Exe
1818

1919
zip -r -9 Web2ExeLinux-CMD.zip Web2ExeLinux-CMD/*
2020
zip -r -9 Web2ExeLinux-${VERSION}.zip Web2ExeLinux
21+
22+
python upload_release.py

build_mac.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ rm -rf build dist
3030

3131
/Applications/Keka.app/Contents/Resources/keka7z a -r Web2ExeMac-CMD.zip Web2ExeMac-CMD
3232
/Applications/Keka.app/Contents/Resources/keka7z a -r Web2ExeMac-${VERSION}.zip Web2Executable.app
33+
34+
python upload_release.py

build_windows.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ cd command_line_builds
2424
7z a ..\Web2ExeWin-CMD.zip -tzip -r *
2525
cd ..
2626
7z a Web2Exe-Setup.zip Web2Exe-Setup.exe
27+
28+
call python upload_release.py

upload_release.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/python
2+
3+
import requests
4+
import json
5+
from pprint import pprint
6+
from glob import glob
7+
8+
from semantic_version import Version
9+
import getpass
10+
import sys
11+
12+
def main():
13+
14+
version = ""
15+
with open('files/version.txt') as f:
16+
version = f.read().strip()
17+
18+
base_url = 'https://api.github.com/repos/jyapayne/Web2Executable/releases'
19+
20+
req = requests.get(base_url+'/tags/'+version)
21+
22+
update = False
23+
rel_id = None
24+
upload_url = None
25+
26+
github_user = raw_input('Github user:')
27+
28+
password = getpass.getpass('Password:')
29+
30+
if req.status_code == 200:
31+
json_data = json.loads(req.text)
32+
tag = json_data.get('tag_name', '')
33+
cur_ver = Version(tag[1:-1])
34+
new_ver = Version(version[1:-1])
35+
if new_ver <= cur_ver:
36+
update = True
37+
rel_id = json_data['id']
38+
upload_url = json_data['upload_url'].replace('{?name,label}', '')
39+
40+
if not update:
41+
data = {'tag_name': version,
42+
'target_commitish': 'master',
43+
'name': 'Web2Executable ' + version}
44+
post_res = requests.post(base_url, data=json.dumps(data), auth=(github_user, password))
45+
if post_res.status_code == 201:
46+
json_data = json.loads(post_res.text)
47+
upload_url = json_data['upload_url'].replace('{?name,label}', '')
48+
rel_id = json_data['id']
49+
else:
50+
print 'Authentication failed!'
51+
52+
if rel_id:
53+
zip_files = glob('*.zip')
54+
for zip_file in zip_files:
55+
with open(zip_file, 'rb') as zipf:
56+
file_data = zipf.read()
57+
print 'Uploading file {}...'.format(zip_file)
58+
data = {'name': zip_file}
59+
headers = {'Content-Type': 'application/zip'}
60+
r = requests.post(upload_url, params=data, data=file_data, headers=headers, auth=(github_user, password))
61+
if r.status_code == 201:
62+
print 'Success!'
63+
else:
64+
print 'Error:', r.text
65+
66+
67+
if __name__ == '__main__':
68+
main()

0 commit comments

Comments
 (0)