| 1 |
#!/usr/bin/env php |
|---|
| 2 |
<?php |
|---|
| 3 |
/** |
|---|
| 4 |
* |
|---|
| 5 |
* Solar release script. |
|---|
| 6 |
* |
|---|
| 7 |
* Automates the release process, all but for the package upload and |
|---|
| 8 |
* website update. |
|---|
| 9 |
* |
|---|
| 10 |
* @author Clay Loveless |
|---|
| 11 |
* |
|---|
| 12 |
* @author Paul M. Jones |
|---|
| 13 |
* |
|---|
| 14 |
* @license http://opensource.org/licenses/bsd-license.php BSD |
|---|
| 15 |
* |
|---|
| 16 |
*/ |
|---|
| 17 |
|
|---|
| 18 |
/** |
|---|
| 19 |
* |
|---|
| 20 |
* Prints, then executes a shell command with passthru(). |
|---|
| 21 |
* |
|---|
| 22 |
* @param string $cmd The shell command to execute. |
|---|
| 23 |
* |
|---|
| 24 |
* @return void |
|---|
| 25 |
* |
|---|
| 26 |
*/ |
|---|
| 27 |
function solar_passthru($cmd) |
|---|
| 28 |
{ |
|---|
| 29 |
echo "\$ $cmd\n"; |
|---|
| 30 |
passthru($cmd, $status); |
|---|
| 31 |
return $status; |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
/** |
|---|
| 35 |
* |
|---|
| 36 |
* Prints, then executes a shell command with exec(). |
|---|
| 37 |
* |
|---|
| 38 |
* @param string $cmd The shell command to execute. |
|---|
| 39 |
* |
|---|
| 40 |
* @param array &$output This array is cleared and then filled with |
|---|
| 41 |
* output lines. |
|---|
| 42 |
* |
|---|
| 43 |
* @return string The last line of the output. |
|---|
| 44 |
* |
|---|
| 45 |
*/ |
|---|
| 46 |
function solar_exec($cmd, &$output) |
|---|
| 47 |
{ |
|---|
| 48 |
$output = null; |
|---|
| 49 |
echo "\$ $cmd\n"; |
|---|
| 50 |
return exec($cmd, $output); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
// remove previous release files, if any |
|---|
| 54 |
solar_passthru("rm trunk/*.xml"); |
|---|
| 55 |
solar_passthru("rm trunk/*.tgz"); |
|---|
| 56 |
|
|---|
| 57 |
// clean dotfiles |
|---|
| 58 |
solar_passthru('php clean.php'); |
|---|
| 59 |
|
|---|
| 60 |
// update keywords |
|---|
| 61 |
solar_passthru('php keywords.php'); |
|---|
| 62 |
|
|---|
| 63 |
// make sure relevant files are up-to-date |
|---|
| 64 |
$result = solar_exec('svn status info/ trunk/', $output); |
|---|
| 65 |
if (trim($result) != '') { |
|---|
| 66 |
echo implode("\n", $output) . "\n"; |
|---|
| 67 |
echo "Info and/or trunk not up-to-date. Please handle outstanding issues.\n"; |
|---|
| 68 |
exit(1); |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
// // make sure all tests pass |
|---|
| 72 |
// $result = solar_exec('cd trunk/tests/; ./phpunit AllTests.php', $output); |
|---|
| 73 |
// if (in_array("FAILURES!", $output)) { |
|---|
| 74 |
// echo implode("\n", $output) . "\n"; |
|---|
| 75 |
// echo "\nAt least one test failed. Please run tests manually and resolve.\n"; |
|---|
| 76 |
// exit(1); |
|---|
| 77 |
// } |
|---|
| 78 |
|
|---|
| 79 |
// // generate docs |
|---|
| 80 |
// solar_passthru('/Users/pmjones/Sites/dev/solarweb/make-docs.sh'); |
|---|
| 81 |
|
|---|
| 82 |
// whether or not we're doing a full commit |
|---|
| 83 |
$commit = isset($argv[1]) && $argv[1] == 'commit'; |
|---|
| 84 |
|
|---|
| 85 |
// --------------------------------------------------------------------- |
|---|
| 86 |
// |
|---|
| 87 |
// RELEASE INFORMATION |
|---|
| 88 |
// |
|---|
| 89 |
|
|---|
| 90 |
// get all files in the info directory, reverse-sorted |
|---|
| 91 |
$dir = dirname(__FILE__) . '/info'; |
|---|
| 92 |
$list = scandir($dir, 1); |
|---|
| 93 |
|
|---|
| 94 |
// grab number for most-recent version and set directory |
|---|
| 95 |
$version = '0.0.0'; |
|---|
| 96 |
foreach ($list as $val) { |
|---|
| 97 |
if (version_compare($val, $version, ">")) { |
|---|
| 98 |
$version = $val; |
|---|
| 99 |
} |
|---|
| 100 |
} |
|---|
| 101 |
$dir .= "/$version"; |
|---|
| 102 |
|
|---|
| 103 |
// get release-specific info |
|---|
| 104 |
$stability = file_get_contents("$dir/stability"); |
|---|
| 105 |
$summary = file_get_contents("$dir/summary"); |
|---|
| 106 |
$descr = file_get_contents("$dir/description"); |
|---|
| 107 |
$notes = file_get_contents("$dir/notes"); |
|---|
| 108 |
|
|---|
| 109 |
// get maintainers |
|---|
| 110 |
$list = file("$dir/maintainers"); |
|---|
| 111 |
$maintainers = array(); |
|---|
| 112 |
foreach ($list as $data) { |
|---|
| 113 |
|
|---|
| 114 |
// ignore blank lines |
|---|
| 115 |
if (trim($data) == '') { |
|---|
| 116 |
continue; |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
$person = explode(',', trim($data)); |
|---|
| 120 |
array_walk($person, 'trim'); |
|---|
| 121 |
$maintainers[] = $person; |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
// --------------------------------------------------------------------- |
|---|
| 126 |
// |
|---|
| 127 |
// BUILD THE PACKAGE |
|---|
| 128 |
// |
|---|
| 129 |
|
|---|
| 130 |
require_once 'PEAR/PackageFileManager2.php'; |
|---|
| 131 |
PEAR::setErrorHandling(PEAR_ERROR_PRINT); |
|---|
| 132 |
$pkg = new PEAR_PackageFileManager2; |
|---|
| 133 |
|
|---|
| 134 |
$opts = array( |
|---|
| 135 |
'baseinstalldir' => '/', |
|---|
| 136 |
'packagefile' => 'package2.xml', |
|---|
| 137 |
'packagedirectory' => dirname(__FILE__) . '/trunk/', |
|---|
| 138 |
'filelistgenerator' => 'file', |
|---|
| 139 |
'roles' => array( |
|---|
| 140 |
'*' => 'php', |
|---|
| 141 |
), |
|---|
| 142 |
'exceptions' => array( |
|---|
| 143 |
'tests/*' => 'test', |
|---|
| 144 |
'docs/*' => 'doc', |
|---|
| 145 |
), |
|---|
| 146 |
); |
|---|
| 147 |
|
|---|
| 148 |
$e = $pkg->setOptions($opts); |
|---|
| 149 |
|
|---|
| 150 |
$pkg->setPackage('Solar'); |
|---|
| 151 |
$pkg->setSummary($summary); |
|---|
| 152 |
$pkg->setDescription($descr); |
|---|
| 153 |
|
|---|
| 154 |
foreach ($maintainers as $person) { |
|---|
| 155 |
$result = call_user_func_array( |
|---|
| 156 |
array($pkg, 'addMaintainer'), |
|---|
| 157 |
$person |
|---|
| 158 |
); |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
$pkg->setChannel('solarphp.com'); |
|---|
| 162 |
$pkg->setAPIVersion($version); |
|---|
| 163 |
$pkg->setReleaseVersion($version); |
|---|
| 164 |
$pkg->setReleaseStability($stability); |
|---|
| 165 |
$pkg->setAPIStability($stability); |
|---|
| 166 |
$pkg->setPackageType('php'); |
|---|
| 167 |
$pkg->addRelease(); |
|---|
| 168 |
$pkg->setNotes($notes); |
|---|
| 169 |
$pkg->setPhpDep('5.2.0'); |
|---|
| 170 |
$pkg->setPearinstallerDep('1.4.6'); |
|---|
| 171 |
$pkg->setLicense('BSD', 'http://www.opensource.org/licenses/bsd-license.php'); |
|---|
| 172 |
|
|---|
| 173 |
$pkg->addGlobalReplacement('package-info', '@package_version@', 'version'); |
|---|
| 174 |
$pkg->addGlobalReplacement('package-info', '@package_date@', 'date'); |
|---|
| 175 |
|
|---|
| 176 |
// 0 => 'name', |
|---|
| 177 |
// 1 => 'summary', |
|---|
| 178 |
// 2 => 'channel', |
|---|
| 179 |
// 3 => 'notes', |
|---|
| 180 |
// 4 => 'extends', |
|---|
| 181 |
// 5 => 'description', |
|---|
| 182 |
// 6 => 'release_notes', |
|---|
| 183 |
// 7 => 'license', |
|---|
| 184 |
// 8 => 'release-license', |
|---|
| 185 |
// 9 => 'license-uri', |
|---|
| 186 |
// 10 => 'version', |
|---|
| 187 |
// 11 => 'api-version', |
|---|
| 188 |
// 12 => 'state', |
|---|
| 189 |
// 13 => 'api-state', |
|---|
| 190 |
// 14 => 'release_date', |
|---|
| 191 |
// 15 => 'date', |
|---|
| 192 |
// 16 => 'time', |
|---|
| 193 |
|
|---|
| 194 |
$pkg->generateContents(); |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
// write the package file |
|---|
| 198 |
echo "\nWrite package file...\n"; |
|---|
| 199 |
$compat =& $pkg->exportCompatiblePackageFile1(); |
|---|
| 200 |
$compat->writePackageFile(); |
|---|
| 201 |
$pkg->writePackageFile(); |
|---|
| 202 |
|
|---|
| 203 |
// create the package. |
|---|
| 204 |
// creates package.xml, package2.xml, and the .tgz file |
|---|
| 205 |
solar_passthru('cd trunk; pear package'); |
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
// --------------------------------------------------------------------- |
|---|
| 209 |
// |
|---|
| 210 |
// COMMIT THE RELEASE |
|---|
| 211 |
// |
|---|
| 212 |
|
|---|
| 213 |
if (! $commit) { |
|---|
| 214 |
// not committing the release, so we're done |
|---|
| 215 |
echo "Flag for 'commit' not specified; release process complete.\n"; |
|---|
| 216 |
exit(0); |
|---|
| 217 |
} |
|---|
| 218 |
|
|---|
| 219 |
// copy trunk to tags/release-x.y.z |
|---|
| 220 |
// and commit with release message |
|---|
| 221 |
solar_passthru("svn copy trunk tags/release-$version"); |
|---|
| 222 |
solar_passthru("svn add tags/release-$version/*"); |
|---|
| 223 |
solar_passthru("svn commit -m \"tagged release $version\" tags/release-$version"); |
|---|
| 224 |
|
|---|
| 225 |
echo "Done.\n"; |
|---|
| 226 |
exit(0); |
|---|