2019-12-25 19:14:41 +01:00
#!/bin/bash -e
2018-02-20 15:49:54 +01:00
2019-06-18 12:31:44 +02:00
# Configure
2019-06-18 14:31:38 +02:00
PHP_MAJOR_VERSION = $( php -r 'echo PHP_MAJOR_VERSION;' )
PHP_MINOR_VERSION = $( php -r 'echo PHP_MINOR_VERSION;' )
2019-09-21 20:43:01 +02:00
IS_RELEASE = n
git rev-parse " $TRAVIS_COMMIT " 2>/dev/null | grep " $TRAVIS_COMMIT " -q && IS_RELEASE = y
2019-06-18 14:31:38 +02:00
2019-06-18 12:31:44 +02:00
# Clean up
2018-02-21 12:55:42 +01:00
rm -rf phar7 phar5 MadelineProtoPhar
2019-05-11 01:02:15 +02:00
madelinePath = $PWD
cd
rm -rf phar7 phar5 MadelineProtoPhar
2018-02-21 12:55:42 +01:00
mkdir phar7
cd phar7
2019-06-18 12:31:44 +02:00
# Install
2018-02-21 12:55:42 +01:00
echo ' {
2018-02-20 15:49:54 +01:00
"name" : "danog/madelineprototests" ,
"minimum-stability" :"dev" ,
"require" : {
2019-06-12 18:48:05 +02:00
"danog/madelineproto" : "dev-master" ,
2019-12-13 17:55:05 +01:00
"amphp/dns" : "dev-master#ecbeca2ae0e93c08e8150a92810a3961fad8ecbe as v1"
2018-02-20 15:49:54 +01:00
} ,
"repositories" : [
2019-05-11 01:02:15 +02:00
{
"type" : "path" ,
"url" : " ' $madelinePath ' " ,
"options" : {
"symlink" : false
}
2018-02-20 15:49:54 +01:00
}
] ,
"authors" : [
{
"name" : "Daniil Gentili" ,
"email" : "daniil@daniil.it"
}
]
} ' > composer.json
2019-06-18 14:39:31 +02:00
composer config platform.php "7.4"
[ $PHP_MAJOR_VERSION -eq 5 ] && composer require dstuecken/php7ify
2019-05-11 01:02:15 +02:00
composer clearcache
2018-02-21 12:55:42 +01:00
composer update
2019-12-26 19:17:31 +01:00
composer dumpautoload --optimize
2019-06-06 15:57:21 +02:00
cp -a $madelinePath /src vendor/danog/madelineproto/
2018-02-21 12:55:42 +01:00
cd ..
2018-02-20 15:49:54 +01:00
2019-06-18 14:31:38 +02:00
[ $PHP_MAJOR_VERSION -eq 5 ] && {
2019-06-20 18:34:05 +02:00
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update -q
sudo apt-get install php7.3-cli php7.3-json php7.3-mbstring php7.3-curl php7.3-xml php7.3-json -y
2019-12-25 19:38:44 +01:00
2019-12-26 19:17:31 +01:00
composer global require danog/7to5
2019-06-19 14:59:32 +02:00
[ -f $HOME /.composer/vendor/bin/php7to5 ] && php7to5 = $HOME /.composer/vendor/bin/php7to5
[ -f $HOME /.config/composer/vendor/bin/php7to5 ] && php7to5 = $HOME /.config/composer/vendor/bin/php7to5
2019-12-26 00:20:15 +01:00
2019-12-26 19:23:03 +01:00
sed -re 's/\?(\w*) (\$\w+)/\2 = NULL/g;s/= null = null/=null/ig;s/: self//g' -i phar7/vendor/league/uri-interfaces/src/Contracts/UriInterface.php
while IFS = read -r line; do l = $( echo " $line " | sed 's/[(].*//g' ) ; sed -i " s/ $l .*/ $line /g " phar7/vendor/league/uri/src/Uri.php; done <<< $( grep 'public function' phar7/vendor/league/uri-interfaces/src/Contracts/UriInterface.php | sed 's/;//g;s/: self//g' )
2019-12-26 19:17:31 +01:00
2019-12-26 19:23:03 +01:00
sed -i 's/handleConnectionWindowIncrement[(]\$windowSize[)]/handleConnectionWindowIncrement(int $windowSize)/g' phar7/vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php
2019-12-26 19:17:31 +01:00
2019-12-26 19:23:03 +01:00
sed -ri 's/^\{/{ use \\MyCallableMaker;/g;s/\\Closure::fromCallable[(]\[(.+), (.+)\][)]/\1->callableFromInstanceMethod(\2)/g' phar7/vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php phar7/vendor/amphp/http-client/src/Connection/Http{ 2,1} Connection.php
2019-12-26 19:17:31 +01:00
2019-12-26 00:20:15 +01:00
php7.3 $php7to5 convert --copy-all phar7 phar5 >/dev/null
2019-12-25 19:38:44 +01:00
2019-06-18 14:31:38 +02:00
sed 's/^Loop::set.*;//g' -i phar5/vendor/amphp/amp/lib/Loop.php
echo 'Loop::set((new DriverFactory())->create());' >> phar5/vendor/amphp/amp/lib/Loop.php
2019-06-18 18:27:26 +02:00
cp $madelinePath /tests/random.php phar5/vendor/paragonie/random_compat/lib/random.php
2019-06-18 17:52:04 +02:00
cp phar5/vendor/danog/madelineproto/src/danog/MadelineProto/Coroutine.php phar5/vendor/amphp/amp/lib/Coroutine.php
sed 's/namespace danog\\MadelineProto;/namespace Amp;/g' -i phar5/vendor/amphp/amp/lib/Coroutine.php
2019-06-18 18:52:17 +02:00
sed 's/public static function echo/public static function echo_/g' -i phar5/vendor/danog/madelineproto/src/danog/MadelineProto/Tools.php
2019-12-25 19:38:44 +01:00
2019-12-25 23:48:42 +01:00
find phar5/vendor/amphp -type f -name '*.php' -exec sed "s/extension_loaded[(]'zlib'[)]/false/g;s/new[(]/new_(/g;s/clone[(]/clone_(/g" -i { } +
2019-12-26 00:08:20 +01:00
2019-12-25 19:42:39 +01:00
find phar5/vendor/danog/madelineproto -type f -name '*.php' -exec sed 's/: EncryptableSocket/: \\Amp\\Socket\\Socket/g' -i { } +
2019-12-25 19:38:44 +01:00
2019-12-26 19:23:03 +01:00
sed 's/use Kelunik\\Certificate\\Certificate/use Kelunik\Certificate\Certificate as _Certificate/g;s/new Certificate/new _Certificate/g' -i phar5/vendor/amphp/socket/src/TlsInfo.php
2019-12-26 19:17:31 +01:00
echo " <?php
namespace League\U ri\C ontracts;
interface UriException
{
2019-12-26 19:23:03 +01:00
} " > phar5/vendor/league/uri-interfaces/src/Contracts/UriException.php
2019-12-26 19:17:31 +01:00
2019-06-18 15:04:13 +02:00
php -v
2019-06-18 14:31:38 +02:00
php = 5
}
[ $PHP_MAJOR_VERSION -eq 7 ] && {
[ $PHP_MINOR_VERSION -eq 0 ] && {
2019-06-19 14:59:32 +02:00
composer global require danog/7to70
[ -f $HOME /.composer/vendor/bin/php7to70 ] && php7to70 = $HOME /.composer/vendor/bin/php7to70
[ -f $HOME /.config/composer/vendor/bin/php7to70 ] && php7to70 = $HOME /.config/composer/vendor/bin/php7to70
2019-12-26 00:20:15 +01:00
2019-12-26 19:23:03 +01:00
sed -re 's/\?(\w*) (\$\w+)/\2 = NULL/g;s/= null = null/=null/ig;s/: self//g' -i phar7/vendor/league/uri-interfaces/src/Contracts/UriInterface.php
while IFS = read -r line; do l = $( echo " $line " | sed 's/[(].*//g' ) ; sed -i " s/ $l .*/ $line /g " phar7/vendor/league/uri/src/Uri.php; done <<< $( grep 'public function' phar7/vendor/league/uri-interfaces/src/Contracts/UriInterface.php | sed 's/;//g;s/: self//g' )
2019-12-26 19:17:31 +01:00
2019-12-26 19:23:03 +01:00
sed -i 's/handleConnectionWindowIncrement[(]\$windowSize[)]/handleConnectionWindowIncrement(int $windowSize)/g' phar7/vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php
2019-12-26 19:17:31 +01:00
2019-12-26 19:23:03 +01:00
sed -ri 's/^\{/{ use \\MyCallableMaker;/g;s/\\Closure::fromCallable[(]\[(.+), (.+)\][)]/\1->callableFromInstanceMethod(\2)/g' phar7/vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php phar7/vendor/amphp/http-client/src/Connection/Http{ 2,1} Connection.php
2019-12-25 19:38:44 +01:00
2019-06-18 14:31:38 +02:00
$php7to70 convert --copy-all phar7 phar5 >/dev/null
2019-12-26 00:08:20 +01:00
2019-12-25 19:42:39 +01:00
find phar5/vendor/danog/madelineproto -type f -name '*.php' -exec sed 's/: EncryptableSocket/: \\Amp\\Socket\\Socket/g' -i { } +
2019-12-25 19:38:44 +01:00
2019-06-18 14:31:38 +02:00
php = 70
} || {
cp -a phar7 phar5
}
}
2018-06-22 13:28:33 +02:00
find phar5 -type f -exec sed 's/\w* \.\.\./.../' -i { } +
2018-02-21 12:55:42 +01:00
2019-06-19 11:18:51 +02:00
# Make sure conversion worked
2019-06-19 11:36:07 +02:00
for f in $( find phar5 -type f -name '*.php' ) ; do php -l $f ; done
2019-06-19 11:18:51 +02:00
2019-06-18 19:35:13 +02:00
branch = " - $TRAVIS_BRANCH "
2019-05-11 01:02:15 +02:00
cd $madelinePath
2019-09-21 17:11:37 +02:00
2019-06-18 14:31:38 +02:00
export TRAVIS_PHAR = " madeline $php $branch .phar "
2019-06-16 21:20:29 +02:00
export TEST_SECRET_CHAT = test
export TEST_USERNAME = danogentili
2019-06-17 12:19:46 +02:00
export TEST_DESTINATION_GROUPS = '["@danogentili"]'
2019-09-04 18:33:27 +02:00
export MTPROTO_SETTINGS = '{"logger":{"logger_level":5}}'
2019-06-16 21:20:29 +02:00
2019-12-25 18:15:50 +01:00
php tools/makephar.php $HOME /phar5 " $TRAVIS_PHAR " $TRAVIS_COMMIT
curl -s https://api.telegram.org/bot$BOT_TOKEN /sendDocument -F chat_id = 101374607 -F document = " @ $TRAVIS_PHAR "
2019-06-17 12:19:46 +02:00
tests/testing.php <<EOF
m
$API_ID
$API_HASH
b
$BOT_TOKEN
n
n
n
EOF
2019-06-16 21:20:29 +02:00
2018-02-21 13:05:35 +01:00
eval " $( ssh-agent -s) "
2018-02-22 15:26:57 +01:00
echo -e " $private_key " > madeline_rsa
chmod 600 madeline_rsa
2018-02-21 13:05:35 +01:00
ssh-add madeline_rsa
2018-02-21 12:55:42 +01:00
git clone git@github.com:danog/MadelineProtoPhar
cd MadelineProtoPhar
2019-09-04 22:16:35 +02:00
[ " $php " = = "70" ] && {
while [ " $( cat release$branch ) " != " $TRAVIS_COMMIT " ] ; do sleep 1; git pull; done
}
[ " $php " = = "5" ] && {
while [ " $( cat release70$branch ) " != " $TRAVIS_COMMIT " ] ; do sleep 1; git pull; done
}
2019-06-18 14:31:38 +02:00
cp " ../madeline $php $branch .phar " .
2019-10-28 22:39:23 +01:00
cp ../tools/phar.php ../examples/mtproxyd .
2019-06-18 19:02:31 +02:00
echo -n $TRAVIS_COMMIT > release$php $branch
2019-06-21 21:20:44 +02:00
2019-09-21 20:43:01 +02:00
[ " $IS_RELEASE " = = "y" ] && {
2019-06-21 21:20:44 +02:00
cp release$php $branch release$php
cp madeline$php $branch .phar madeline$php .phar
}
2019-06-21 21:28:15 +02:00
git add -A
git commit -am " Release $TRAVIS_BRANCH - $TRAVIS_COMMIT_MESSAGE "
2019-09-04 22:16:35 +02:00
git push origin master
2019-09-04 19:17:16 +02:00
2018-02-21 12:55:42 +01:00
cd ..
2018-02-25 10:52:55 +01:00
echo " $TRAVIS_COMMIT_MESSAGE " | grep "Apply fixes from StyleCI" && exit
2018-02-20 13:15:32 +01:00
[ -d JSON.sh ] || git clone https://github.com/dominictarr/JSON.sh
for chat_id in $destinations ; do
2019-12-25 19:38:44 +01:00
ID = $( curl -s https://api.telegram.org/bot$BOT_TOKEN /sendMessage -F disable_web_page_preview = 1 -F text = " <b>Recent Commits to MadelineProto: $TRAVIS_BRANCH </b>
<a href = \" https://github.com/danog/MadelineProto/commit/$TRAVIS_COMMIT \" >$TRAVIS_COMMIT_MESSAGE ( PHP $PHP_MAJOR_VERSION .$PHP_MINOR_VERSION ) </a>
$TRAVIS_COMMIT_MESSAGE " -F parse_mode=" HTML" -F chat_id= $chat_id | JSON.sh/JSON.sh -s | egrep '\[ " result"," message_id"\]' | cut -f 2 | cut -d '" ' -f 2)
2018-02-20 13:15:32 +01:00
done