Skip to content

Commit

Permalink
fix: better process informing; fix regex templates in software registry
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jul 19, 2024
1 parent 265bd28 commit 7ca6b39
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 20 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,11 @@ To download all the configured software, run `dload get` without arguments:
</registry>
</dload>
```

### GitHub Token

To increase the rate limit for GitHub API, you can specify the token in the environment variable `GITHUB_TOKEN`:

```bash
GITHUB_TOKEN=your_token_here ./vendor/bin/dload get
```
2 changes: 2 additions & 0 deletions dload.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
>
<actions>
<download software="rr" version="^2.12.0" />
<download software="dolt" />
<download software="temporal" />
</actions>
<registry overwrite="false">
<software name="RoadRunner" alias="rr"
Expand Down
103 changes: 95 additions & 8 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.25.0@01a8eb06b9e9cc6cfb6a320bf9fb14331919d505">
<file src="src/Command/Base.php">
<LessSpecificReturnStatement>
<code><![CDATA[$config]]></code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType>
<code><![CDATA[non-empty-string|null]]></code>
</MoreSpecificReturnType>
</file>
<file src="src/Command/Get.php">
<ArgumentTypeCoercion>
<code><![CDATA[(string) $software]]></code>
</ArgumentTypeCoercion>
<LessSpecificReturnStatement>
<code><![CDATA[\array_map(
static fn(mixed $software): DownloadConfig => $toDownload[$software]
?? DownloadConfig::fromSoftwareId((string) $software),
$input->getArgument(self::ARG_SOFTWARE),
)]]></code>
</LessSpecificReturnStatement>
<MixedArgument>
<code><![CDATA[$binary]]></code>
<code><![CDATA[$input->getArgument(self::ARG_SOFTWARE)]]></code>
</MixedArgument>
<MixedArrayOffset>
<code><![CDATA[$toDownload[$software]]]></code>
</MixedArrayOffset>
<MixedAssignment>
<code><![CDATA[$binary]]></code>
<code><![CDATA[$argument]]></code>
</MixedAssignment>
<MixedOperand>
<code><![CDATA[$input->getArgument('binary')]]></code>
<code><![CDATA[$input->getOption('path')]]></code>
</MixedOperand>
<MoreSpecificReturnType>
<code><![CDATA[list<DownloadConfig>]]></code>
</MoreSpecificReturnType>
<PropertyNotSetInConstructor>
<code><![CDATA[$container]]></code>
<code><![CDATA[$logger]]></code>
<code><![CDATA[Get]]></code>
<code><![CDATA[Get]]></code>
</PropertyNotSetInConstructor>
<UndefinedThisPropertyAssignment>
<code><![CDATA[$this->cancelling]]></code>
</UndefinedThisPropertyAssignment>
</file>
<file src="src/Command/ListSoftware.php">
<MixedAssignment>
<code><![CDATA[$repo]]></code>
</MixedAssignment>
<MixedPropertyFetch>
<code><![CDATA[$repo->type]]></code>
<code><![CDATA[$repo->uri]]></code>
</MixedPropertyFetch>
<PropertyNotSetInConstructor>
<code><![CDATA[ListSoftware]]></code>
<code><![CDATA[ListSoftware]]></code>
</PropertyNotSetInConstructor>
<RawObjectIteration>
<code><![CDATA[$software->repositories]]></code>
</RawObjectIteration>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$software->homepage]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/DLoad.php">
<ArgumentTypeCoercion>
<code><![CDATA[$conf->pattern]]></code>
</ArgumentTypeCoercion>
<InvalidArgument>
<code><![CDATA[$software->files]]></code>
</InvalidArgument>
</file>
<file src="src/Module/Archive/ArchiveFactory.php">
<MixedPropertyTypeCoercion>
Expand All @@ -34,12 +79,33 @@
<code><![CDATA[\Generator]]></code>
</MoreSpecificReturnType>
</file>
<file src="src/Module/Common/Config/Action/Download.php">
<MissingConstructor>
<code><![CDATA[$software]]></code>
</MissingConstructor>
</file>
<file src="src/Module/Common/Config/Embed/Repository.php">
<MissingConstructor>
<code><![CDATA[$uri]]></code>
</MissingConstructor>
</file>
<file src="src/Module/Common/Config/Embed/Software.php">
<InvalidPropertyAssignmentValue>
<code><![CDATA[[]]]></code>
<code><![CDATA[[]]]></code>
<code><![CDATA[\array_map(
static fn(array $fileArray): File => File::fromArray($fileArray),
$softwareArray['files'] ?? [],
)]]></code>
<code><![CDATA[\array_map(
static fn(array $repositoryArray): Repository => Repository::fromArray($repositoryArray),
$softwareArray['repositories'] ?? [],
)]]></code>
</InvalidPropertyAssignmentValue>
<MismatchingDocblockPropertyType>
<code><![CDATA[array]]></code>
<code><![CDATA[array]]></code>
</MismatchingDocblockPropertyType>
<MissingConstructor>
<code><![CDATA[$name]]></code>
</MissingConstructor>
Expand Down Expand Up @@ -69,17 +135,29 @@
<ArgumentTypeCoercion>
<code><![CDATA[$context->repoConfig->assetPattern]]></code>
</ArgumentTypeCoercion>
<DocblockTypeContradiction>
<code><![CDATA[$repositories === []]]></code>
</DocblockTypeContradiction>
<InternalMethod>
<code><![CDATA[toArray]]></code>
<code><![CDATA[toArray]]></code>
</InternalMethod>
<InvalidArgument>
<code><![CDATA[$repositories]]></code>
</InvalidArgument>
<InvalidNullableReturnType>
<code><![CDATA[AssetInterface]]></code>
<code><![CDATA[ReleaseInterface]]></code>
</InvalidNullableReturnType>
<MissingClosureReturnType>
<code><![CDATA[static fn(int $dlNow, int $dlSize, array $info) => ($context->onProgress)(]]></code>
</MissingClosureReturnType>
<MixedArgument>
<code><![CDATA[$context->repoConfig]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$context->repoConfig]]></code>
</MixedAssignment>
<TooManyArguments>
<code><![CDATA[download]]></code>
</TooManyArguments>
Expand All @@ -92,6 +170,15 @@
<code><![CDATA[$repoConfig]]></code>
</PropertyNotSetInConstructor>
</file>
<file src="src/Module/Downloader/SoftwareCollection.php">
<MixedArgument>
<code><![CDATA[$softwareArray]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$json]]></code>
<code><![CDATA[$softwareArray]]></code>
</MixedAssignment>
</file>
<file src="src/Module/Repository/Collection/ReleasesCollection.php">
<LessSpecificReturnStatement>
<code><![CDATA[\ltrim(\str_replace(
Expand Down
7 changes: 3 additions & 4 deletions resources/software.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@
{
"type": "github",
"uri": "temporalio/cli",
"asset-pattern": "/^temporal-.*/"
"asset-pattern": "/^temporal_cli_.*/"
}
],
"files": [
{
"pattern": "/^temporal-.*/",
"rename": "temporal"
"pattern": "/^(temporal)(?:\\.exe)?$/"
}
]
},
Expand All @@ -51,7 +50,7 @@
],
"files": [
{
"pattern": "/^dolt-.*/"
"pattern": "/^(dolt)(?:\\.exe)?$/"
}
]
}
Expand Down
2 changes: 0 additions & 2 deletions src/Command/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$actionsConfig = $container->get(Actions::class);
$actions = $this->getDownloadActions($input, $actionsConfig);

$output->writeln('Binary to load: ' . \implode(',', $actions));
$output->writeln('Path to store the binary: ' . $input->getOption('path'));
$output->writeln('Architecture: ' . $container->get(Architecture::class)->name);
$output->writeln(' Op. system: ' . $container->get(OperatingSystem::class)->name);
$output->writeln(' Stability: ' . $container->get(Stability::class)->name);
Expand Down
3 changes: 3 additions & 0 deletions src/DLoad.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Internal\DLoad\Module\Downloader\Task\DownloadResult;
use Internal\DLoad\Module\Downloader\Task\DownloadTask;
use Internal\DLoad\Module\Downloader\TaskManager;
use Internal\DLoad\Service\Logger;
use React\Promise\PromiseInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\StyleInterface;
Expand All @@ -30,6 +31,7 @@ final class DLoad
public bool $useMock = false;

public function __construct(
private readonly Logger $logger,
private readonly TaskManager $taskManager,
private readonly SoftwareCollection $softwareCollection,
private readonly Downloader $downloader,
Expand Down Expand Up @@ -85,6 +87,7 @@ private function prepareExtractTask(Software $software): \Closure
$fileInfo = $downloadResult->file;
$archive = $this->archiveFactory->create($fileInfo);
$extractor = $archive->extract();
$this->logger->info('Extracting %s', $fileInfo->getFilename());

while ($extractor->valid()) {
$file = $extractor->current();
Expand Down
13 changes: 9 additions & 4 deletions src/Module/Downloader/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ public function download(
private function processRepository(RepositoryInterface $repository, DownloadContext $context): \Closure
{
return function () use ($repository, $context): ReleaseInterface {
$this->logger->info(
'Loading releases from `%s` repository %s',
$context->repoConfig->type,
$repository->getName(),
);

$releasesCollection = $repository->getReleases()
->minimumStability($this->stability);

Expand All @@ -104,20 +110,19 @@ private function processRepository(RepositoryInterface $repository, DownloadCont
/** @var ReleaseInterface[] $releases */
$releases = $releasesCollection->sortByVersion()->toArray();

td($releases);

$this->logger->debug('%d releases found.', \count($releases));

process_release:
$releases === [] and throw new \RuntimeException('No relevant release found.');
$context->release = \array_shift($releases);

$this->logger->debug('Trying to load release `%s`', $context->release->getName());
$this->logger->info('Loading release `%s`', $context->release->getName());

try {
await(coroutine($this->processRelease($context)));
return $context->release;
} catch (\Throwable $e) {
$this->logger->error('%s', $e->getMessage());
$this->logger->exception($e);
goto process_release;
}
Expand Down Expand Up @@ -164,7 +169,7 @@ private function processAsset(DownloadContext $context): \Closure
$temp = $this->getTempDirectory() . DIRECTORY_SEPARATOR . $context->asset->getName();
$file = new \SplFileObject($temp, 'wb+');

$this->logger->debug('Downloading into ' . $temp);
$this->logger->info('Downloading into %s', $temp);

await(coroutine(
(static function () use ($context, $file): void {
Expand Down
3 changes: 2 additions & 1 deletion src/Module/Downloader/TaskManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function getProcessor(): \Generator

yield $task->resume();
} catch (\Throwable $e) {
$this->logger->error($e->getMessage());
$this->logger->exception($e);
unset($this->tasks[$key]);
yield $e;
Expand All @@ -55,7 +56,7 @@ public function await(): void
$processor = $this->getProcessor();
$processor->current();
while ($processor->valid()) {
$processor->send(null);
$processor->next();
}
}
}
2 changes: 1 addition & 1 deletion src/Service/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function status(string $sender, string $message, string|int|float|bool ..

public function info(string $message, string|int|float|bool ...$values): void
{
$this->echo("\033[32m" . \sprintf($message, ...$values) . "\033[0m\n", !$this->verbose);
$this->echo("\033[32m" . \sprintf($message, ...$values) . "\033[0m\n", false);
}

public function debug(string $message, string|int|float|bool ...$values): void
Expand Down

0 comments on commit 7ca6b39

Please sign in to comment.