2012-02-07 03:24:48 +00:00
< ? php
2022-06-28 11:32:56 +00:00
2012-02-07 03:24:48 +00:00
/**
* Script used to build Joomla distribution archive packages
2018-06-15 05:59:24 +00:00
* Builds packages in tmp / packages folder ( for example , 'build/tmp/packages' )
2012-02-07 03:24:48 +00:00
*
* Note : the new package must be tagged in your git repository BEFORE doing this
* It uses the git tag for the new version , not trunk .
*
2021-08-13 06:50:42 +00:00
* This script is designed to be run in CLI on Linux , Mac OS X and WSL .
2012-02-07 03:24:48 +00:00
* Make sure your default umask is 022 to create archives with correct permissions .
*
2021-08-13 06:50:42 +00:00
* For WSL based setups make sure there is a / etc / wsl . conf with the following content :
* [ automount ]
* enabled = true
* options = metadata , uid = 1000 , gid = 1000 , umask = 022
*
2012-02-07 03:24:48 +00:00
* Steps :
* 1. Tag new release in the local git repository ( for example , " git tag 2.5.1 " )
* 2. Set the $version and $release variables for the new version .
* 3. Run from CLI as : ' php build . php " from build directory.
* 4. Check the archives in the tmp directory .
*
2015-01-23 15:19:17 +00:00
* @ package Joomla . Build
2020-11-28 01:33:45 +00:00
* @ copyright ( C ) 2012 Open Source Matters , Inc . < https :// www . joomla . org >
2015-01-23 15:19:17 +00:00
* @ license GNU General Public License version 2 or later ; see LICENSE . txt
2012-02-07 03:24:48 +00:00
*/
2017-05-01 12:51:27 +00:00
use Joomla\CMS\Version ;
2018-04-04 11:52:22 +00:00
const PHP_TAB = " \t " ;
2018-07-28 00:17:32 +00:00
function usage ( string $command )
2018-04-04 11:52:22 +00:00
{
2022-06-28 11:32:56 +00:00
echo PHP_EOL ;
echo 'Usage: php ' . $command . ' [options]' . PHP_EOL ;
echo PHP_TAB . '[options]:' . PHP_EOL ;
echo PHP_TAB . PHP_TAB . '--remote=<remote>:' . PHP_TAB . 'The git remote reference to build from (ex: `tags/3.8.6`, `4.0-dev`), defaults to the most recent tag for the repository' . PHP_EOL ;
echo PHP_TAB . PHP_TAB . '--exclude-zip:' . PHP_TAB . PHP_TAB . 'Exclude the generation of .zip packages' . PHP_EOL ;
echo PHP_TAB . PHP_TAB . '--exclude-gzip:' . PHP_TAB . PHP_TAB . 'Exclude the generation of .tar.gz packages' . PHP_EOL ;
echo PHP_TAB . PHP_TAB . '--exclude-bzip2:' . PHP_TAB . 'Exclude the generation of .tar.bz2 packages' . PHP_EOL ;
echo PHP_TAB . PHP_TAB . '--include-zstd:' . PHP_TAB . 'Include the generation of .tar.zst packages' . PHP_EOL ;
echo PHP_TAB . PHP_TAB . '--help:' . PHP_TAB . PHP_TAB . PHP_TAB . 'Show this help output' . PHP_EOL ;
echo PHP_EOL ;
2018-04-04 11:52:22 +00:00
}
2018-07-28 00:17:32 +00:00
function clean_checkout ( string $dir )
{
2022-06-28 11:32:56 +00:00
// Save the current working directory to restore when complete
$cwd = getcwd ();
chdir ( $dir );
echo " Cleaning checkout in $dir . \n " ;
// Removes .DS_Store; .git sources; testing, CI, and IDE configuration files; Changelogs; GitHub Meta; and README files
system ( 'find . -name .appveyor.yml | xargs rm -rf -' );
system ( 'find . -name .coveralls.yml | xargs rm -rf -' );
system ( 'find . -name .DS_Store | xargs rm -rf -' );
system ( 'find . -name .editorconfig | xargs rm -rf -' );
system ( 'find . -name .gitattributes | xargs rm -rf -' );
system ( 'find . -name .github | xargs rm -rf -' );
system ( 'find . -name .gitignore | xargs rm -rf -' );
system ( 'find . -name .gitmodules | xargs rm -rf -' );
2022-10-21 10:19:30 +00:00
system ( 'find . -name .phan | xargs rm -rf -' );
2022-06-28 11:32:56 +00:00
system ( 'find . -name .php-cs-fixer.dist.php | xargs rm -rf -' );
system ( 'find . -name .scrutinizer.yml | xargs rm -rf -' );
system ( 'find . -name .travis.yml | xargs rm -rf -' );
system ( 'find . -name appveyor.yml | xargs rm -rf -' );
system ( 'find . -name CHANGELOG.md | xargs rm -rf -' );
system ( 'find . -name CONTRIBUTING.md | xargs rm -rf -' );
system ( 'find . -name psalm.xml | xargs rm -rf -' );
system ( 'find . -name psalm.xml.dist | xargs rm -rf -' );
system ( 'find . -name phpcs.xml | xargs rm -rf -' );
system ( 'find . -name phpcs.xml.dist | xargs rm -rf -' );
system ( 'find . -name phpunit.xml | xargs rm -rf -' );
system ( 'find . -name phpunit.*.xml | xargs rm -rf -' );
system ( 'find . -name phpunit.xml.dist | xargs rm -rf -' );
system ( 'find . -name README.md | xargs rm -rf -' );
system ( 'find . -name SECURITY.md | xargs rm -rf -' );
echo " Cleaning vendors. \n " ;
system ( 'find libraries/vendor -name CODE_OF_CONDUCT.md | xargs rm -rf -' );
system ( 'find libraries/vendor -name CONDUCT.md | xargs rm -rf -' );
system ( 'find libraries/vendor -name docker-compose.yml | xargs rm -rf -' );
system ( 'find libraries/vendor -name phpunit.xml | xargs rm -rf -' );
system ( 'find libraries/vendor -name README.md | xargs rm -rf -' );
system ( 'find libraries/vendor -name readme.md | xargs rm -rf -' );
system ( 'find libraries/vendor -name UPGRADING.md | xargs rm -rf -' );
system ( 'find libraries/vendor -name SUMMARY.md | xargs rm -rf -' );
system ( 'find libraries/vendor -name .travis.yml | xargs rm -rf -' );
system ( 'find libraries/vendor -name .git | xargs rm -rf -' );
system ( 'find libraries/vendor -name .gitignore | xargs rm -rf -' );
system ( 'find libraries/vendor -name .gitmodules | xargs rm -rf -' );
system ( 'find libraries/vendor -name ISSUE_TEMPLATE | xargs rm -rf -' );
system ( 'find libraries/vendor -name CONTRIBUTING.md | xargs rm -rf -' );
system ( 'find libraries/vendor -name CHANGES.md | xargs rm -rf -' );
system ( 'find libraries/vendor -name CHANGELOG.md | xargs rm -rf -' );
system ( 'find libraries/vendor -name SECURITY.md | xargs rm -rf -' );
system ( 'find libraries/vendor -name psalm.md | xargs rm -rf -' );
system ( 'find libraries/vendor -name psalm-baseline.md | xargs rm -rf -' );
system ( 'find libraries/vendor -name psalm-baseline.xml | xargs rm -rf -' );
system ( 'find libraries/vendor -name .yamllint | xargs rm -rf -' );
system ( 'find libraries/vendor -name .remarkrc | xargs rm -rf -' );
system ( 'find libraries/vendor -name .editorconfig | xargs rm -rf -' );
system ( 'find libraries/vendor -name appveyor.yml | xargs rm -rf -' );
system ( 'find libraries/vendor -name phpunit.xml.dist | xargs rm -rf -' );
system ( 'find libraries/vendor -name .php_cs | xargs rm -rf -' );
system ( 'find libraries/vendor -name .php_cs.dist | xargs rm -rf -' );
system ( 'find libraries/vendor -name phpcs.xsd | xargs rm -rf -' );
system ( 'find libraries/vendor -name phpcs.xml | xargs rm -rf -' );
system ( 'find libraries/vendor -name build.xml | xargs rm -rf -' );
system ( 'find libraries/vendor -name infection.json.dist | xargs rm -rf -' );
system ( 'find libraries/vendor -name phpbench.json | xargs rm -rf -' );
system ( 'find libraries/vendor -name phpstan.neon.dist | xargs rm -rf -' );
system ( 'find libraries/vendor -name .doctrine-project.json | xargs rm -rf -' );
system ( 'find libraries/vendor -name .pullapprove.yml | xargs rm -rf -' );
system ( 'find libraries/vendor -name phpstan.neon | xargs rm -rf -' );
system ( 'find libraries/vendor -name _config.yml | xargs rm -rf -' );
system ( 'find libraries/vendor -name .bowerrc | xargs rm -rf -' );
system ( 'find libraries/vendor -name bower.json | xargs rm -rf -' );
system ( 'rm -rf libraries/vendor/bin' );
// aldo26-matthias/idna-convert
system ( 'rm -rf libraries/vendor/algo26-matthias/idna-convert/tests' );
// defuse/php-encryption
system ( 'rm -rf libraries/vendor/defuse/php-encryption/docs' );
// doctrine/inflector
system ( 'rm -rf libraries/vendor/doctrine/inflector/docs' );
// fig/link-util
system ( 'rm -rf libraries/vendor/fig/link-util/test' );
// google/recaptcha
system ( 'rm -rf libraries/vendor/google/recaptcha/examples' );
system ( 'rm -rf libraries/vendor/google/recaptcha/tests' );
// jakeasmith/http_build_url
system ( 'rm -rf libraries/vendor/jakeasmith/http_build_url/tests' );
// joomla/*
system ( 'rm -rf libraries/vendor/joomla/*/docs' );
system ( 'rm -rf libraries/vendor/joomla/*/tests' );
system ( 'rm -rf libraries/vendor/joomla/*/Tests' );
system ( 'rm -rf libraries/vendor/joomla/*/ruleset.xml' );
// testing sampledata
system ( 'rm -rf plugins/sampledata/testing' );
system ( 'rm -rf images/sampledata/parks' );
system ( 'rm -rf images/sampledata/fruitshop' );
// maximebf/debugbar
system ( 'rm -rf libraries/vendor/maximebf/debugbar/build' );
system ( 'rm -rf libraries/vendor/maximebf/debugbar/demo' );
system ( 'rm -rf libraries/vendor/maximebf/debugbar/docs' );
system ( 'rm -rf libraries/vendor/maximebf/debugbar/tests' );
// paragonie/sodium_compat
system ( 'rm -rf libraries/vendor/paragonie/sodium_compat/build-phar.sh' );
// phpmailer/phpmailer
system ( 'rm -rf libraries/vendor/phpmailer/phpmailer/language' );
system ( 'rm -rf libraries/vendor/phpmailer/phpmailer/get_oauth_token.php' );
// psr/log
system ( 'rm -rf libraries/vendor/psr/log/Psr/Log/Test' );
// symfony/*
system ( 'rm -rf libraries/vendor/symfony/*/Resources/doc' );
system ( 'rm -rf libraries/vendor/symfony/*/Tests' );
system ( 'rm -rf libraries/vendor/symfony/console/Resources' );
2022-08-18 18:16:52 +00:00
system ( 'rm -rf libraries/vendor/symfony/string/Resources/bin' );
2022-06-28 11:32:56 +00:00
// tobscure/json-api
system ( 'rm -rf libraries/vendor/tobscure/json-api/tests' );
// wamania/php-stemmer
system ( 'rm -rf libraries/vendor/wamania/php-stemmer/test' );
// willdurand/negotiation
system ( 'rm -rf libraries/vendor/willdurand/negotiation/tests' );
2022-10-09 17:04:23 +00:00
// jfcherng
system ( 'rm -rf libraries/vendor/jfcherng/php-color-output/demo.php' );
system ( 'rm -rf libraries/vendor/jfcherng/php-color-output/UPGRADING_v2.md' );
system ( 'rm -rf libraries/vendor/jfcherng/php-diff/CHANGELOG' );
system ( 'rm -rf libraries/vendor/jfcherng/php-diff/example' );
system ( 'rm -rf libraries/vendor/jfcherng/php-diff/UPGRADING' );
system ( 'rm -rf libraries/vendor/jfcherng/php-mb-string/CHANGELOG' );
2022-06-28 11:32:56 +00:00
echo " Cleanup complete. \n " ;
chdir ( $cwd );
2018-07-28 00:17:32 +00:00
}
function clean_composer ( string $dir )
{
2022-06-28 11:32:56 +00:00
// Save the current working directory to restore when complete
$cwd = getcwd ();
chdir ( $dir );
2018-07-28 00:17:32 +00:00
2022-06-28 11:32:56 +00:00
echo " Cleaning Composer manifests in $dir . \n " ;
2018-07-28 00:17:32 +00:00
2022-06-28 11:32:56 +00:00
// Removes Composer manifests
system ( 'find . -name composer.json | xargs rm -rf -' );
system ( 'find . -name composer.lock | xargs rm -rf -' );
2018-07-28 00:17:32 +00:00
2022-06-28 11:32:56 +00:00
echo " Cleanup complete. \n " ;
2018-07-28 00:17:32 +00:00
2022-06-28 11:32:56 +00:00
chdir ( $cwd );
2018-07-28 00:17:32 +00:00
}
2018-04-04 11:52:22 +00:00
$time = time ();
2013-08-24 00:42:52 +00:00
// Set path to git binary (e.g., /usr/local/git/bin/git or /usr/bin/git)
ob_start ();
passthru ( 'which git' , $systemGit );
2016-07-31 17:37:52 +00:00
$systemGit = trim ( ob_get_clean ());
2012-02-07 03:24:48 +00:00
2013-08-24 00:42:52 +00:00
// Make sure file and folder permissions are set correctly
umask ( 022 );
2012-02-07 03:24:48 +00:00
2013-08-24 00:42:52 +00:00
// Shortcut the paths to the repository root and build folder
$repo = dirname ( __DIR__ );
$here = __DIR__ ;
2012-02-07 03:24:48 +00:00
2013-08-24 00:42:52 +00:00
// Set paths for the build packages
$tmp = $here . '/tmp' ;
2018-04-04 11:52:22 +00:00
$fullpath = $tmp . '/' . $time ;
2012-02-07 03:24:48 +00:00
2018-04-04 11:52:22 +00:00
// Parse input options
2021-11-28 18:41:15 +00:00
$options = getopt ( '' , [ 'help' , 'remote::' , 'exclude-zip' , 'exclude-gzip' , 'exclude-bzip2' , 'include-zstd' , 'disable-patch-packages' ]);
2018-04-04 11:52:22 +00:00
2018-07-28 00:17:32 +00:00
$remote = $options [ 'remote' ] ? ? false ;
2018-04-04 11:52:22 +00:00
$excludeZip = isset ( $options [ 'exclude-zip' ]);
$excludeGzip = isset ( $options [ 'exclude-gzip' ]);
$excludeBzip2 = isset ( $options [ 'exclude-bzip2' ]);
2020-03-20 12:05:38 +00:00
$excludeZstd = ! isset ( $options [ 'include-zstd' ]);
2021-11-29 00:18:32 +00:00
$buildPatchPackages = ! isset ( $options [ 'disable-patch-packages' ]);
2018-04-04 11:52:22 +00:00
$showHelp = isset ( $options [ 'help' ]);
2021-06-11 12:18:30 +00:00
// Disable the generation of extra text files
$includeExtraTextfiles = false ;
2022-06-28 11:32:56 +00:00
if ( $showHelp ) {
usage ( $argv [ 0 ]);
exit ;
2018-04-04 11:52:22 +00:00
}
// If not given a remote, assume we are looking for the latest local tag
2022-06-28 11:32:56 +00:00
if ( ! $remote ) {
chdir ( $repo );
$tagVersion = system ( $systemGit . ' describe --tags `' . $systemGit . ' rev-list --tags --max-count=1`' , $tagVersion );
$remote = 'tags/' . $tagVersion ;
chdir ( $here );
// We are in release mode so we need the extra text files
$includeExtraTextfiles = true ;
2018-04-04 11:52:22 +00:00
}
echo " Start build for remote $remote . \n " ;
2012-02-07 03:24:48 +00:00
echo " Delete old release folder. \n " ;
system ( 'rm -rf ' . $tmp );
mkdir ( $tmp );
mkdir ( $fullpath );
echo " Copy the files from the git repository. \n " ;
chdir ( $repo );
2018-04-04 11:52:22 +00:00
system ( $systemGit . ' archive ' . $remote . ' | tar -x -C ' . $fullpath );
2022-09-02 19:41:35 +00:00
system ( 'cp build/fido.jwt ' . $fullpath . '/plugins/system/webauthn/fido.jwt' );
2018-07-28 00:17:32 +00:00
// Install PHP and NPM dependencies and compile required media assets, skip Composer autoloader until post-cleanup
chdir ( $fullpath );
2021-08-10 22:04:24 +00:00
system ( 'composer install --no-dev --no-autoloader --ignore-platform-reqs' , $composerReturnCode );
2018-09-23 15:44:15 +00:00
2022-06-28 11:32:56 +00:00
if ( $composerReturnCode !== 0 ) {
echo " `composer install` did not complete as expected. \n " ;
exit ( 1 );
2018-09-23 15:44:15 +00:00
}
2022-09-02 19:37:25 +00:00
// Try to update the fido.jwt file
if ( ! file_exists ( rtrim ( $fullpath , '\\/' ) . '/plugins/system/webauthn/fido.jwt' ))
{
echo " The file plugins/system/webauthn/fido.jwt was not created. Build failed. \n " ;
exit ( 1 );
}
2018-09-23 15:44:15 +00:00
system ( 'npm install --unsafe-perm' , $npmReturnCode );
2022-06-28 11:32:56 +00:00
if ( $npmReturnCode !== 0 ) {
echo " `npm install` did not complete as expected. \n " ;
exit ( 1 );
2019-03-18 09:08:43 +00:00
}
// Create gzipped version of the static assets
system ( 'npm run gzip' , $gzipReturnCode );
2022-06-28 11:32:56 +00:00
if ( $gzipReturnCode !== 0 ) {
echo " `npm run gzip` did not complete as expected. \n " ;
exit ( 1 );
2018-09-23 15:44:15 +00:00
}
2018-07-27 13:18:14 +00:00
2021-03-24 16:38:00 +00:00
// Create version entries of the static assets in their respective joomla.asset.json
system ( 'npm run versioning' , $verReturnCode );
2022-06-28 11:32:56 +00:00
if ( $verReturnCode !== 0 ) {
echo " `npm run versioning` did not complete as expected. \n " ;
exit ( 1 );
2021-03-24 16:38:00 +00:00
}
2018-07-28 00:17:32 +00:00
// Clean the checkout of extra resources
clean_checkout ( $fullpath );
// Regenerate the Composer autoloader without deleted files
2021-08-10 22:04:24 +00:00
system ( 'composer dump-autoload --no-dev --optimize --no-scripts' );
2018-07-28 00:17:32 +00:00
// Clean the Composer manifests now
clean_composer ( $fullpath );
// And cleanup the Node installation
system ( 'rm -rf node_modules' );
echo " Workspace built. \n " ;
2018-04-04 11:52:22 +00:00
// Import the version class to set the version information
define ( 'JPATH_PLATFORM' , 1 );
require_once $fullpath . '/libraries/src/Version.php' ;
// Set version information for the build
$version = Version :: MAJOR_VERSION . '.' . Version :: MINOR_VERSION ;
$release = Version :: PATCH_VERSION ;
2022-06-28 11:32:56 +00:00
$fullVersion = ( new Version ()) -> getShortVersion ();
2012-02-07 03:24:48 +00:00
2020-08-17 11:31:26 +00:00
$previousRelease = Version :: PATCH_VERSION - 1 ;
2022-06-28 11:32:56 +00:00
if ( $previousRelease < 0 ) {
$previousRelease = false ;
2020-08-17 11:31:26 +00:00
}
2012-02-07 03:24:48 +00:00
chdir ( $tmp );
system ( 'mkdir diffdocs' );
system ( 'mkdir diffconvert' );
2018-06-15 05:59:24 +00:00
system ( 'mkdir packages' );
2012-02-07 03:24:48 +00:00
2018-04-04 11:52:22 +00:00
echo " Create list of changed files from git repository for version $fullVersion . \n " ;
2012-02-07 03:24:48 +00:00
2013-08-24 00:42:52 +00:00
/*
* Here we force add every top - level directory and file in our diff archive , even if they haven ' t changed .
* This allows us to install these files from the Extension Manager .
* So we add the index file for each top - level directory .
* Note : If we add new top - level directories or files , be sure to include them here .
*/
2012-06-22 01:31:45 +00:00
$filesArray = array (
2022-06-28 11:32:56 +00:00
" administrator/index.php \n " => true ,
" api/index.php \n " => true ,
" cache/index.html \n " => true ,
" cli/index.html \n " => true ,
" components/index.html \n " => true ,
" images/index.html \n " => true ,
" includes/index.html \n " => true ,
" language/index.html \n " => true ,
" layouts/index.html \n " => true ,
" libraries/index.html \n " => true ,
" media/index.html \n " => true ,
" modules/index.html \n " => true ,
" plugins/index.html \n " => true ,
" templates/index.html \n " => true ,
" tmp/index.html \n " => true ,
" htaccess.txt \n " => true ,
" index.php \n " => true ,
" LICENSE.txt \n " => true ,
" README.txt \n " => true ,
" robots.txt.dist \n " => true ,
" web.config.txt \n " => true
2012-06-22 01:31:45 +00:00
);
2014-05-05 19:52:55 +00:00
/*
* Here we set the files / folders which should not be packaged at any time
* These paths are from the repository root without the leading slash
2018-07-28 00:17:32 +00:00
* Because this is a fresh copy from a git tag , local environment files may be ignored
2014-05-05 19:52:55 +00:00
*/
$doNotPackage = array (
2022-06-28 11:32:56 +00:00
'.appveyor.yml' ,
'.drone.yml' ,
'.editorconfig' ,
'.github' ,
'.gitignore' ,
2022-10-21 10:19:30 +00:00
'.phan' ,
2022-06-28 11:32:56 +00:00
'.php-cs-fixer.dist.php' ,
'acceptance.suite.yml' ,
2022-08-14 07:12:04 +00:00
// Media Manager Node Assets
'administrator/components/com_media/resources' ,
2022-06-28 11:32:56 +00:00
'appveyor-phpunit.xml' ,
'build' ,
'build.xml' ,
'codeception.yml' ,
2022-08-14 07:12:04 +00:00
'CODE_OF_CONDUCT.md' ,
2022-06-28 11:32:56 +00:00
'composer.json' ,
'composer.lock' ,
'crowdin.yml' ,
'package-lock.json' ,
'package.json' ,
'phpunit-pgsql.xml.dist' ,
'phpunit.xml.dist' ,
'plugins/sampledata/testing/language/en-GB/en-GB.plg_sampledata_testing.ini' ,
'plugins/sampledata/testing/language/en-GB/en-GB.plg_sampledata_testing.sys.ini' ,
2022-08-14 07:12:04 +00:00
'plugins/sampledata/testing/testing.php' ,
'plugins/sampledata/testing/testing.xml' ,
'README.md' ,
'renovate.json' ,
2022-06-28 11:42:10 +00:00
'ruleset.xml' ,
2022-06-28 11:32:56 +00:00
'selenium.log' ,
'tests' ,
2014-05-05 19:52:55 +00:00
);
2014-05-19 20:52:38 +00:00
/*
* Here we set the files / folders which should not be packaged with patch packages only
* These paths are from the repository root without the leading slash
*/
$doNotPatch = array (
2022-06-28 11:32:56 +00:00
'administrator/cache' ,
'administrator/logs' ,
'images' ,
2022-08-14 07:12:04 +00:00
'installation' ,
2014-05-19 20:52:38 +00:00
);
2018-05-06 15:28:38 +00:00
/*
* This array will contain the checksums for all files which are created by this script .
* This is an associative array with the following structure :
* array (
* 'filename' => array (
* 'type1' => 'hash' ,
* 'type2' => 'hash' ,
* ),
* )
*/
$checksums = array ();
2013-10-31 23:09:27 +00:00
// For the packages, replace spaces in stability (RC) with underscores
2017-08-07 14:29:32 +00:00
$packageStability = str_replace ( ' ' , '_' , Version :: DEV_STATUS );
2013-10-31 23:09:27 +00:00
2018-07-28 00:17:32 +00:00
// Delete the files and folders we exclude from the packages (tests, docs, build, etc.).
echo " Delete folders not included in packages. \n " ;
2022-06-28 11:32:56 +00:00
foreach ( $doNotPackage as $removeFile ) {
system ( 'rm -rf ' . $time . '/' . $removeFile );
2018-07-28 00:17:32 +00:00
}
2012-06-22 01:31:45 +00:00
// Count down starting with the latest release and add diff files to this array
2022-06-28 11:32:56 +00:00
for ( $num = $release - 1 ; $num >= 0 ; $num -- ) {
if ( ! $buildPatchPackages ) {
echo " Disabled creating patch package for $num per flag. \n " ;
continue ;
}
echo " Create version $num update packages. \n " ;
// Here we get a list of all files that have changed between the two references ($previousTag and $remote) and save in diffdocs
$previousTag = $version . '.' . $num ;
$command = $systemGit . ' diff tags/' . $previousTag . ' ' . $remote . ' --name-status > diffdocs/' . $version . '.' . $num ;
system ( $command );
// $filesArray will hold the array of files to include in diff package
$deletedFiles = array ();
$files = file ( 'diffdocs/' . $version . '.' . $num );
// Loop through and add all files except: tests, installation, build, .git, .travis, travis, phpunit, .md, or images
foreach ( $files as $file ) {
if ( substr ( $file , 0 , 1 ) === 'R' ) {
$fileName = substr ( $file , strrpos ( $file , " \t " ) + 1 );
} else {
$fileName = substr ( $file , 2 );
}
$folderPath = explode ( '/' , $fileName );
$baseFolderName = $folderPath [ 0 ];
$doNotPackageFile = in_array ( trim ( $fileName ), $doNotPackage );
$doNotPatchFile = in_array ( trim ( $fileName ), $doNotPatch );
$doNotPackageBaseFolder = in_array ( $baseFolderName , $doNotPackage );
$doNotPatchBaseFolder = in_array ( $baseFolderName , $doNotPatch );
$dirtyHackForMediaCheck = false ;
// The raw files for the vue files are not packaged but are not a top level directory so aren't handled by the
// above checks. This is dirty but a fairly performant fix for now until we can come up with something better.
if ( count ( $folderPath ) >= 4 ) {
$fullPath = [ $folderPath [ 0 ] . '/' . $folderPath [ 1 ] . '/' . $folderPath [ 2 ] . '/' . $folderPath [ 3 ]];
$dirtyHackForMediaCheck = in_array ( 'administrator/components/com_media/resources' , $fullPath );
}
if ( $dirtyHackForMediaCheck || $doNotPackageFile || $doNotPatchFile || $doNotPackageBaseFolder || $doNotPatchBaseFolder ) {
continue ;
}
// Act on the file based on the action
switch ( substr ( $file , 0 , 1 )) {
// This is a new case with git 2.9 to handle renamed files
case 'R' :
// Explode the file on the tab character; key 0 is the action (rename), key 1 is the old filename, and key 2 is the new filename
$renamedFileData = explode ( " \t " , $file );
// Add the new file for packaging
$filesArray [ $renamedFileData [ 2 ]] = true ;
// And flag the old file as deleted
$deletedFiles [] = $renamedFileData [ 1 ];
break ;
// Deleted files
case 'D' :
$deletedFiles [] = $fileName ;
break ;
// Regular additions and modifications
default :
$filesArray [ $fileName ] = true ;
break ;
}
}
// Write the file list to a text file.
$filePut = array_keys ( $filesArray );
sort ( $filePut );
file_put_contents ( 'diffconvert/' . $version . '.' . $num , implode ( '' , $filePut ));
file_put_contents ( 'diffconvert/' . $version . '.' . $num . '-deleted' , $deletedFiles );
// Only create archives for 0 and most recent versions. Skip other update versions.
if ( $num != 0 && ( $num != $release - 1 )) {
echo " Skipping patch archive for version $version . $num\n " ;
continue ;
}
$fromName = $num == 0 ? 'x' : $num ;
// Create the diff archive packages using the file name list.
if ( ! $excludeBzip2 ) {
$packageName = 'Joomla_' . $version . '.' . $fromName . '_to_' . $fullVersion . '-' . $packageStability . '-Patch_Package.tar.bz2' ;
echo " Building " . $packageName . " ... " ;
system ( 'tar --create --bzip2 --no-recursion --directory ' . $time . ' --file packages/' . $packageName . ' --files-from diffconvert/' . $version . '.' . $num . '> /dev/null' );
echo " done. \n " ;
$checksums [ $packageName ] = array ();
}
if ( ! $excludeGzip ) {
$packageName = 'Joomla_' . $version . '.' . $fromName . '_to_' . $fullVersion . '-' . $packageStability . '-Patch_Package.tar.gz' ;
echo " Building " . $packageName . " ... " ;
system ( 'tar --create --gzip --no-recursion --directory ' . $time . ' --file packages/' . $packageName . ' --files-from diffconvert/' . $version . '.' . $num . '> /dev/null' );
echo " done. \n " ;
$checksums [ $packageName ] = array ();
}
if ( ! $excludeZip ) {
$packageName = 'Joomla_' . $version . '.' . $fromName . '_to_' . $fullVersion . '-' . $packageStability . '-Patch_Package.zip' ;
echo " Building " . $packageName . " ... " ;
chdir ( $time );
system ( 'zip ../packages/' . $packageName . ' -@ < ../diffconvert/' . $version . '.' . $num . '> /dev/null' );
chdir ( '..' );
echo " done. \n " ;
$checksums [ $packageName ] = array ();
}
if ( ! $excludeZstd ) {
$packageName = 'Joomla_' . $version . '.' . $fromName . '_to_' . $fullVersion . '-' . $packageStability . '-Patch_Package.tar.zst' ;
echo " Building " . $packageName . " ... " ;
system ( 'tar --create --use-compress-program=zstd --no-recursion --directory ' . $time . ' --file packages/' . $packageName . ' --files-from diffconvert/' . $version . '.' . $num . '> /dev/null' );
echo " done. \n " ;
$checksums [ $packageName ] = array ();
}
2012-02-07 03:24:48 +00:00
}
echo " Build full package files. \n " ;
2018-04-04 11:52:22 +00:00
chdir ( $time );
2012-02-07 03:24:48 +00:00
2021-08-17 04:00:47 +00:00
// The search package manifest should not be present for new installs, temporarily move it
system ( 'mv administrator/manifests/packages/pkg_search.xml ../pkg_search.xml' );
2021-10-17 16:35:55 +00:00
// The restore_finalisation.php should not be present for new installs, temporarily move it
system ( 'mv administrator/components/com_joomlaupdate/restore_finalisation.php ../restore_finalisation.php' );
2012-02-07 03:24:48 +00:00
// Create full archive packages.
2022-06-28 11:32:56 +00:00
if ( ! $excludeBzip2 ) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Full_Package.tar.bz2' ;
echo " Building " . $packageName . " ... " ;
system ( 'tar --create --bzip2 --file ../packages/' . $packageName . ' * > /dev/null' );
echo " done. \n " ;
$checksums [ $packageName ] = array ();
2018-04-04 11:52:22 +00:00
}
2012-02-07 03:24:48 +00:00
2022-06-28 11:32:56 +00:00
if ( ! $excludeGzip ) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Full_Package.tar.gz' ;
echo " Building " . $packageName . " ... " ;
system ( 'tar --create --gzip --file ../packages/' . $packageName . ' * > /dev/null' );
echo " done. \n " ;
$checksums [ $packageName ] = array ();
2018-04-04 11:52:22 +00:00
}
2012-02-07 03:24:48 +00:00
2022-06-28 11:32:56 +00:00
if ( ! $excludeZip ) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Full_Package.zip' ;
echo " Building " . $packageName . " ... " ;
system ( 'zip -r ../packages/' . $packageName . ' * > /dev/null' );
echo " done. \n " ;
$checksums [ $packageName ] = array ();
2020-03-20 12:05:38 +00:00
}
2022-06-28 11:32:56 +00:00
if ( ! $excludeZstd ) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Full_Package.tar.zst' ;
echo " Building " . $packageName . " ... " ;
system ( 'tar --create --use-compress-program=zstd --file ../packages/' . $packageName . ' * > /dev/null' );
echo " done. \n " ;
$checksums [ $packageName ] = array ();
2018-04-04 11:52:22 +00:00
}
2012-02-07 03:24:48 +00:00
2016-05-11 21:20:18 +00:00
// Create full update file without the default logs directory, installation folder, or sample images.
2012-02-07 03:24:48 +00:00
echo " Build full update package. \n " ;
2016-05-11 21:20:18 +00:00
system ( 'rm -r administrator/logs' );
2012-02-07 03:24:48 +00:00
system ( 'rm -r installation' );
2014-01-31 00:51:26 +00:00
system ( 'rm -r images/banners' );
system ( 'rm -r images/headers' );
system ( 'rm -r images/sampledata' );
2015-03-18 22:56:56 +00:00
system ( 'rm images/joomla_black.png' );
2014-01-31 00:51:26 +00:00
system ( 'rm images/powered_by.png' );
2012-10-08 21:27:15 +00:00
2021-08-17 04:00:47 +00:00
// Move the search manifest back
system ( 'mv ../pkg_search.xml administrator/manifests/packages/pkg_search.xml' );
2021-10-17 16:35:55 +00:00
// Move the restore_finalisation.php back
system ( 'mv ../restore_finalisation.php administrator/components/com_joomlaupdate/restore_finalisation.php' );
2022-06-28 11:32:56 +00:00
if ( ! $excludeBzip2 ) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Update_Package.tar.bz2' ;
echo " Building " . $packageName . " ... " ;
system ( 'tar --create --bzip2 --file ../packages/' . $packageName . ' * > /dev/null' );
echo " done. \n " ;
$checksums [ $packageName ] = array ();
2018-04-04 11:52:22 +00:00
}
2012-10-08 21:27:15 +00:00
2022-06-28 11:32:56 +00:00
if ( ! $excludeGzip ) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Update_Package.tar.gz' ;
echo " Building " . $packageName . " ... " ;
system ( 'tar --create --gzip --file ../packages/' . $packageName . ' * > /dev/null' );
echo " done. \n " ;
$checksums [ $packageName ] = array ();
2018-04-04 11:52:22 +00:00
}
2012-10-08 21:27:15 +00:00
2022-06-28 11:32:56 +00:00
if ( ! $excludeZip ) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Update_Package.zip' ;
echo " Building " . $packageName . " ... " ;
system ( 'zip -r ../packages/' . $packageName . ' * > /dev/null' );
echo " done. \n " ;
$checksums [ $packageName ] = array ();
2020-03-20 12:05:38 +00:00
}
2022-06-28 11:32:56 +00:00
if ( ! $excludeZstd ) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Update_Package.tar.zst' ;
echo " Building " . $packageName . " ... " ;
system ( 'tar --create --use-compress-program=zstd --file ../packages/' . $packageName . ' * > /dev/null' );
echo " done. \n " ;
$checksums [ $packageName ] = array ();
2018-05-06 15:28:38 +00:00
}
chdir ( '..' );
2021-08-15 13:45:18 +00:00
// This is only needed when we release a version
2022-06-28 11:32:56 +00:00
if ( $includeExtraTextfiles ) {
foreach ( array_keys ( $checksums ) as $packageName ) {
echo " Generating checksums for $packageName\n " ;
foreach ( array ( 'sha256' , 'sha384' , 'sha512' ) as $hash ) {
if ( file_exists ( 'packages/' . $packageName )) {
$checksums [ $packageName ][ $hash ] = hash_file ( $hash , 'packages/' . $packageName );
} else {
echo " Package $packageName not found in build directories \n " ;
}
}
}
echo " Generating checksums.txt file \n " ;
$checksumsContent = '' ;
foreach ( $checksums as $packageName => $packageHashes ) {
$checksumsContent .= " Filename: $packageName\n " ;
foreach ( $packageHashes as $hashType => $hash ) {
$checksumsContent .= " $hashType : $hash\n " ;
}
$checksumsContent .= " \n " ;
}
file_put_contents ( 'checksums.txt' , $checksumsContent );
echo " Generating github_release.txt file \n " ;
$githubContent = array ();
$githubText = '' ;
$releaseText = array (
'FULL' => 'New Joomla! Installations ' ,
'POINT' => 'Update from Joomla! ' . $version . '.' . $previousRelease . ' ' ,
'MINOR' => 'Update from Joomla! ' . $version . '.x ' ,
'UPGRADE' => 'Update from Joomla! 3.10 ' ,
);
if ( ! $buildPatchPackages ) {
$releaseText [ 'UPGRADE' ] = 'Update from a previous version of Joomla! ' ;
}
$githubLink = 'https://github.com/joomla/joomla-cms/releases/download/' . $tagVersion . '/' ;
foreach ( $checksums as $packageName => $packageHashes ) {
$type = '' ;
if ( strpos ( $packageName , 'Full_Package' ) !== false ) {
$type = 'FULL' ;
} elseif ( strpos ( $packageName , 'Patch_Package' ) !== false ) {
if ( strpos ( $packageName , '.x_to' ) !== false ) {
$type = 'MINOR' ;
} else {
$type = 'POINT' ;
}
} elseif ( strpos ( $packageName , 'Update_Package' ) !== false ) {
$type = 'UPGRADE' ;
}
$githubContent [ $type ][] = '[' . substr ( $packageName , strpos ( $packageName , 'Package' ) + 7 ) . '](' . $githubLink . $packageName . ')' ;
}
foreach ( $releaseText as $type => $text ) {
if ( empty ( $githubContent [ $type ])) {
continue ;
}
$githubText .= $text ;
$githubText .= implode ( " | " , $githubContent [ $type ]);
$githubText .= " \n " ;
}
file_put_contents ( 'github_release.txt' , $githubText );
2020-08-17 11:31:26 +00:00
}
2013-08-24 00:42:52 +00:00
echo " Build of version $fullVersion complete! \n " ;