Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion other/Updaters/AsciiTransliteratorDataUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,23 @@
*/
class AsciiTransliteratorDataUpdater extends UpdaterBase
{
/*******************
* Public properties
*******************/

/**
*
*/
public string $commit_msg = 'Updates AsciiTransliterator data';

/****************
* Public methods
****************/

/**
* Constructor.
*/
public function __construct(string $new_branch)
public function __construct(?string $new_branch = null)
{
parent::__construct($new_branch);

Expand Down Expand Up @@ -138,6 +147,8 @@ public function execute(): void
echo 'Done.', !$this->hasChanged() ? ' No changes were made.' : '', PHP_EOL;
}

$this->ready_to_commit = true;

$this->removeUselessBranch();
}
}
26 changes: 20 additions & 6 deletions other/Updaters/TimezoneDataUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ class TimezoneDataUpdater extends UpdaterBase
* Public properties
*******************/

/**
*
*/
public string $commit_msg = 'Updates time zone data';

/**
* Git commit hash associated with TZDB_PREV_TAG.
*/
Expand Down Expand Up @@ -202,6 +207,9 @@ public function execute()

$this->checkoutNewBranch();

// Assume true until proven otherwise.
$this->ready_to_commit = true;

$this->fetchTzdbUpdates();
$this->updateTimezoneClass();
$this->updateTimezonesLangfile();
Expand All @@ -212,16 +220,12 @@ public function execute()
if (!empty($this->tz_data['changed']['wtf'])) {
$wtf_message = 'The following time zones changed in unexpected ways. Please review them manually to figure out what to do.' . PHP_EOL . "\t" . implode(PHP_EOL . "\t", $this->tz_data['changed']['wtf']) . PHP_EOL . PHP_EOL;

if (php_sapi_name() === 'cli') {
echo $wtf_message;
} else {
throw new \Exception($wtf_message);
}
throw new \Exception($wtf_message);
}

// Say something when finished.
if (php_sapi_name() === 'cli') {
echo 'Done. ', $this->files_updated ? 'Please review all changes manually.' : 'No changes were made.', PHP_EOL;
echo 'Done.', !$this->files_updated ? ' No changes were made.' : (!$this->ready_to_commit ? ' Please review all changes manually.' : ''), PHP_EOL;
}

$this->removeUselessBranch();
Expand Down Expand Up @@ -427,6 +431,7 @@ private function updateTimezoneClass(): void
if (preg_match('~' . $search_for . '~', $file_contents)) {
echo "Added fallback code for {$tzid} in TimeZone::\$fallbacks.\nACTION NEEDED: Review the fallback code for {$tzid}.\n\n";

$this->ready_to_commit = false;
$this->files_updated = true;
}
}
Expand Down Expand Up @@ -506,6 +511,10 @@ private function updateTimezoneClass(): void
$final_entry = preg_replace('~//\s*OPTIONS[^\n]+\n\h*~', $new_alt_tzid_comment, $final_entry);
}

if (str_contains($final_entry, 'OPTIONS')) {
$this->ready_to_commit = false;
}

$final_entries[] = $final_entry;

continue 2;
Expand All @@ -527,6 +536,7 @@ private function updateTimezoneClass(): void
$final_code = str_replace($existing_inner, $final_inner, $existing_code);
$file_contents = str_replace($existing_code, $final_code, $file_contents);

$this->ready_to_commit = false;
$this->files_updated = true;

echo "Fallback code for {$tzid} has been updated in TimeZone::\$fallbacks.\nACTION NEEDED: Review the fallback code for {$tzid}.\n\n";
Expand Down Expand Up @@ -861,6 +871,7 @@ function (&$zone) {
echo "Created new metazone for {$tzid} in TimeZone::\$metazones.\n";
echo "ACTION NEEDED: Review the automatically generated \$tztxt key, '" . $metazone['tztxt_key'] . "'.\n\n";

$this->ready_to_commit = false;
$this->files_updated = true;

if (\count($added) === \count($this->new_metazones)) {
Expand Down Expand Up @@ -932,6 +943,7 @@ private function updateTimezonesLangfile(): void
echo "Added \$tztxt['{$metazone['tztxt_key']}'] to Languages/en_US/Timezones.php.\n";
echo "ACTION NEEDED: Review the metazone label text, '{$label}'.\n\n";

$this->ready_to_commit = false;
$this->files_updated = true;
}

Expand Down Expand Up @@ -1266,6 +1278,8 @@ private function getTzidLabel(string $tzid): array
$label = str_replace(['St_', '_'], ['St. ', ' '], substr($tzid, strrpos($tzid, '/') + 1));

$msg = "ACTION NEEDED: Check that the label is spelled correctly, etc.\n";

$this->ready_to_commit = false;
}

