46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
/**
|
|
* Pure semver arithmetic for the Release page: given the current version, what rc-target versions
|
|
* may the operator cut? The dashboard computes the target X.Y.Z; the host bridge computes -rcN.
|
|
*/
|
|
class ReleasePlanner
|
|
{
|
|
/**
|
|
* Proposed target versions (bare X.Y.Z) for the current version. A release candidate also offers
|
|
* continuing its own base (another release candidate of the same target).
|
|
*
|
|
* @return array{patch:string, minor:string, major:string, continueRc?:string}
|
|
*/
|
|
public function proposedTargets(string $current): array
|
|
{
|
|
$current = ltrim($current, 'vV');
|
|
$base = preg_replace('/-.*$/', '', $current);
|
|
[$maj, $min, $pat] = array_map('intval', array_pad(explode('.', (string) $base), 3, '0'));
|
|
|
|
$targets = [
|
|
'patch' => "{$maj}.{$min}.".($pat + 1),
|
|
'minor' => "{$maj}.".($min + 1).'.0',
|
|
'major' => ($maj + 1).'.0.0',
|
|
];
|
|
|
|
if (str_contains($current, '-rc')) {
|
|
$targets['continueRc'] = "{$maj}.{$min}.{$pat}";
|
|
}
|
|
|
|
return $targets;
|
|
}
|
|
|
|
/**
|
|
* The flat list of allowed target versions — the server-side allow-list for a posted target.
|
|
*
|
|
* @return array<int,string>
|
|
*/
|
|
public function allowedTargets(string $current): array
|
|
{
|
|
return array_values($this->proposedTargets($current));
|
|
}
|
|
}
|