-
Notifications
You must be signed in to change notification settings - Fork 5
/
uploader.py
118 lines (93 loc) · 3.32 KB
/
uploader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import sys
import os
import tarfile
import shutil
import glob
import subprocess
version = os.environ['GITHUB_REF'].split('/')[-1]
print(f'version: {version}')
_, os_name, token = sys.argv
osn = os_name.split('-')[0]
cwd = os.path.realpath('.')
folder_name = os.path.realpath('./dist/Ninja-Preview/')
dist_folder = os.path.realpath('./dist/')
# Download Qmlview archive for os
# extract to folder
# copy all those contents to folder_name, skipping the existing ones
def change_iss():
with open('ninja_preview_template.iss', 'r') as iss_file:
conts = iss_file.read()
# version number
conts = conts.replace('{{version_number}}', version[1:])
# curr dir
conts = conts.replace('{{curr_dir}}', cwd)
with open('ninja_preview_setup.iss', 'w') as iss_write:
iss_write.write(conts)
# Login to GH
with open('token.txt', 'w') as tok:
tok.write(token)
print('Finished writing token file')
cmd = 'gh auth login --with-token < token.txt'
os.system(cmd)
print('Authenticated')
# Build archives
if os_name == 'windows-latest':
# Download Qmlview archive for os
os_cmd = 'gh release download --repo'
os_cmd += ' github.com/amoh-godwin/Qmlview --pattern "*.zip"'
os.system(os_cmd)
print('done with download of Qmlviews')
# extract to folder
arch = glob.glob('qmlview*.zip')[0]
shutil.unpack_archive(arch, extract_dir=folder_name)
# copy all those contents to folder_name, skip exitsting
print('done with unpack')
# instead of a zip make Inno setup file
# Extract inno setup
shutil.unpack_archive(os.path.join(cwd, 'inno.zip'))
print('done unpacking inno setup')
# Inno setup workings
change_iss()
inno_script = os.path.join(cwd, 'ninja_preview_setup.iss')
os.chdir('inno')
inno_cmd = f'iscc "{inno_script}"'
out = subprocess.run(inno_cmd, capture_output=True)
print('Inno script done changing back to directory')
# change directory back
os.chdir('..')
# rename
try:
old_file = os.path.join(cwd, 'dist',
f"Ninja-Preview-{version[1:]}-setup.exe")
filename = os.path.join(cwd, 'dist',
f'Ninja_Preview_{version}_{osn}-setup.exe')
os.replace(old_file, filename)
except:
print('failed trying something else')
print(os.listdir(dist_folder))
old_file = os.path.join(cwd, 'dist',
f"Ninja-Preview-{version[1:]}-setup")
filename = os.path.join(cwd, 'dist',
f'Ninja_Preview_{version}_{osn}-setup.exe')
os.replace(old_file, filename)
else:
# Download Qmlview archive for os
os_cmd = 'gh release download --repo'
os_cmd += ' github.com/amoh-godwin/Qmlview --pattern "*.tar.gz"'
os.system(os_cmd)
print('done with download of Qmlview')
# extract to folder
arch = glob.glob('qmlview*.tar.gz')[0]
shutil.unpack_archive(arch, extract_dir=folder_name)
print('done with unpack')
# copy all those contents to folder_name, skip existing
# tar.gz file
old_file = shutil.make_archive('Ninja_Preview', 'gztar',
root_dir=dist_folder, base_dir=folder_name)
filename = os.path.join(dist_folder,
f'Ninja_Preview_{version}_{osn}.tar.gz')
os.replace(old_file, filename)
print(f'filename: {filename}')
cmd1 = f'gh release upload {version} {filename}'
os.system(cmd1)
print('All Done')