Skip to content

Commit 2d647a0

Browse files
author
Michael Babker
committed
Add script to handle release tasks
1 parent 9441b01 commit 2d647a0

File tree

2 files changed

+123
-1
lines changed

2 files changed

+123
-1
lines changed

administrator/components/com_patchtester/patchtester.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<license>GNU General Public License version 2 or later</license>
88
<authorEmail>admin@joomla.org</authorEmail>
99
<authorUrl>https://www.joomla.org</authorUrl>
10-
<version>3.0.0.dev</version>
10+
<version>3.0.0-dev</version>
1111
<description>COM_PATCHTESTER_XML_DESCRIPTION</description>
1212
<scriptfile>script.php</scriptfile>
1313
<install>

build/patchtester/release.php

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/**
4+
* Script used to prepare a patchtester release
5+
*
6+
* This script will:
7+
*
8+
* - Replace `__DEPLOY_VERSION__` markers with the version
9+
* - Update the version number in the component manifest
10+
* - Update the version in the update server manifest
11+
*
12+
* Usage: php build/patchtester/release.php -v <version> --exclude-manifest
13+
*
14+
* Examples:
15+
* - php build/patchtester/release.php -v 3.0.0
16+
* - php build/patchtester/release.php -v 3.0.1-dev --exclude-manifest
17+
*
18+
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2016 Open Source Matters, Inc. All rights reserved.
19+
* @license GNU General Public License version 2 or later
20+
*/
21+
22+
// Constants.
23+
const PHP_TAB = "\t";
24+
25+
// Functions.
26+
function usage($command)
27+
{
28+
echo PHP_EOL;
29+
echo 'Usage: php ' . $command . ' [options]' . PHP_EOL;
30+
echo PHP_TAB . '[options]:'.PHP_EOL;
31+
echo PHP_TAB . PHP_TAB . '-v <version>:' . PHP_TAB . 'Version (ex: 3.0.0, 3.0.1-dev)' . PHP_EOL;
32+
echo PHP_TAB . PHP_TAB . '--exclude-manifest: Exclude updating the update server manifest';
33+
echo PHP_EOL;
34+
}
35+
36+
$manifestFile = '/administrator/components/com_patchtester/patchtester.xml';
37+
$updateServerFile = '/manifest.xml';
38+
39+
// Check arguments (exit if incorrect cli arguments).
40+
$opts = getopt('v:', array('exclude-manifest'));
41+
42+
if (empty($opts['v']))
43+
{
44+
usage($argv[0]);
45+
die();
46+
}
47+
48+
// Check version string (exit if not correct).
49+
$versionParts = explode('-', $opts['v']);
50+
51+
if (!preg_match('#^[0-9]+\.[0-9]+\.[0-9]+$#', $versionParts[0]))
52+
{
53+
usage($argv[0]);
54+
die();
55+
}
56+
57+
if (isset($versionParts[1]) && !preg_match('#(dev|alpha|beta|rc)[0-9]*#', $versionParts[1]))
58+
{
59+
usage($argv[0]);
60+
die();
61+
}
62+
63+
if (isset($versionParts[2]) && $versionParts[2] !== 'dev')
64+
{
65+
usage($argv[0]);
66+
die();
67+
}
68+
69+
// Make sure we use the correct language and timezone.
70+
setlocale(LC_ALL, 'en_GB');
71+
date_default_timezone_set('Europe/London');
72+
73+
// Make sure file and folder permissions are set correctly.
74+
umask(022);
75+
76+
// Set version properties.
77+
$versionSubParts = explode('.', $versionParts[0]);
78+
79+
$version = array(
80+
'main' => $versionSubParts[0] . '.' . $versionSubParts[1],
81+
'release' => $versionSubParts[0] . '.' . $versionSubParts[1] . '.' . $versionSubParts[2],
82+
'dev_devel' => $versionSubParts[2] . (!empty($versionParts[1]) ? '-' . $versionParts[1] : '') . (!empty($versionParts[2]) ? '-' . $versionParts[2] : ''),
83+
'credate' => date('d-F-Y'),
84+
);
85+
86+
// Prints version information.
87+
echo PHP_EOL;
88+
echo 'Version data:'. PHP_EOL;
89+
echo '- Main:' . PHP_TAB . PHP_TAB . PHP_TAB . $version['main'] . PHP_EOL;
90+
echo '- Release:' . PHP_TAB . PHP_TAB . $version['release'] . PHP_EOL;
91+
echo '- Full:' . PHP_TAB . PHP_TAB . PHP_TAB . $version['main'] . '.' . $version['dev_devel'] . PHP_EOL;
92+
echo '- Dev Level:' . PHP_TAB . PHP_TAB . $version['dev_devel'] . PHP_EOL;
93+
echo '- Creation date:' . PHP_TAB . $version['credate'] . PHP_EOL;
94+
echo PHP_EOL;
95+
96+
$rootPath = dirname(dirname(__DIR__));
97+
98+
// Updates the version and creation date in the component manifest file.
99+
if (file_exists($rootPath . $manifestFile))
100+
{
101+
$fileContents = file_get_contents($rootPath . $manifestFile);
102+
$fileContents = preg_replace('#<version>[^<]*</version>#', '<version>' . $version['main'] . '.' . $version['dev_devel'] . '</version>', $fileContents);
103+
$fileContents = preg_replace('#<creationDate>[^<]*</creationDate>#', '<creationDate>' . $version['credate'] . '</creationDate>', $fileContents);
104+
file_put_contents($rootPath . $manifestFile, $fileContents);
105+
}
106+
107+
// Replaces the `__DEPLOY_VERSION__` marker with the "release" version number
108+
system('cd ' . $rootPath . ' && find administrator -name "*.php" -type f -exec sed -i "" "s/__DEPLOY_VERSION__/' . $version['release'] . '/g" "{}" \;');
109+
110+
// If not instructed to exclude it, update the update server's manifest
111+
if (!isset($opts['exclude-manifest']))
112+
{
113+
if (file_exists($rootPath . $updateServerFile))
114+
{
115+
$fileContents = file_get_contents($rootPath . $updateServerFile);
116+
$fileContents = preg_replace('#<infourl title="Patch Tester Component">[^<]*</infourl>#', '<infourl title="Patch Tester Component">https://github.com/joomla-extensions/patchtester/releases/tag/' . $version['release'] . '</infourl>', $fileContents);
117+
$fileContents = preg_replace('#<downloadurl type="full" format="zip">[^<]*</downloadurl>#', '<downloadurl type="full" format="zip">https://github.com/joomla-extensions/patchtester/releases/download/' . $version['release'] . '/com_patchtester.zip</downloadurl>', $fileContents);
118+
file_put_contents($rootPath . $updateServerFile, $fileContents);
119+
}
120+
}
121+
122+
echo 'Version bump complete!' . PHP_EOL;

0 commit comments

Comments
 (0)