aboutsummaryrefslogtreecommitdiffstats
path: root/build/generate_package_json.php
blob: 152f38958a81d7a6f08c79e4520adc2439878fac (plain)
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
#!/usr/bin/env php
<?php
/**
 *
 * This file is part of the phpBB Forum Software package.
 *
 * @copyright (c) phpBB Limited <https://www.phpbb.com>
 * @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 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 = [];

// 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, $name, $file_name, $type, $subtype, $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;
}