From 28ff362ec07b2d9fcef142460a34c999ee1d452a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 18 Sep 2019 21:47:06 +0200 Subject: [ticket/16160] Add script for generating package json file PHPBB3-16160 --- build/generate_package_json.php | 128 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 build/generate_package_json.php (limited to 'build') diff --git a/build/generate_package_json.php b/build/generate_package_json.php new file mode 100644 index 0000000000..ed9341fa14 --- /dev/null +++ b/build/generate_package_json.php @@ -0,0 +1,128 @@ +#!/usr/bin/env php + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +if (version_compare(PHP_VERSION, '7.0-dev', '<')) +{ + die('generate_package_json.php requires at least PHP 7.0.'); +} + +define('IN_PHPBB', true); +include_once('../phpBB/includes/functions.php'); + +$json_data = new \stdClass(); +$json_data->metadata = new class +{ + public $current_version_date; + public $current_version; + public $download_path; + public $show_update_package = true; + public $historic = false; +}; + +$json_data->package = []; + +// Open build.xml +$build_xml = simplexml_load_file('build.xml'); +$current_version = (string) $build_xml->xpath('/project/property[@name=\'newversion\']/@value')[0]->value; +$previous_version = (string) $build_xml->xpath('/project/property[@name=\'prevversion\']/@value')[0]->value; +$older_verions = explode(', ', (string) $build_xml->xpath('/project/property[@name=\'olderversions\']/@value')[0]->value); + +// Clean and sort version info +$older_verions[] = $previous_version; +$older_verions = array_filter($older_verions, function($version) { + preg_match(get_preg_expression('semantic_version'), $version, $matches); + return empty($matches['prerelease']) || strpos($matches['prerelease'], 'pl') !== false; +}); +usort($older_verions, function($version_a, $version_b) +{ + return phpbb_version_compare($version_b, $version_a); +}); + +// Set metadata +$json_data->metadata->current_version = $current_version; +$json_data->metadata->current_version_date = date('Y-m-d'); +$json_data->metadata->download_path = 'https://download.phpbb.com/pub/release/' . preg_replace('#([0-9]+\.[0-9]+)(\..+)#', '$1', $current_version) . '/' . $current_version; + +// Add package, patch files, and changed files +phpbb_add_package_file( + $json_data->package, + 'phpBB ' . $current_version, + 'phpBB-' . $current_version, + 'full', + '' +); +phpbb_add_package_file( + $json_data->package, + 'phpBB ' . $current_version . ' Patch Files', + 'phpBB-' . $current_version . '-patch', + 'update', + 'patch' +); +phpbb_add_package_file( + $json_data->package, + 'phpBB ' . $current_version . ' Changed Files', + 'phpBB-' . $current_version . '-files', + 'update', + 'files' +); + +// Loop through packages and assign to packages array +foreach ($older_verions as $version) +{ + phpbb_add_package_file( + $json_data->package, + 'phpBB ' . $version . ' to ' . $current_version . ' Update Package', + 'phpBB-' . $version . '_to_' . $current_version, + 'update', + 'update', + $version + ); +} + +echo(json_encode($json_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n"); + +function phpbb_add_package_file(array &$package_list, string $name, string $file_name, string $type, string $subtype, string $from = '') +{ + if (!file_exists(__DIR__ . '/new_version/release_files/' . $file_name . '.zip')) + { + trigger_error('File does not exist: ' . __DIR__ . '/new_version/release_files/' . $file_name . '.zip'); + return; + } + + $package_file = new stdClass(); + $package_file->name = $name; + $package_file->filename = $file_name; + $package_file->type = $type; + if (!empty($subtype)) + { + $package_file->subtype = $subtype; + } + if (!empty($from)) + { + $package_file->from = $from; + } + $package_file->files = []; + + foreach (['zip', 'tar.bz2'] as $extension) + { + $file_path = 'new_version/release_files/' . $file_name . '.' . $extension; + $filedata = new stdClass(); + $filedata->filesize = filesize($file_path); + $filedata->checksum = trim(preg_replace('/(^\w+)(.+)/', '$1', file_get_contents($file_path . '.sha256'))); + $filedata->filetype = $extension; + $package_file->files[] = $filedata; + } + + $package_list[] = $package_file; +} -- cgit v1.2.3-65-gdbad From d1822e821a1d6a958f2e2eef02b9ab63d805e708 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 19 Sep 2019 21:56:41 +0200 Subject: [ticket/16160] Make script compatible with PHP 5.x PHPBB3-16160 --- build/generate_package_json.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'build') diff --git a/build/generate_package_json.php b/build/generate_package_json.php index ed9341fa14..b880008577 100644 --- a/build/generate_package_json.php +++ b/build/generate_package_json.php @@ -21,14 +21,13 @@ define('IN_PHPBB', true); include_once('../phpBB/includes/functions.php'); $json_data = new \stdClass(); -$json_data->metadata = new class -{ - public $current_version_date; - public $current_version; - public $download_path; - public $show_update_package = true; - public $historic = false; -}; +$json_data->metadata = new stdClass(); + +$json_data->metadata->current_version_date = ''; +$json_data->metadata->current_version = ''; +$json_data->metadata->download_path = ''; +$json_data->metadata->show_update_package = true; +$json_data->metadata->historic = false; $json_data->package = []; @@ -92,7 +91,7 @@ foreach ($older_verions as $version) echo(json_encode($json_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n"); -function phpbb_add_package_file(array &$package_list, string $name, string $file_name, string $type, string $subtype, string $from = '') +function phpbb_add_package_file(array &$package_list, $name, $file_name, $type, $subtype, $from = '') { if (!file_exists(__DIR__ . '/new_version/release_files/' . $file_name . '.zip')) { -- cgit v1.2.3-65-gdbad From 4e285db71a997d3df12edf6cc6d2acd248e68fef Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 21 Sep 2019 07:51:35 +0200 Subject: [ticket/16160] Add missing trailing slash PHPBB3-16160 --- build/generate_package_json.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'build') diff --git a/build/generate_package_json.php b/build/generate_package_json.php index b880008577..152f38958a 100644 --- a/build/generate_package_json.php +++ b/build/generate_package_json.php @@ -51,7 +51,7 @@ usort($older_verions, function($version_a, $version_b) // Set metadata $json_data->metadata->current_version = $current_version; $json_data->metadata->current_version_date = date('Y-m-d'); -$json_data->metadata->download_path = 'https://download.phpbb.com/pub/release/' . preg_replace('#([0-9]+\.[0-9]+)(\..+)#', '$1', $current_version) . '/' . $current_version; +$json_data->metadata->download_path = 'https://download.phpbb.com/pub/release/' . preg_replace('#([0-9]+\.[0-9]+)(\..+)#', '$1', $current_version) . '/' . $current_version . '/'; // Add package, patch files, and changed files phpbb_add_package_file( -- cgit v1.2.3-65-gdbad