-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
build.php
728 lines (597 loc) · 27.3 KB
/
build.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
<?php
/**
* Script used to build Joomla distribution archive packages
* Builds packages in tmp/packages folder (for example, 'build/tmp/packages')
*
* 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.
*
* This script is designed to be run in CLI on Linux, Mac OS X and WSL.
* Make sure your default umask is 022 to create archives with correct permissions.
*
* 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
*
* 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.
*
* @package Joomla.Build
* @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
use Joomla\CMS\Version;
const PHP_TAB = "\t";
function usage(string $command)
{
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;
}
function clean_checkout(string $dir)
{
// 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 -');
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');
// 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');
echo "Cleanup complete.\n";
chdir($cwd);
}
function clean_composer(string $dir)
{
// Save the current working directory to restore when complete
$cwd = getcwd();
chdir($dir);
echo "Cleaning Composer manifests in $dir.\n";
// Removes Composer manifests
system('find . -name composer.json | xargs rm -rf -');
system('find . -name composer.lock | xargs rm -rf -');
echo "Cleanup complete.\n";
chdir($cwd);
}
$time = time();
// Set path to git binary (e.g., /usr/local/git/bin/git or /usr/bin/git)
ob_start();
passthru('which git', $systemGit);
$systemGit = trim(ob_get_clean());
// Make sure file and folder permissions are set correctly
umask(022);
// Shortcut the paths to the repository root and build folder
$repo = dirname(__DIR__);
$here = __DIR__;
// Set paths for the build packages
$tmp = $here . '/tmp';
$fullpath = $tmp . '/' . $time;
// Parse input options
$options = getopt('', ['help', 'remote::', 'exclude-zip', 'exclude-gzip', 'exclude-bzip2', 'include-zstd', 'disable-patch-packages']);
$remote = $options['remote'] ?? false;
$excludeZip = isset($options['exclude-zip']);
$excludeGzip = isset($options['exclude-gzip']);
$excludeBzip2 = isset($options['exclude-bzip2']);
$excludeZstd = !isset($options['include-zstd']);
$buildPatchPackages = !isset($options['disable-patch-packages']);
$showHelp = isset($options['help']);
// Disable the generation of extra text files
$includeExtraTextfiles = false;
if ($showHelp) {
usage($argv[0]);
exit;
}
// If not given a remote, assume we are looking for the latest local tag
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;
}
echo "Start build for remote $remote.\n";
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);
system($systemGit . ' archive ' . $remote . ' | tar -x -C ' . $fullpath);
// Install PHP and NPM dependencies and compile required media assets, skip Composer autoloader until post-cleanup
chdir($fullpath);
system('composer install --no-dev --no-autoloader --ignore-platform-reqs', $composerReturnCode);
if ($composerReturnCode !== 0) {
echo "`composer install` did not complete as expected.\n";
exit(1);
}
system('npm install --unsafe-perm', $npmReturnCode);
if ($npmReturnCode !== 0) {
echo "`npm install` did not complete as expected.\n";
exit(1);
}
// Create gzipped version of the static assets
system('npm run gzip', $gzipReturnCode);
if ($gzipReturnCode !== 0) {
echo "`npm run gzip` did not complete as expected.\n";
exit(1);
}
// Create version entries of the static assets in their respective joomla.asset.json
system('npm run versioning', $verReturnCode);
if ($verReturnCode !== 0) {
echo "`npm run versioning` did not complete as expected.\n";
exit(1);
}
// Clean the checkout of extra resources
clean_checkout($fullpath);
// Regenerate the Composer autoloader without deleted files
system('composer dump-autoload --no-dev --optimize --no-scripts');
// Clean the Composer manifests now
clean_composer($fullpath);
// And cleanup the Node installation
system('rm -rf node_modules');
echo "Workspace built.\n";
// 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;
$fullVersion = (new Version())->getShortVersion();
$previousRelease = Version::PATCH_VERSION - 1;
if ($previousRelease < 0) {
$previousRelease = false;
}
chdir($tmp);
system('mkdir diffdocs');
system('mkdir diffconvert');
system('mkdir packages');
echo "Create list of changed files from git repository for version $fullVersion.\n";
/*
* 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.
*/
$filesArray = array(
"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
);
/*
* 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
* Because this is a fresh copy from a git tag, local environment files may be ignored
*/
$doNotPackage = array(
'.appveyor.yml',
'.drone.yml',
'.editorconfig',
'.github',
'.gitignore',
'.php-cs-fixer.dist.php',
'CODE_OF_CONDUCT.md',
'README.md',
'acceptance.suite.yml',
'appveyor-phpunit.xml',
'build',
'build.xml',
'codeception.yml',
'composer.json',
'composer.lock',
'crowdin.yml',
'package-lock.json',
'package.json',
'phpunit-pgsql.xml.dist',
'phpunit.xml.dist',
'plugins/sampledata/testing/testing.php',
'plugins/sampledata/testing/testing.xml',
'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',
'ruleset.xml',
'selenium.log',
'tests',
// Media Manager Node Assets
'administrator/components/com_media/resources',
);
/*
* 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(
'administrator/cache',
'administrator/logs',
'installation',
'images',
);
/*
* 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();
// For the packages, replace spaces in stability (RC) with underscores
$packageStability = str_replace(' ', '_', Version::DEV_STATUS);
// Delete the files and folders we exclude from the packages (tests, docs, build, etc.).
echo "Delete folders not included in packages.\n";
foreach ($doNotPackage as $removeFile) {
system('rm -rf ' . $time . '/' . $removeFile);
}
// Count down starting with the latest release and add diff files to this array
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();
}
}
echo "Build full package files.\n";
chdir($time);
// 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');
// 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');
// Create full archive packages.
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();
}
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();
}
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();
}
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();
}
// Create full update file without the default logs directory, installation folder, or sample images.
echo "Build full update package.\n";
system('rm -r administrator/logs');
system('rm -r installation');
system('rm -r images/banners');
system('rm -r images/headers');
system('rm -r images/sampledata');
system('rm images/joomla_black.png');
system('rm images/powered_by.png');
// Move the search manifest back
system('mv ../pkg_search.xml administrator/manifests/packages/pkg_search.xml');
// Move the restore_finalisation.php back
system('mv ../restore_finalisation.php administrator/components/com_joomlaupdate/restore_finalisation.php');
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();
}
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();
}
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();
}
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();
}
chdir('..');
// This is only needed when we release a version
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);
}
echo "Build of version $fullVersion complete!\n";