From beb63b2b4b73c5fd966e60ed635bbac777c59ec4 Mon Sep 17 00:00:00 2001 From: Stefan Wendhausen Date: Sat, 11 Jan 2025 22:34:52 +0100 Subject: [PATCH 1/2] improve bump script --- build/bump.php | 471 +++++++++++++++++++++++-------------------------- 1 file changed, 225 insertions(+), 246 deletions(-) diff --git a/build/bump.php b/build/bump.php index e3b7a1f96..8e974509e 100644 --- a/build/bump.php +++ b/build/bump.php @@ -1,36 +1,29 @@ -l + * Usage: php build/bump.php -v -l -d * * Examples: - * - php build/bump.php -v 4.1.0 -l 1 + * - php build/bump.php -v 5.2.4 -l 1 + * - php build/bump.php -v 5.2.4-rc1 -l 1 -d "2025-02-11 18:00" * * @package Joomla.Language * @copyright (C) 2021 - 2025 J!German * @license GNU General Public License version 2 or later; see LICENSE.txt */ -// This script is largly based on the Joomla CMS Bump Script -// https://github.com/joomla/joomla-cms/blob/4.0-dev/build/bump.php +const DATE_FORMAT = 'Y-m-d H:i'; +const PHP_TAB = "\t"; -// Functions -function usage($command) -{ - echo PHP_EOL; - echo 'Usage: php ' . $command . ' [options]' . PHP_EOL; - echo PHP_TAB . '[options]:' . PHP_EOL; - echo PHP_TAB . PHP_TAB . '-v :' . PHP_TAB . 'Version (ex: 4.1.0, 4.1.0-rc1)' . PHP_EOL; - echo PHP_TAB . PHP_TAB . '-l :' . PHP_TAB . 'Languagepackversion (ex: 1, 2)' . PHP_EOL; - echo PHP_EOL; -} +// Make sure we use the correct language and timezone. +setlocale(LC_ALL, 'en_GB'); +date_default_timezone_set('Europe/London'); -// Constants. -const PHP_TAB = "\t"; +// Make sure file and folder permissions are set correctly. +umask(022); -// File paths. +// File paths $languageXmlFiles = [ '/administrator/language/de-DE/install.xml', '/administrator/language/de-DE/langmetadata.xml', @@ -39,271 +32,257 @@ function usage($command) '/language/de-DE/install.xml', '/language/de-DE/langmetadata.xml', ]; - $installerXmlFile = '/installation/language/de-DE/langmetadata.xml'; - $languagePackXmlFile = '/pkg_de-DE.xml'; - $languagePackSqlFile = '/installation/sql/mysql/localise.sql'; -/* - * Change copyright date exclusions. - * Some systems may try to scan the .git directory, exclude it. - * Also exclude build resources such as the packaging space or the API documentation build - * as well as external libraries. - */ -$directoryLoopExcludeDirectories = [ - '/.git', - '/build/tmp/', -]; - +// Exclusion rules +$directoryLoopExcludeDirectories = ['/.git', '/build/tmp/']; $directoryLoopExcludeFiles = []; -// Check arguments (exit if incorrect cli arguments). -$opts = getopt("v:l:"); - -if (empty($opts['v'])) -{ - usage($argv[0]); - die(); +// Function to display usage +/** + * @param $command + * @return void + */ +function usage($command) { + echo PHP_EOL; + echo 'Usage: php ' . $command . ' [options]' . PHP_EOL; + echo PHP_TAB . '[options]:' . PHP_EOL; + echo PHP_TAB . PHP_TAB . '-v : Version (e.g., 5.2.4, 5.2.4-rc1)' . PHP_EOL; + echo PHP_TAB . PHP_TAB . '-l : Language pack version (e.g., 1, 2)' . PHP_EOL; + echo PHP_TAB . PHP_TAB . '-d : Release date in ISO 8601 format [optional] (e.g., "2025-02-11 18:00")' . PHP_EOL; + echo PHP_EOL; } -if (empty($opts['l'])) -{ - usage($argv[0]); - die(); -} +/** + * @param $dateString + * @return DateTime|void + */ +function validateDate($dateString) { + if ($dateString === 'now') { + return new DateTime('now'); + } -// Check version string (exit if not correct). -$versionParts = explode('-', $opts['v']); -$languagePackVersion = (integer) $opts['l']; + $date = DateTime::createFromFormat(DATE_FORMAT, $dateString); + if (!$date || $date->format(DATE_FORMAT) !== $dateString) { + die("Error: Invalid date format. Please use 'Y-m-d H:i'."); + } -if (!preg_match('#^[0-9]+\.[0-9]+\.[0-9]+$#', $versionParts[0])) -{ - usage($argv[0]); - die(); + return $date; } -if (isset($versionParts[1]) && !preg_match('#(dev|alpha|beta|rc)[0-9]*#', $versionParts[1])) -{ - usage($argv[0]); - die(); +/** + * @param $versionParts + * @return string + */ +function determineDevStatus($versionParts) { + $devStatus = 'Stable'; + if (isset($versionParts[1])) { + if (preg_match('#^dev#', $versionParts[1])) { + $devStatus = 'Development'; + } elseif (preg_match('#^alpha#', $versionParts[1])) { + $devStatus = 'Alpha'; + } elseif (preg_match('#^beta#', $versionParts[1])) { + $devStatus = 'Beta'; + } elseif (preg_match('#^rc#', $versionParts[1])) { + $devStatus = 'Release Candidate'; + } + } + return $devStatus; } -if (isset($versionParts[2]) && $versionParts[2] !== 'dev') -{ - usage($argv[0]); - die(); +/** + * @param $rootPath + * @param $files + * @param $version + * @return void + */ +function updateLanguageXmlFiles($rootPath, $files, $version) { + foreach ($files as $file) { + $filePath = $rootPath . $file; + if (file_exists($filePath)) { + $contents = file_get_contents($filePath); + $contents = preg_replace('#[^<]*#', '' . $version['full'] . '', $contents); + $contents = preg_replace('#[^<]*#', '' . $version['credate'] . '', $contents); + $contents = preg_replace('#(.*)<\/span>#', '' . $version['main'] . '', $contents); + file_put_contents($filePath, $contents); + echo "Updated: $filePath" . PHP_EOL; + } else { + echo "Skipped: File not found - $filePath" . PHP_EOL; + } + } } -if (!is_integer($languagePackVersion)) -{ - usage($argv[0]); - die(); +/** + * @param $rootPath + * @param $file + * @param $version + * @return void + */ +function updateInstallerXmlFile($rootPath, $file, $version) { + $filePath = $rootPath . $file; + if (file_exists($filePath)) { + $contents = file_get_contents($filePath); + $contents = preg_replace('#[^<]*#', '' . $version['install_version'] . '', $contents); + $contents = preg_replace('#[^<]*#', '' . $version['install_credate'] . '', $contents); + $contents = preg_replace('#(.*)<\/span>#', '' . $version['main'] . '', $contents); + file_put_contents($filePath, $contents); + echo "Updated: $filePath" . PHP_EOL; + } else { + echo "Skipped: File not found - $filePath" . PHP_EOL; + } } -// Make sure we use the correct language and timezone. -setlocale(LC_ALL, 'en_GB'); -date_default_timezone_set('Europe/London'); - -// Make sure file and folder permissions are set correctly. -umask(022); - -// Get version dev status. -$dev_status = 'Stable'; - -if (!isset($versionParts[1])) -{ - $versionParts[1] = ''; -} -else -{ - if (preg_match('#^dev#', $versionParts[1])) - { - $dev_status = 'Development'; - } - elseif (preg_match('#^alpha#', $versionParts[1])) - { - $dev_status = 'Alpha'; - } - elseif (preg_match('#^beta#', $versionParts[1])) - { - $dev_status = 'Beta'; - } - elseif (preg_match('#^rc#', $versionParts[1])) - { - $dev_status = 'Release Candidate'; +/** + * @param $rootPath + * @param $file + * @param $version + * @return void + */ +function updateLanguagePackXmlFile($rootPath, $file, $version) { + $filePath = $rootPath . $file; + if (file_exists($filePath)) { + $contents = file_get_contents($filePath); + $contents = preg_replace('#[^<]*#', '' . $version['full'] . '', $contents); + $contents = preg_replace('#[^<]*#', '' . $version['credate'] . '', $contents); + $contents = preg_replace( + '#

