tdesktop/Telegram/build/updates.py

211 lines
7.4 KiB
Python
Raw Normal View History

2019-04-19 14:08:21 +00:00
import os, sys, re, subprocess, datetime, time
executePath = os.getcwd()
scriptPath = os.path.dirname(os.path.realpath(__file__))
lastCommit = ''
today = ''
uuid = ''
nextLast = False
nextDate = False
nextUuid = False
building = True
2018-12-25 15:42:02 +00:00
composing = False
2023-08-18 21:03:05 +00:00
conf = 'Release'
for arg in sys.argv:
if nextLast:
lastCommit = arg
nextLast = False
elif nextDate:
today = arg
nextDate = False
elif nextUuid:
uuid = arg
nextUuid = False
elif arg == 'send':
building = False
2018-12-25 15:42:02 +00:00
composing = False
elif arg == 'from':
nextLast = True
2018-12-25 15:42:02 +00:00
building = False
composing = True
elif arg == 'date':
nextDate = True
elif arg == 'request_uuid':
nextUuid = True
2023-08-18 21:03:05 +00:00
elif arg == 'debug':
conf = 'Debug'
2019-04-19 14:08:21 +00:00
def finish(code, error = ''):
if error != '':
print('[ERROR] ' + error)
global executePath
os.chdir(executePath)
sys.exit(code)
os.chdir(scriptPath + '/..')
2019-04-19 14:08:21 +00:00
if 'AC_USERNAME' not in os.environ:
finish(1, 'AC_USERNAME not found!')
username = os.environ['AC_USERNAME']
if today == '':
today = datetime.datetime.now().strftime("%d_%m_%y")
outputFolder = 'updates/' + today
archive = 'tdesktop_macOS_' + today + '.zip'
if building:
print('Building ' + conf + ' version for OS X 10.13+..')
2023-08-18 21:03:05 +00:00
if os.path.exists('../out/' + conf + '/' + outputFolder):
2019-04-19 14:08:21 +00:00
finish(1, 'Todays updates version exists.')
if uuid == '':
result = subprocess.call('./configure.sh', shell=True)
if result != 0:
finish(1, 'While calling GYP.')
os.chdir('../out')
if uuid == '':
2023-08-18 21:03:05 +00:00
result = subprocess.call('cmake --build . --config ' + conf + ' --target Telegram', shell=True)
if result != 0:
finish(1, 'While building Telegram.')
2023-08-18 21:03:05 +00:00
os.chdir(conf);
2019-04-19 14:08:21 +00:00
if uuid == '':
if not os.path.exists('Telegram.app'):
finish(1, 'Telegram.app not found.')
result = subprocess.call('strip Telegram.app/Contents/MacOS/Telegram', shell=True)
if result != 0:
finish(1, 'While stripping Telegram.')
result = subprocess.call('codesign --force --deep --timestamp --options runtime --sign "Developer ID Application: John Preston" Telegram.app --entitlements "../../Telegram/Telegram/Telegram.entitlements"', shell=True)
if result != 0:
finish(1, 'While signing Telegram.')
if not os.path.exists('Telegram.app/Contents/Frameworks/Updater'):
finish(1, 'Updater not found.')
elif not os.path.exists('Telegram.app/Contents/Helpers/crashpad_handler'):
finish(1, 'crashpad_handler not found.')
elif not os.path.exists('Telegram.app/Contents/Resources/Icon.icns'):
finish(1, 'Icon not found.')
elif not os.path.exists('Telegram.app/Contents/_CodeSignature'):
finish(1, 'Signature not found.')
if os.path.exists(today):
subprocess.call('rm -rf ' + today, shell=True)
result = subprocess.call('mkdir -p ' + today + '/TelegramForcePortable', shell=True)
if result != 0:
finish(1, 'Creating folder ' + today + '/TelegramForcePortable')
result = subprocess.call('cp -r Telegram.app ' + today + '/', shell=True)
if result != 0:
finish(1, 'Cloning Telegram.app to ' + today + '.')
result = subprocess.call('zip -r ' + archive + ' ' + today, shell=True)
if result != 0:
finish(1, 'Adding tdesktop to archive.')
print('Beginning notarization process.')
result = subprocess.call('xcrun notarytool submit "' + archive + '" --keychain-profile "preston" --wait', shell=True)
if result != 0:
finish(1, 'Notarizing the archive.')
2019-04-19 14:08:21 +00:00
result = subprocess.call('xcrun stapler staple Telegram.app', shell=True)
if result != 0:
finish(1, 'Error calling stapler')
2019-04-19 14:08:21 +00:00
subprocess.call('rm -rf ' + today + '/Telegram.app', shell=True)
subprocess.call('rm ' + archive, shell=True)
result = subprocess.call('cp -r Telegram.app ' + today + '/', shell=True)
if result != 0:
2019-04-19 14:08:21 +00:00
finish(1, 'Re-Cloning Telegram.app to ' + today + '.')
result = subprocess.call('zip -r ' + archive + ' ' + today, shell=True)
if result != 0:
2019-04-19 14:08:21 +00:00
finish(1, 'Re-Adding tdesktop to archive.')
print('Re-Archived.')
subprocess.call('mkdir -p ' + outputFolder, shell=True)
subprocess.call('mv ' + archive + ' ' + outputFolder + '/', shell=True)
subprocess.call('rm -rf ' + today, shell=True)
print('Finished.')
finish(0)
2023-08-18 21:03:05 +00:00
commandPath = scriptPath + '/../../out/' + conf + '/' + outputFolder + '/command.txt'
2019-01-28 09:39:05 +00:00
2018-12-25 15:42:02 +00:00
if composing:
2019-09-26 09:52:36 +00:00
templatePath = scriptPath + '/../../../DesktopPrivate/updates_template.txt'
2018-12-25 15:42:02 +00:00
if not os.path.exists(templatePath):
2019-04-19 14:08:21 +00:00
finish(1, 'Template file "' + templatePath + '" not found.')
2019-07-19 15:39:36 +00:00
if not re.match(r'^[a-f0-9]{9,40}$', lastCommit):
2019-04-19 14:08:21 +00:00
finish(1, 'Wrong last commit: ' + lastCommit)
2022-06-10 13:38:52 +00:00
log = subprocess.check_output(['git', 'log', lastCommit+'..HEAD']).decode('utf-8')
2018-12-25 15:42:02 +00:00
logLines = log.split('\n')
firstCommit = ''
commits = []
for line in logLines:
if line.startswith('commit '):
commit = line.split(' ')[1]
if not len(firstCommit):
firstCommit = commit
commits.append('')
elif line.startswith(' '):
stripped = line[4:]
if not len(stripped):
continue
elif not len(commits):
print(log)
2019-04-19 14:08:21 +00:00
finish(1, 'Bad git log output.')
2018-12-25 15:42:02 +00:00
if len(commits[len(commits) - 1]):
commits[len(commits) - 1] += '\n' + stripped
else:
commits[len(commits) - 1] = '- ' + stripped
commits.reverse()
if not len(commits):
2019-04-19 14:08:21 +00:00
finish(1, 'No commits since last build :(')
2018-12-25 15:42:02 +00:00
changelog = '\n'.join(commits)
print('\n\nReady! File: ' + archive + '\nChangelog:\n' + changelog)
with open(templatePath, 'r') as template:
2019-01-28 09:39:05 +00:00
with open(commandPath, 'w') as f:
2018-12-25 15:42:02 +00:00
for line in template:
if line.startswith('//'):
continue
2023-08-18 21:03:05 +00:00
line = line.replace('{path}', scriptPath + '/../../out/' + conf + '/' + outputFolder + '/' + archive)
2018-12-25 15:42:02 +00:00
line = line.replace('{caption}', 'TDesktop at ' + today.replace('_', '.') + ':\n\n' + changelog)
f.write(line)
2019-01-28 09:39:05 +00:00
print('\n\nEdit:\n')
print('vi ' + commandPath)
2018-12-25 15:42:02 +00:00
finish(0)
2018-12-25 15:42:02 +00:00
if not os.path.exists(commandPath):
2019-04-19 14:08:21 +00:00
finish(1, 'Command file not found.')
2018-12-25 15:42:02 +00:00
readingCaption = False
caption = ''
with open(commandPath, 'r') as f:
for line in f:
if readingCaption:
caption = caption + line
elif line.startswith('caption: '):
readingCaption = True
caption = line[len('caption: '):]
if not caption.startswith('TDesktop at ' + today.replace('_', '.') + ':'):
2019-04-19 14:08:21 +00:00
finish(1, 'Wrong caption start.')
2018-12-25 15:42:02 +00:00
print('\n\nSending! File: ' + archive + '\nChangelog:\n' + caption)
if len(caption) > 1024:
2019-04-19 14:08:21 +00:00
print('Length: ' + str(len(caption)))
2018-12-25 15:42:02 +00:00
print('vi ' + commandPath)
2019-04-19 14:08:21 +00:00
finish(1, 'Too large.')
2023-08-18 21:03:05 +00:00
if not os.path.exists('../out/' + conf + '/' + outputFolder + '/' + archive):
2019-04-19 14:08:21 +00:00
finish(1, 'Not built yet.')
2018-12-25 15:42:02 +00:00
2023-08-18 21:03:05 +00:00
subprocess.call(scriptPath + '/../../out/' + conf + '/Telegram.app/Contents/MacOS/Telegram -sendpath interpret://' + scriptPath + '/../../out/' + conf + '/' + outputFolder + '/command.txt', shell=True)
finish(0)