return [$label, $msg];
Expand Down
11 changes: 11 additions & 0 deletions other/Updaters/UnicodeDataUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
*/
class UnicodeDataUpdater extends UpdaterBase
{
/*******************
* Public properties
*******************/

/**
*
*/
public string $commit_msg = 'Updates Unicode data';

/****************
* Public methods
****************/
Expand All @@ -62,6 +71,8 @@ public function execute(): void
echo 'Done.', !$this->hasChanged() ? ' No changes were made.' : '', PHP_EOL;
}

$this->ready_to_commit = true;

$this->removeUselessBranch();
}
}
66 changes: 53 additions & 13 deletions other/Updaters/UpdaterBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,25 @@ abstract class UpdaterBase
*******************/

/**
* @var string
* @var ?string
*
* The name of a new Git branch to hold the changes.
*/
public string $new_branch;
public ?string $new_branch;

/**
* @var bool
*
* Whether the changes are ready to be committed.
*/
public bool $ready_to_commit = false;

/**
* @var string
*
* Commit message to use if changes are committed.
*/
public string $commit_msg;

/**************************
* Public static properties
Expand Down Expand Up @@ -80,7 +94,7 @@ abstract class UpdaterBase
*
* @param string $new_branch Name of a new Git branch to hold the changes.
*/
public function __construct(string $new_branch)
public function __construct(?string $new_branch = null)
{
// Set the name of our new Git branch.
$this->new_branch = $new_branch;
Expand Down Expand Up @@ -177,6 +191,10 @@ public function __construct(string $new_branch)
*/
public function checkoutNewBranch(): void
{
if (empty($this->new_branch)) {
return;
}

// Are we already on the new branch?
if (trim(shell_exec('git rev-parse --abbrev-ref HEAD')) === $this->new_branch) {
return;
Expand Down Expand Up @@ -215,19 +233,21 @@ public function checkoutNewBranch(): void
*/
public function hasChanged(): bool
{
// Are there any committed changes?
$new_branch_hash = trim(shell_exec('git rev-parse "' . $this->new_branch . '"'));
$main_branch_hash = trim(shell_exec('git rev-parse "' . self::MAIN_BRANCH . '"'));
if (!empty($this->new_branch)) {
// Are there any committed changes?
$new_branch_hash = trim(shell_exec('git rev-parse "' . $this->new_branch . '"'));
$main_branch_hash = trim(shell_exec('git rev-parse "' . self::MAIN_BRANCH . '"'));

if ($new_branch_hash !== $main_branch_hash) {
return true;
}
if ($new_branch_hash !== $main_branch_hash) {
return true;
}

// Are we currently on the new branch?
$current_branch = trim(shell_exec('git rev-parse --abbrev-ref HEAD'));
// Are we currently on the new branch?
$current_branch = trim(shell_exec('git rev-parse --abbrev-ref HEAD'));

if ($current_branch !== $this->new_branch) {
throw new \Exception('Could not continue. Wrong branch checked out.');
if ($current_branch !== $this->new_branch) {
throw new \Exception('Could not continue. Wrong branch checked out.');
}
}

// Are there any uncommitted changes?
Expand All @@ -239,6 +259,10 @@ public function hasChanged(): bool
*/
public function removeUselessBranch(): void
{
if (empty($this->new_branch)) {
return;
}

// Never delete the main branch!
if ($this->new_branch === self::MAIN_BRANCH) {
return;
Expand All @@ -254,4 +278,20 @@ public function removeUselessBranch(): void
shell_exec('git branch -d "' . $this->new_branch . '"');
}
}

/**
* Checks whether there are changes ready to commit and if so commits them.
*
* @return bool Whether a commit was made.
*/
public function commit(): bool
{
if (!$this->ready_to_commit || empty($this->commit_msg) || !$this->hasChanged()) {
return false;
}

exec("git commit -a -s -m '{$this->commit_msg}'", $output, $result_code);

return ($result_code == 0);
}
}
31 changes: 31 additions & 0 deletions other/Updaters/VersionNumberUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class VersionNumberUpdater extends UpdaterBase
* Public properties
*******************/

/**
*
*/
public string $commit_msg = 'Updates version numbers, etc.';

/**
* @var string
*
Expand Down Expand Up @@ -146,9 +151,35 @@ public function execute(?string $new_version = null): void
echo 'Done.', !$this->hasChanged() ? ' No changes were made.' : '', PHP_EOL;
}

$this->ready_to_commit = true;

$this->removeUselessBranch();
}

/**
* Gets a suitable string for a new Git tag based on $this->new_version.
*/
public function getNewTag(): string
{
return 'v' . preg_replace(
[
'/(\d)([A-Za-z])/',
'/([A-Za-z])(\d)/',
'/\s+/',
'/\s(?=[A-Za-z])/',
'/\s/',
],
[
'$1 $2',
'$1 $2',
' ',
'-',
'.',
],
strtolower($this->new_version),
);
}

/******************
* Internal methods
******************/
Expand Down
43 changes: 34 additions & 9 deletions other/prepare_release.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@

require_once 'Updaters/UpdaterBase.php';

foreach (
[
'UnicodeDataUpdater',
'AsciiTransliteratorDataUpdater',
'TimezoneDataUpdater',
'VersionNumberUpdater',
]
as $class_name
) {
$updaters = [
'TimezoneDataUpdater',
'UnicodeDataUpdater',
'AsciiTransliteratorDataUpdater',
'VersionNumberUpdater',
];

$num_updaters_executed = 0;

foreach ($updaters as $class_name) {
$file_name = 'Updaters/' . $class_name . '.php';
$fully_qualified_class_name = __NAMESPACE__ . '\\Updaters\\' . $class_name;

Expand All @@ -52,7 +53,31 @@

if ($class_name === 'VersionNumberUpdater') {
$updater->execute($argv[1] ?? null);
$new_tag = $updater->getNewTag();
} else {
$updater->execute();
}

$num_updaters_executed++;

if (!$updater->hasChanged()) {
continue;
}

if (!$updater->ready_to_commit) {
echo 'Changes are not ready to commit. Deal with them manually and commit them, then run this script again.' . PHP_EOL;

// Don't execute subsequent updaters until these changes are dealt with.
// This ensures that the version number updater and manifest updater
// don't end up working with bad data.
break;
}

if ($updater->commit()) {
echo 'Changes committed.' . PHP_EOL;
}
}

if ($num_updaters_executed === \count($updaters) && !empty($new_tag)) {
echo "You may now tag the new release using `git tag '{$new_tag}'`." . PHP_EOL;
}
8 changes: 8 additions & 0 deletions other/update_asciitransliterator_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@

$updater = new Updaters\AsciiTransliteratorDataUpdater('update_asciitransliterator_data');
$updater->execute();

if ($updater->hasChanged()) {
if (!$updater->ready_to_commit) {
echo 'Changes are not ready to commit. Deal with them manually.' . PHP_EOL;
} elseif ($updater->commit()) {
echo 'Changes committed.' . PHP_EOL;
}
}
8 changes: 8 additions & 0 deletions other/update_timezones.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@

$updater = new Updaters\TimezoneDataUpdater('update_timezones');
$updater->execute();

if ($updater->hasChanged()) {
if (!$updater->ready_to_commit) {
echo 'Changes are not ready to commit. Deal with them manually.' . PHP_EOL;
} elseif ($updater->commit()) {
echo 'Changes committed.' . PHP_EOL;
}
}
Loading
Loading