xref: /web-php/bin/createReleaseEntry (revision bf7eff4a)
1#!/usr/bin/env php
2<?php
3PHP_SAPI == 'cli' or die("Please run this script using the cli sapi");
4
5require_once __DIR__ . '/../src/autoload.php';
6
7use phpweb\News\Entry;
8
9if (!file_exists(Entry::ARCHIVE_FILE_ABS)) {
10	fwrite(STDERR, "Can't find " . Entry::ARCHIVE_FILE_REL . ", are you sure you are in phpweb/?\n");
11	exit(1);
12}
13
14$opts = getopt('v:r',['security']);
15if (!isset($opts['v'])) {
16	echo "Usage: {$_SERVER['argv'][0]} -v 8.0.8 [ -r ] [ --security ]\n";
17	echo "Create a standard stable-release news entry in archive/entries/\n\n";
18	echo "  -v x.y.z     Version of PHP being announced\n";
19	echo "  -r           Create a matching releases/x_y_z.php file\n";
20	echo "  --security   This is a security release (default: bug fix)\n";
21	exit(0);
22}
23$version = $opts['v'];
24if (!preg_match('/^(\d+)\.(\d+)\.\d+$/', $version, $matches)) {
25	fwrite(STDERR, "Unable to parse version identifier\n");
26	exit(1);
27}
28$major = $matches[1];
29$branch = "{$major}.{$matches[2]}";
30$security = isset($opts['security']) ? 'security' : 'bug fix';
31
32// Create content.
33$template = <<<EOD
34<p>The PHP development team announces the immediate availability of PHP $version. This is a $security release.</p>
35
36<p>All PHP $branch users are encouraged to upgrade to this version.</p>
37
38<p>For source downloads of PHP $version please visit our <a href="https://www.php.net/downloads.php">downloads page</a>,
39Windows source and binaries can be found on <a href="https://windows.php.net/download/">windows.php.net/download/</a>.
40The list of changes is recorded in the <a href="https://www.php.net/ChangeLog-{$major}.php#{$version}">ChangeLog</a>.
41</p>
42EOD;
43
44// Mint the news XML entry.
45$entry = (new Entry)
46	->setTitle("PHP $version Released!")
47	->setCategories(['releases','frontpage'])
48	->setContent($template);
49
50$entry->save()->updateArchiveXML();
51$addedFiles = [Entry::ARCHIVE_ENTRIES_REL . $entry->getId() . '.xml'];
52
53// Mint the releases/x_y_z.php archive.
54const RELEASES_REL = 'releases/';
55const RELEASES_ABS = __DIR__ . '/../' . RELEASES_REL;
56if (isset($opts['r'])) {
57	$release = strtr($version, '.', '_') . '.php';
58	file_put_contents(RELEASES_ABS . $release, "<?php
59\$_SERVER['BASE_PAGE'] = 'releases/$release';
60include_once __DIR__ . '/../include/prepend.inc';
61site_header('PHP $version Release Announcement');
62?>
63<h1>PHP $version Release Announcement</h1>
64
65$template
66<?php site_footer();
67");
68	$addedFiles[] = RELEASES_REL . $release;
69}
70
71echo "News entry created.\n";
72echo "Please sanity check changes to " . Entry::ARCHIVE_FILE_REL . " and add the newly created file(s):\ngit add";
73foreach ($addedFiles as $file) { echo " $file"; }
74echo "\n";
75