Add some automation for updates posting.
This commit is contained in:
		
							parent
							
								
									9f08faf263
								
							
						
					
					
						commit
						684ce09bb5
					
				
					 5 changed files with 241 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -86,6 +86,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
#include "export/view/export_view_top_bar.h"
 | 
			
		||||
#include "export/view/export_view_panel_controller.h"
 | 
			
		||||
#include "auth_session.h"
 | 
			
		||||
#include "support/support_helper.h"
 | 
			
		||||
#include "storage/storage_facade.h"
 | 
			
		||||
#include "storage/storage_shared_media.h"
 | 
			
		||||
#include "storage/storage_user_photos.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -3602,7 +3603,17 @@ void MainWidget::activate() {
 | 
			
		|||
			_dialogs->activate();
 | 
			
		||||
        } else if (App::wnd() && !Ui::isLayerShown()) {
 | 
			
		||||
			if (!cSendPaths().isEmpty()) {
 | 
			
		||||
				const auto interpret = qstr("interpret://");
 | 
			
		||||
				const auto path = cSendPaths()[0];
 | 
			
		||||
				if (path.startsWith(interpret)) {
 | 
			
		||||
					cSetSendPaths(QStringList());
 | 
			
		||||
					const auto error = Support::InterpretSendPath(path.mid(interpret.size()));
 | 
			
		||||
					if (!error.isEmpty()) {
 | 
			
		||||
						Ui::show(Box<InformBox>(error));
 | 
			
		||||
					}
 | 
			
		||||
				} else {
 | 
			
		||||
					showSendPathsLayer();
 | 
			
		||||
				}
 | 
			
		||||
			} else if (_history->peer()) {
 | 
			
		||||
				_history->activate();
 | 
			
		||||
			} else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,6 +19,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
#include "chat_helpers/emoji_suggestions_widget.h"
 | 
			
		||||
#include "lang/lang_keys.h"
 | 
			
		||||
#include "window/window_controller.h"
 | 
			
		||||
#include "storage/storage_media_prepare.h"
 | 
			
		||||
#include "storage/localimageloader.h"
 | 
			
		||||
#include "auth_session.h"
 | 
			
		||||
#include "observer_peer.h"
 | 
			
		||||
#include "apiwrap.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -537,4 +539,51 @@ QString ChatOccupiedString(not_null<History*> history) {
 | 
			
		|||
		: hand + ' ' + name + " is here";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString InterpretSendPath(const QString &path) {
 | 
			
		||||
	QFile f(path);
 | 
			
		||||
	if (!f.open(QIODevice::ReadOnly)) {
 | 
			
		||||
		return "App Error: Could not open interpret file: " + path;
 | 
			
		||||
	}
 | 
			
		||||
	const auto content = QString::fromUtf8(f.readAll());
 | 
			
		||||
	f.close();
 | 
			
		||||
	const auto lines = content.split('\n');
 | 
			
		||||
	auto toId = PeerId(0);
 | 
			
		||||
	auto filePath = QString();
 | 
			
		||||
	auto caption = QString();
 | 
			
		||||
	for (const auto &line : lines) {
 | 
			
		||||
		if (line.startsWith(qstr("from: "))) {
 | 
			
		||||
			if (Auth().userId() != line.mid(qstr("from: ").size()).toInt()) {
 | 
			
		||||
				return "App Error: Wrong current user.";
 | 
			
		||||
			}
 | 
			
		||||
		} else if (line.startsWith(qstr("channel: "))) {
 | 
			
		||||
			const auto channelId = line.mid(qstr("channel: ").size()).toInt();
 | 
			
		||||
			toId = peerFromChannel(channelId);
 | 
			
		||||
		} else if (line.startsWith(qstr("file: "))) {
 | 
			
		||||
			const auto path = line.mid(qstr("file: ").size());
 | 
			
		||||
			if (!QFile(path).exists()) {
 | 
			
		||||
				return "App Error: Could not find file with path: " + path;
 | 
			
		||||
			}
 | 
			
		||||
			filePath = path;
 | 
			
		||||
		} else if (line.startsWith(qstr("caption: "))) {
 | 
			
		||||
			caption = line.mid(qstr("caption: ").size());
 | 
			
		||||
		} else if (!caption.isEmpty()) {
 | 
			
		||||
			caption += '\n' + line;
 | 
			
		||||
		} else {
 | 
			
		||||
			return "App Error: Invalid command: " + line;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	const auto history = App::historyLoaded(toId);
 | 
			
		||||
	if (!history) {
 | 
			
		||||
		return "App Error: Could not find channel with id: " + QString::number(peerToChannel(toId));
 | 
			
		||||
	}
 | 
			
		||||
	Ui::showPeerHistory(history, ShowAtUnreadMsgId);
 | 
			
		||||
	Auth().api().sendFiles(
 | 
			
		||||
		Storage::PrepareMediaList(QStringList(filePath), st::sendMediaPreviewSize),
 | 
			
		||||
		SendMediaType::File,
 | 
			
		||||
		{ caption },
 | 
			
		||||
		nullptr,
 | 
			
		||||
		ApiWrap::SendOptions(history));
 | 
			
		||||
	return QString();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace Support
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -100,4 +100,6 @@ private:
 | 
			
		|||
 | 
			
		||||
QString ChatOccupiedString(not_null<History*> history);
 | 
			
		||||
 | 
			
		||||
QString InterpretSendPath(const QString &path);
 | 
			
		||||
 | 
			
		||||
} // namespace Support
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										156
									
								
								Telegram/build/updates.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										156
									
								
								Telegram/build/updates.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,156 @@
 | 
			
		|||
import os, sys, re, subprocess, datetime
 | 
			
		||||
 | 
			
		||||
print('Building debug version for OS X 10.8+..')
 | 
			
		||||
 | 
			
		||||
executePath = os.getcwd()
 | 
			
		||||
scriptPath = os.path.dirname(os.path.realpath(__file__))
 | 
			
		||||
 | 
			
		||||
lastCommit = ''
 | 
			
		||||
today = ''
 | 
			
		||||
nextLast = False
 | 
			
		||||
nextDate = False
 | 
			
		||||
sending = False
 | 
			
		||||
for arg in sys.argv:
 | 
			
		||||
    if nextLast:
 | 
			
		||||
        lastCommit = arg
 | 
			
		||||
        nextLast = False
 | 
			
		||||
    elif nextDate:
 | 
			
		||||
        today = arg
 | 
			
		||||
        nextDate = False
 | 
			
		||||
    elif arg == 'send':
 | 
			
		||||
        sending = True
 | 
			
		||||
    elif arg == 'from':
 | 
			
		||||
        nextLast = True
 | 
			
		||||
    elif arg == 'date':
 | 
			
		||||
        nextDate = True
 | 
			
		||||
 | 
			
		||||
def finish(code):
 | 
			
		||||
    global executePath
 | 
			
		||||
    os.chdir(executePath)
 | 
			
		||||
    sys.exit(code)
 | 
			
		||||
 | 
			
		||||
os.chdir(scriptPath + '/..')
 | 
			
		||||
 | 
			
		||||
if today == '':
 | 
			
		||||
    today = datetime.datetime.now().strftime("%d_%m_%y")
 | 
			
		||||
outputFolder = 'updates/' + today
 | 
			
		||||
 | 
			
		||||
if os.path.exists('../out/Debug/' + outputFolder):
 | 
			
		||||
    if sending:
 | 
			
		||||
        #subprocess.call(['/Applications/Telegram.app/Contents/MacOS/Telegram', '-sendpath', 'interpret://' + scriptPath + '../../out/Debug/' + outputFolder + '/command.txt'], shell=True)
 | 
			
		||||
        subprocess.call(scriptPath + '/../../out/Debug/Telegram.app/Contents/MacOS/Telegram -sendpath interpret://' + scriptPath + '/../../out/Debug/' + outputFolder + '/command.txt', shell=True)
 | 
			
		||||
        finish(0)
 | 
			
		||||
    else:
 | 
			
		||||
        print('[ERROR] Todays updates version exists.')
 | 
			
		||||
        finish(1)
 | 
			
		||||
 | 
			
		||||
templatePath = scriptPath + '/../../../TelegramPrivate/updates_template.txt'
 | 
			
		||||
if not os.path.exists(templatePath):
 | 
			
		||||
    print('[ERROR] Template file "' + templatePath + '" not found.')
 | 
			
		||||
    finish(1)
 | 
			
		||||
 | 
			
		||||
if not re.match(r'^[a-f0-9]{40}$', lastCommit):
 | 
			
		||||
    print('[ERROR] Wrong last commit: ' + lastCommit)
 | 
			
		||||
    finish(1)
 | 
			
		||||
 | 
			
		||||
log = subprocess.check_output(['git', 'log', lastCommit+'..HEAD'])
 | 
			
		||||
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('[ERROR] Bad git log output:')
 | 
			
		||||
            print(log)
 | 
			
		||||
            finish(1)
 | 
			
		||||
        if len(commits[len(commits) - 1]):
 | 
			
		||||
            commits[len(commits) - 1] += '\n' + stripped
 | 
			
		||||
        else:
 | 
			
		||||
            commits[len(commits) - 1] = '- ' + stripped
 | 
			
		||||
commits.reverse()
 | 
			
		||||
if not len(commits):
 | 
			
		||||
    print('[ERROR] No commits since last build :(')
 | 
			
		||||
    finish(1)
 | 
			
		||||
 | 
			
		||||
result = subprocess.call('gyp/refresh.sh', shell=True)
 | 
			
		||||
if result != 0:
 | 
			
		||||
    print('[ERROR] While calling GYP.')
 | 
			
		||||
    finish(1)
 | 
			
		||||
 | 
			
		||||
result = subprocess.call('xcodebuild -project Telegram.xcodeproj -alltargets -configuration Debug build', shell=True)
 | 
			
		||||
if result != 0:
 | 
			
		||||
    print('[ERROR] While building Telegram.')
 | 
			
		||||
    finish(1)
 | 
			
		||||
 | 
			
		||||
os.chdir('../out/Debug')
 | 
			
		||||
if not os.path.exists('Telegram.app'):
 | 
			
		||||
    print('[ERROR] Telegram.app not found.')
 | 
			
		||||
    finish(1)
 | 
			
		||||
 | 
			
		||||
result = subprocess.call('strip Telegram.app/Contents/MacOS/Telegram', shell=True)
 | 
			
		||||
if result != 0:
 | 
			
		||||
    print('[ERROR] While stripping Telegram.')
 | 
			
		||||
    finish(1)
 | 
			
		||||
 | 
			
		||||
result = subprocess.call('codesign --force --deep --sign "Developer ID Application: John Preston" Telegram.app', shell=True)
 | 
			
		||||
if result != 0:
 | 
			
		||||
    print('[ERROR] While signing Telegram.')
 | 
			
		||||
    finish(1)
 | 
			
		||||
 | 
			
		||||
if not os.path.exists('Telegram.app/Contents/Frameworks/Updater'):
 | 
			
		||||
    print('[ERROR] Updater not found.')
 | 
			
		||||
    finish(1)
 | 
			
		||||
elif not os.path.exists('Telegram.app/Contents/Helpers/crashpad_handler'):
 | 
			
		||||
    print('[ERROR] crashpad_handler not found.')
 | 
			
		||||
    finish(1)
 | 
			
		||||
elif not os.path.exists('Telegram.app/Contents/Resources/Icon.icns'):
 | 
			
		||||
    print('[ERROR] Icon not found.')
 | 
			
		||||
    finish(1)
 | 
			
		||||
elif not os.path.exists('Telegram.app/Contents/_CodeSignature'):
 | 
			
		||||
    print('[ERROR] Signature not found.')
 | 
			
		||||
    finish(1)
 | 
			
		||||
 | 
			
		||||
if os.path.exists(today):
 | 
			
		||||
    subprocess.call('rm -rf ' + today, shell=True)
 | 
			
		||||
result = subprocess.call('mkdir -p ' + today + '/TelegramForcePortable', shell=True)
 | 
			
		||||
if result != 0:
 | 
			
		||||
    print('[ERROR] Creating folder ' + today + '/TelegramForcePortable')
 | 
			
		||||
    finish(1)
 | 
			
		||||
 | 
			
		||||
result = subprocess.call('cp -r Telegram.app ' + today + '/', shell=True)
 | 
			
		||||
if result != 0:
 | 
			
		||||
    print('[ERROR] Cloning Telegram.app to ' + today + '.')
 | 
			
		||||
    finish(1)
 | 
			
		||||
 | 
			
		||||
archive = 'tdesktop_macOS_' + today + '.zip'
 | 
			
		||||
result = subprocess.call('zip -r ' + archive + ' ' + today, shell=True)
 | 
			
		||||
if result != 0:
 | 
			
		||||
    print('[ERROR] Adding tdesktop to archive.')
 | 
			
		||||
    finish(1)
 | 
			
		||||
 | 
			
		||||
changelog = '\n'.join(commits)
 | 
			
		||||
print('\n\nReady! File: ' + archive + '\nChangelog:\n' + changelog)
 | 
			
		||||
 | 
			
		||||
subprocess.call('mkdir -p ' + outputFolder, shell=True)
 | 
			
		||||
subprocess.call('mv ' + archive + ' ' + outputFolder + '/', shell=True)
 | 
			
		||||
with open(templatePath, 'r') as template:
 | 
			
		||||
    with open(outputFolder + '/command.txt', 'w') as f:
 | 
			
		||||
        for line in template:
 | 
			
		||||
            if line.startswith('//'):
 | 
			
		||||
                continue
 | 
			
		||||
            line = line.replace('{path}', scriptPath + '/../../out/Debug/' + outputFolder + '/' + archive)
 | 
			
		||||
            line = line.replace('{caption}', 'TDesktop at ' + today.replace('_', '.') + ':\n\n' + changelog)
 | 
			
		||||
            f.write(line)
 | 
			
		||||
 | 
			
		||||
subprocess.call('rm -rf ' + today, shell=True)
 | 
			
		||||
print('Finished.')
 | 
			
		||||
 | 
			
		||||
finish(0)
 | 
			
		||||
							
								
								
									
										22
									
								
								Telegram/build/updates.sh
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										22
									
								
								Telegram/build/updates.sh
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
set -e
 | 
			
		||||
FullExecPath=$PWD
 | 
			
		||||
pushd `dirname $0` > /dev/null
 | 
			
		||||
FullScriptPath=`pwd`
 | 
			
		||||
popd > /dev/null
 | 
			
		||||
 | 
			
		||||
if [ ! -d "$FullScriptPath/../../../TelegramPrivate" ]; then
 | 
			
		||||
  echo ""
 | 
			
		||||
  echo "This script is for building the production version of Telegram Desktop."
 | 
			
		||||
  echo ""
 | 
			
		||||
  echo "For building custom versions please visit the build instructions page at:"
 | 
			
		||||
  echo "https://github.com/telegramdesktop/tdesktop/#build-instructions"
 | 
			
		||||
  exit
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
pushd `dirname $0` > /dev/null
 | 
			
		||||
FullScriptPath=`pwd`
 | 
			
		||||
popd > /dev/null
 | 
			
		||||
 | 
			
		||||
python $FullScriptPath/updates.py $1 $2 $3 $4 $5 $6
 | 
			
		||||
 | 
			
		||||
exit
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue