snappymail/release.php

94 lines
2.9 KiB
PHP
Raw Normal View History

2020-09-11 23:16:11 +08:00
#!/usr/bin/php
2020-08-10 18:43:02 +08:00
<?php
chdir(__DIR__);
2020-08-10 19:47:48 +08:00
2020-08-10 18:43:02 +08:00
$gulp = trim(`which gulp`);
if (!$gulp) {
exit('gulp not installed, run as root: npm install --global gulp-cli');
}
2020-08-10 19:47:48 +08:00
$package = json_decode(file_get_contents('package.json'));
$zip_destination = "rainloop-{$package->version}.zip";
$tar_destination = "rainloop-{$package->version}.tar";
@unlink($zip_destination);
@unlink($tar_destination);
@unlink("{$tar_destination}.gz");
2020-08-10 18:43:02 +08:00
passthru($gulp, $return_var);
if ($return_var) {
exit("gulp failed with error code {$return_var}\n");
}
if ($gzip = trim(`which gzip`)) {
2020-09-23 20:49:43 +08:00
passthru("{$gzip} -k --best -r ".escapeshellarg(__DIR__ . '/rainloop/v/0.0.0/static/js/*.js'), $return_var);
passthru("{$gzip} -k --best -r ".escapeshellarg(__DIR__ . '/rainloop/v/0.0.0/static/css/app*.css'), $return_var);
}
2020-08-24 06:09:54 +08:00
if ($brotli = trim(`which brotli`)) {
2020-09-23 20:49:43 +08:00
passthru("{$brotli} -k --best ".escapeshellarg(__DIR__ . '/rainloop/v/0.0.0/static/js/*.js'), $return_var);
passthru("{$brotli} -k --best ".escapeshellarg(__DIR__ . '/rainloop/v/0.0.0/static/js/min/*.js'), $return_var);
passthru("{$brotli} -k --best ".escapeshellarg(__DIR__ . '/rainloop/v/0.0.0/static/css/app*.css'), $return_var);
2020-08-24 06:09:54 +08:00
}
2020-08-10 19:47:48 +08:00
// Temporary rename folder to speed up PharData
if (!rename('rainloop/v/0.0.0', "rainloop/v/{$package->version}")){
exit('Failed to temporary rename rainloop/v/0.0.0');
}
register_shutdown_function(function(){
// Rename folder back to original
@rename("rainloop/v/{$GLOBALS['package']->version}", 'rainloop/v/0.0.0');
});
2020-08-10 18:43:02 +08:00
$zip = new ZipArchive();
2020-08-10 19:47:48 +08:00
if (!$zip->open($zip_destination, ZIPARCHIVE::CREATE)) {
exit("Failed to create {$zip_destination}");
2020-08-10 18:43:02 +08:00
}
2020-08-10 19:47:48 +08:00
$tar = new PharData($tar_destination);
2020-08-10 18:43:02 +08:00
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('rainloop/v'), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$file = str_replace('\\', '/', $file);
2020-08-10 19:47:48 +08:00
echo "{$file}\n";
2020-08-10 18:43:02 +08:00
// Ignore "." and ".." folders
2020-08-10 19:47:48 +08:00
if (!in_array(substr($file, strrpos($file, '/')+1), array('.', '..'))) {
if (is_dir($file)) {
$zip->addEmptyDir($file);
} else if (is_file($file)) {
$zip->addFile($file);
}
2020-08-10 18:43:02 +08:00
}
}
2020-08-10 19:47:48 +08:00
$tar->buildFromDirectory('./', "@rainloop/v/{$package->version}@");
2020-08-10 18:43:02 +08:00
$zip->addFromString('data/VERSION', $package->version);
2020-08-10 19:47:48 +08:00
$tar->addFromString('data/VERSION', $package->version);
2020-08-10 18:43:02 +08:00
//$zip->addFromString('data/EMPTY', $package->version);
2020-08-10 19:47:48 +08:00
//$tar->addFromString('data/EMPTY', $package->version);
2020-08-10 18:43:02 +08:00
$zip->addFile('_include.php');
2020-08-10 19:47:48 +08:00
$tar->addFile('_include.php');
2020-08-10 18:43:02 +08:00
2020-09-23 20:49:43 +08:00
$zip->addFile('.htaccess');
$tar->addFile('.htaccess');
2020-08-10 18:43:02 +08:00
$index = file_get_contents('index.php');
$index = str_replace('0.0.0', $package->version, $index);
$index = str_replace('source', 'community', $index);
$zip->addFromString('index.php', $index);
2020-08-10 19:47:48 +08:00
$tar->addFromString('index.php', $index);
2020-08-10 18:43:02 +08:00
$zip->addFile('README.md');
$tar->addFile('README.md');
2020-08-10 18:43:02 +08:00
$zip->close();
2020-08-10 19:47:48 +08:00
$tar->compress(Phar::GZ);
unlink($tar_destination);
echo "\n{$zip_destination} created\n{$tar_destination}.gz created\n";