2025-12-28 02:28:35 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace NoccyLabs\Composer\PackagePlugin\Command;
|
|
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
use Composer\Command\BaseCommand;
|
2025-12-28 15:26:33 +01:00
|
|
|
use NoccyLabs\Composer\PackagePlugin\Package\PackagePublisher;
|
|
|
|
|
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;
|
2026-01-09 17:07:25 +01:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2025-12-28 02:28:35 +01:00
|
|
|
|
2026-01-09 17:43:54 +01:00
|
|
|
class PackagePublishCommand extends PackageCommand
|
2025-12-28 02:28:35 +01:00
|
|
|
{
|
|
|
|
|
protected function configure(): void
|
|
|
|
|
{
|
|
|
|
|
$this
|
|
|
|
|
->setName('package:publish')
|
2025-12-28 15:26:33 +01:00
|
|
|
->setDescription("Publish a package to a composer package registry")
|
|
|
|
|
->addArgument("registry", InputArgument::OPTIONAL, "The registry to publish to")
|
2026-01-09 17:07:25 +01:00
|
|
|
->addArgument("version", InputArgument::OPTIONAL, "The tag to publish (default is latest tag)")
|
2025-12-28 15:26:33 +01:00
|
|
|
;
|
2025-12-28 02:28:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
|
{
|
2026-01-09 17:43:54 +01:00
|
|
|
$credentials = $this->getCredentialsStore();
|
2025-12-28 15:26:33 +01:00
|
|
|
|
2026-01-09 17:07:25 +01:00
|
|
|
$registry = $input->getArgument("registry");
|
|
|
|
|
$version = $input->getArgument("version");
|
|
|
|
|
|
2025-12-28 15:26:33 +01:00
|
|
|
$providers = [
|
|
|
|
|
'gitea' => new GiteaProvider($credentials)
|
|
|
|
|
];
|
|
|
|
|
|
2026-01-09 17:07:25 +01:00
|
|
|
$factory = new RegistryFactory($providers);
|
|
|
|
|
$publisher = new PackagePublisher($factory, $output);
|
2025-12-28 15:26:33 +01:00
|
|
|
|
2026-01-09 17:07:25 +01:00
|
|
|
$project = ProjectInfo::read(version: $version);
|
2025-12-28 15:26:33 +01:00
|
|
|
|
|
|
|
|
if (!$registry) {
|
|
|
|
|
$output->writeln([
|
|
|
|
|
"Missing registry to publish to. Please specify the registry like this:",
|
|
|
|
|
"",
|
2026-01-09 17:07:25 +01:00
|
|
|
" <info>gitea:{server}</> - to publish to <info>server</> as the default user",
|
|
|
|
|
" <info>gitea:{server}:{owner}</> - to publish to <info>server</> as <info>owner</>",
|
2025-12-28 15:26:33 +01:00
|
|
|
""
|
|
|
|
|
]);
|
|
|
|
|
return self::INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$publisher->publish($project, $registry);
|
|
|
|
|
|
2025-12-28 02:28:35 +01:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|