(.*)<\/h2>#', + '

Deutsches Sprachpaket (Version: ' . $version['full'] . ' vom ' . $version['credate_de'] . ') für Joomla! ' . $version['main'] . ' von J!German

', + $contents + ); + file_put_contents($filePath, $contents); + echo "Updated: $filePath" . PHP_EOL; + } else { + echo "Skipped: File not found - $filePath" . PHP_EOL; } } -if (!isset($versionParts[2])) -{ - $versionParts[2] = ''; -} -else -{ - $dev_status = 'Development'; +/** + * @param $rootPath + * @param $file + * @param $version + * @return void + */ +function updateLanguagePackSqlFile($rootPath, $file, $version) { + $filePath = $rootPath . $file; + if (file_exists($filePath)) { + $contents = file_get_contents($filePath); + $contents = preg_replace('#"version":"[^"]*"#', '"version":"' . $version['full'] . '"', $contents); + $contents = preg_replace('#"creationDate":"[^"]*"#', '"creationDate":"' . $version['credate'] . '"', $contents); + file_put_contents($filePath, $contents); + echo "Updated: $filePath" . PHP_EOL; + } else { + echo "Skipped: File not found - $filePath" . PHP_EOL; + } } -// Set version properties. -$versionSubParts = explode('.', $versionParts[0]); +/** + * @param $rootPath + * @param $year + * @param $excludeDirectories + * @param $excludeFiles + * @return void + */ +function changeCopyrightDate($rootPath, $year, $excludeDirectories, $excludeFiles) { + $changedFiles = 0; + $directory = new RecursiveDirectoryIterator($rootPath); + $iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST); + + foreach ($iterator as $file) { + if ($file->isFile()) { + $filePath = $file->getPathname(); + $relativePath = str_replace($rootPath, '', $filePath); + + // Skip excluded files and directories + if (preg_match('#\.(png|jpeg|jpg|gif|bmp|ico|webp|svg|woff|woff2|ttf|eot)$#', $filePath) || in_array($relativePath, $excludeFiles)) { + continue; + } -$version = [ - 'main' => $versionSubParts[0] . '.' . $versionSubParts[1], - 'major' => $versionSubParts[0], - 'minor' => $versionSubParts[1], - 'patch' => $versionSubParts[2], - 'extra' => (!empty($versionParts[1]) ? $versionParts[1] : '') . (!empty($versionParts[2]) ? (!empty($versionParts[1]) ? '-' : '') . $versionParts[2] : ''), - 'release' => $versionSubParts[0] . '.' . $versionSubParts[1] . '.' . $versionSubParts[2] . 'v' . $languagePackVersion, - 'full' => $versionSubParts[0] . '.' . $versionSubParts[1] . '.' . $versionSubParts[2] . (!empty($versionParts[1]) ? '-' . $versionParts[1] : '') . (!empty($versionParts[2]) ? '-' . $versionParts[2] : '') . '.' . $languagePackVersion, - 'dev_devel' => $versionSubParts[2] . (!empty($versionParts[1]) ? '-' . $versionParts[1] : '') . (!empty($versionParts[2]) ? '-' . $versionParts[2] : ''), - 'dev_status' => $dev_status, - 'reldate' => date('j-F-Y'), - 'reltime' => date('H:i'), - 'reltz' => 'GMT', - 'credate' => date('Y-m-d'), - 'credate_de' => date('d.m.Y'), - 'install_credate' => date('Y-m'), - 'install_version' => $versionSubParts[0] . '.' . $versionSubParts[1] . '.' . $versionSubParts[2], -]; + $skip = false; + foreach ($excludeDirectories as $excludeDir) { + if (strpos($relativePath, $excludeDir) === 0) { + $skip = true; + break; + } + } -// Prints version information. -echo PHP_EOL; -echo 'Version data:' . PHP_EOL; -echo '- Main:' . PHP_TAB . PHP_TAB . PHP_TAB . PHP_TAB . $version['main'] . PHP_EOL; -echo '- Release:' . PHP_TAB . PHP_TAB . PHP_TAB . $version['release'] . PHP_EOL; -echo '- Full:' . PHP_TAB . PHP_TAB . PHP_TAB . PHP_TAB . $version['full'] . PHP_EOL; -echo '- Dev Level:' . PHP_TAB . PHP_TAB . PHP_TAB . $version['dev_devel'] . PHP_EOL; -echo '- Dev Status:' . PHP_TAB . PHP_TAB . PHP_TAB . $version['dev_status'] . PHP_EOL; -echo '- Release date:' . PHP_TAB . PHP_TAB . PHP_TAB . $version['reldate'] . PHP_EOL; -echo '- Release time:' . PHP_TAB . PHP_TAB . PHP_TAB . $version['reltime'] . PHP_EOL; -echo '- Release timezone:' . PHP_TAB . PHP_TAB . $version['reltz'] . PHP_EOL; -echo '- Creation date:' . PHP_TAB . PHP_TAB . $version['credate'] . PHP_EOL; -echo '- Creation date DE:' . PHP_TAB . PHP_TAB . $version['credate_de'] . PHP_EOL; -echo '- Installer: creation date:' . PHP_TAB . $version['install_credate'] . PHP_EOL; -echo '- Installer: version:' . PHP_TAB . PHP_TAB . $version['install_version'] . PHP_EOL; - - -echo PHP_EOL; + if ($skip) { + continue; + } -$rootPath = dirname(__DIR__); + // Load file contents and replace copyright year + $contents = file_get_contents($filePath); + $updated = false; -// Updates the version and creation date in language xml files. -foreach ($languageXmlFiles as $languageXmlFile) -{ - if (file_exists($rootPath . $languageXmlFile)) - { - $fileContents = file_get_contents($rootPath . $languageXmlFile); - $fileContents = preg_replace('#[^<]*#', '' . $version['full'] . '', $fileContents); - $fileContents = preg_replace('#[^<]*#', '' . $version['credate'] . '', $fileContents); - $fileContents = preg_replace('#(.*)<\/span>#', '' . $version['main'] . '', $fileContents); - file_put_contents($rootPath . $languageXmlFile, $fileContents); + if (preg_match('#2005\s+-\s+[0-9]{4}\s+Open\s+Source\s+Matters#', $contents)) { + $contents = preg_replace('#2005\s+-\s+[0-9]{4}\s+Open\s+Source\s+Matters#', '2005 - ' . $year . ' Open Source Matters', $contents); + $updated = true; + } + + if (preg_match('#2008\s+-\s+[0-9]{4}\s+J\!German#', $contents)) { + $contents = preg_replace('#2008\s+-\s+[0-9]{4}\s+J\!German#', '2008 - ' . $year . ' J!German', $contents); + $updated = true; + } + + if ($updated) { + file_put_contents($filePath, $contents); + echo "Copyright updated: $filePath" . PHP_EOL; + $changedFiles++; + } + } } -} -// Updates the version and creation date in language installer xml file. -if (file_exists($rootPath . $installerXmlFile)) -{ - $fileContents = file_get_contents($rootPath . $installerXmlFile); - $fileContents = preg_replace('#[^<]*#', '' . $version['install_version'] . '', $fileContents); - $fileContents = preg_replace('#[^<]*#', '' . $version['install_credate'] . '', $fileContents); - $fileContents = preg_replace('#(.*)<\/span>#', '' . $version['main'] . '', $fileContents); - file_put_contents($rootPath . $installerXmlFile, $fileContents); + echo "Copyright updated in $changedFiles files." . PHP_EOL; } -// Updates the version and creation date in language package xml file. -if (file_exists($rootPath . $languagePackXmlFile)) -{ - $fileContents = file_get_contents($rootPath . $languagePackXmlFile); - $fileContents = preg_replace('#[^<]*#', '' . $version['full'] . '', $fileContents); - $fileContents = preg_replace('#[^<]*#', '' . $version['credate'] . '', $fileContents); - $fileContents = preg_replace('#

