Add support for building specific version
* Improve version resolution logic. * Allow providing a specific version when building package.
This commit is contained in:
@@ -11,6 +11,7 @@ use NoccyLabs\Composer\PackagePlugin\Project\ProjectInfo;
|
||||
use NoccyLabs\Composer\PackagePlugin\Registry\Credentials\InsecureStore;
|
||||
use NoccyLabs\Composer\PackagePlugin\Registry\Gitea\GiteaProvider;
|
||||
use NoccyLabs\Composer\PackagePlugin\Registry\RegistryFactory;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class PackageBuildCommand extends BaseCommand
|
||||
@@ -25,6 +26,7 @@ class PackageBuildCommand extends BaseCommand
|
||||
->addOption("rm", null, InputOption::VALUE_NONE, "With --publish: remove the .zip after publishing")
|
||||
->addOption("dirty", null, InputOption::VALUE_NONE, "Build directly from source without cloning")
|
||||
->addOption("force", null, InputOption::VALUE_NONE, "Build even if the output file already exists")
|
||||
->addArgument("version", InputArgument::OPTIONAL, "The tag to build (default is latest tag)")
|
||||
;
|
||||
}
|
||||
|
||||
@@ -34,7 +36,9 @@ class PackageBuildCommand extends BaseCommand
|
||||
|
||||
$builder = new PackageBuilder($output);
|
||||
|
||||
$project = ProjectInfo::read();
|
||||
$version = $input->getArgument("version");
|
||||
|
||||
$project = ProjectInfo::read(version:$version);
|
||||
|
||||
if ($registry && file_exists($project->filename) && !$input->getOption("force")) {
|
||||
$output->writeln("<fg=black;bg=yellow>Package file already exists. Pass --force to rebuild it.</>");
|
||||
|
||||
@@ -6,25 +6,36 @@ class ProjectInfo
|
||||
{
|
||||
private static ?ProjectInfo $project = null;
|
||||
|
||||
public static function read(): ProjectInfo
|
||||
public static function read(?string $version = null): ProjectInfo
|
||||
{
|
||||
return self::$project
|
||||
? self::$project
|
||||
: (self::$project = self::readProject());
|
||||
: (self::$project = self::readProject(version: $version));
|
||||
}
|
||||
|
||||
private static function readProject(?string $path = null): ProjectInfo
|
||||
private static function readProject(?string $path = null, ?string $version = null): ProjectInfo
|
||||
{
|
||||
$path ??= getcwd();
|
||||
|
||||
if (!file_exists($path."/composer.json")) {
|
||||
throw new \Exception("No composer project found in {$path}");
|
||||
}
|
||||
|
||||
$json = file_get_contents($path."/composer.json");
|
||||
$manifest = json_decode($json);
|
||||
|
||||
if (file_exists($path."/.git")) {
|
||||
$version = trim(exec("git describe --tags 2>/dev/null")) ?: null;
|
||||
if (!file_exists($path."/.git")) {
|
||||
throw new \Exception("Project is not under git version control");
|
||||
}
|
||||
|
||||
if (!$version) {
|
||||
$version = $manifest->version ?? "1.0.0";
|
||||
$gitVersion = trim(exec("git describe --tags 2>/dev/null")) ?: null;
|
||||
$version = $gitVersion ?? ($manifest->version ?? "1.0.0");
|
||||
} else {
|
||||
exec("git tag 2>/dev/null", $tags, $ret);
|
||||
if (!in_array($version, $tags)) {
|
||||
throw new \Exception("Unable to find version {$version} in the list of git tags");
|
||||
}
|
||||
}
|
||||
|
||||
$packageName = $manifest->name;
|
||||
|
||||
Reference in New Issue
Block a user