(.*)<\/h2>#', '

Deutsches Sprachpaket (Version: ' . $version['full'] . ' vom ' . $version['credate_de'] . ') für Joomla! ' . $version['main'] . ' von J!German

', $fileContents); - file_put_contents($rootPath . $languagePackXmlFile, $fileContents); +$opts = getopt("v:l:d:"); +if (empty($opts['v']) || empty($opts['l'])) { + usage($argv[0]); + die(); } -// Updates the version and creation date in localise.sql file. -if (file_exists($rootPath . $languagePackSqlFile)) -{ - $fileContents = file_get_contents($rootPath . $languagePackSqlFile); - $fileContents = preg_replace('#"version":"[^"]*"#', '"version":"' . $version['full'] . '"', $fileContents); - $fileContents = preg_replace('#"creationDate":"[^"]*"#', '"creationDate":"' . $version['credate'] . '"', $fileContents); - file_put_contents($rootPath . $languagePackSqlFile, $fileContents); +$versionParts = explode('-', $opts['v']); +if (!preg_match('#^[0-9]+\.[0-9]+\.[0-9]+$#', $versionParts[0])) { + usage($argv[0]); + die(); } -// Updates the copyright date in core files. -$changedFilesCopyrightDate = 0; -$year = date('Y'); -$directory = new RecursiveDirectoryIterator($rootPath); -$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST); - -foreach ($iterator as $file) -{ - if ($file->isFile()) - { - $filePath = $file->getPathname(); - $relativePath = str_replace($rootPath, '', $filePath); - - // Exclude certain extensions. - if (preg_match('#\.(png|jpeg|jpg|gif|bmp|ico|webp|svg|woff|woff2|ttf|eot)$#', $filePath)) - { - continue; - } - - // Exclude certain files. - if (in_array($relativePath, $directoryLoopExcludeFiles)) - { - continue; - } - - // Exclude certain directories. - $continue = true; - - foreach ($directoryLoopExcludeDirectories as $excludeDirectory) - { - if (preg_match('#^' . preg_quote($excludeDirectory) . '#', $relativePath)) - { - $continue = false; - break; - } - } - - if ($continue) - { - $changeCopyrightDate = false; +$languagePackVersion = (int)$opts['l']; +if (!is_int($languagePackVersion)) { + usage($argv[0]); + die(); +} - // Load the file. - $fileContents = file_get_contents($filePath); +$date = validateDate($opts['d'] ?? 'now'); +$devStatus = determineDevStatus($versionParts); +$versionSubParts = explode('.', $versionParts[0]); +$year = $date->format('Y'); - // Check if need to change the copyright date. - if (preg_match('#2005\s+-\s+[0-9]{4}\s+Open\s+Source\s+Matters#', $fileContents) && !preg_match('#2005\s+-\s+' . $year . '\s+Open\s+Source\s+Matters#', $fileContents)) - { - $changeCopyrightDate = true; - $fileContents = preg_replace('#2005\s+-\s+[0-9]{4}\s+Open\s+Source\s+Matters#', '2005 - ' . $year . ' Open Source Matters', $fileContents); - $changedFilesCopyrightDate++; - } +$version = [ + 'main' => "{$versionSubParts[0]}.{$versionSubParts[1]}", + 'release' => $versionSubParts[0] . '.' . $versionSubParts[1] . '.' . $versionSubParts[2] . 'v' . $languagePackVersion, + 'full' => "{$opts['v']}.{$languagePackVersion}", + 'dev_status' => $devStatus, + 'reldate' => $date->format('j-F-Y'), + 'reltime' => $date->format('H:i'), + 'reltz' => 'GMT', + 'credate' => $date->format('Y-m-d'), + 'credate_de' => $date->format('d.m.Y'), + 'install_credate' => $date->format('Y-m'), + 'install_version' => "{$versionSubParts[0]}.{$versionSubParts[1]}.{$versionSubParts[2]}", +]; - // Check if need to change the copyright date. - if (preg_match('#2008\s+-\s+[0-9]{4}\s+J\!German#', $fileContents) && !preg_match('#2008\s+-\s+' . $year . '\s+J\!German#', $fileContents)) - { - $changeCopyrightDate = true; - $fileContents = preg_replace('#2008\s+-\s+[0-9]{4}\s+J!German#', '2008 - ' . $year . ' J!German', $fileContents); - $changedFilesCopyrightDate++; - } +$rootPath = dirname(__DIR__); - // Save the file. - if ($changeCopyrightDate) - { - echo $filePath; - file_put_contents($filePath, $fileContents); - } - } - } -} +changeCopyrightDate($rootPath, $year, $directoryLoopExcludeDirectories, $directoryLoopExcludeFiles); +updateLanguageXmlFiles($rootPath, $languageXmlFiles, $version); +updateInstallerXmlFile($rootPath, $installerXmlFile, $version); +updateLanguagePackXmlFile($rootPath, $languagePackXmlFile, $version); +updateLanguagePackSqlFile($rootPath, $languagePackSqlFile, $version); -if ($changedFilesCopyrightDate > 0) -{ - echo '- Copyright Date changed in ' . $changedFilesCopyrightDate . ' files.' . PHP_EOL; - echo PHP_EOL; +echo PHP_EOL . "Version information:" . PHP_EOL; +foreach ($version as $key => $value) { + echo "- " . ucfirst($key) . ": " . $value . PHP_EOL; } - -echo 'Version bump complete!' . PHP_EOL; +echo PHP_EOL . "Version bump complete!" . PHP_EOL; From 6e4692da84b53d1adc2df021173980141f194685 Mon Sep 17 00:00:00 2001 From: Stefan Wendhausen Date: Mon, 13 Jan 2025 08:19:14 +0100 Subject: [PATCH 2/2] remove not in use --- build/bump.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/build/bump.php b/build/bump.php index 8e974509e..3065dfc0b 100644 --- a/build/bump.php +++ b/build/bump.php @@ -215,11 +215,6 @@ function changeCopyrightDate($rootPath, $year, $excludeDirectories, $excludeFile $contents = file_get_contents($filePath); $updated = false; - if (preg_match('#2005\s+-\s+[0-9]{4}\s+Open\s+Source\s+Matters#', $contents)) { - $contents = preg_replace('#2005\s+-\s+[0-9]{4}\s+Open\s+Source\s+Matters#', '2005 - ' . $year . ' Open Source Matters', $contents); - $updated = true; - } - if (preg_match('#2008\s+-\s+[0-9]{4}\s+J\!German#', $contents)) { $contents = preg_replace('#2008\s+-\s+[0-9]{4}\s+J\!German#', '2008 - ' . $year . ' J!German', $contents); $updated = true;