Skip to content

Commit

Permalink
feat(documentator): requirements command will dump requirements for…
Browse files Browse the repository at this point in the history
… `Metadata { version }` equal to `HEAD` even if no git tag.

It is required for rebuilding documentation while release. The `release-it` tags the commit on the last step. We cannot amend the tagged commit (it is needed to update the docs) because the tag will be lost.
  • Loading branch information
LastDragon-ru committed Oct 19, 2023
1 parent f1afbe6 commit 993d002
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions packages/documentator/src/Commands/Requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
description: 'Generates a table with the required versions of PHP/Laravel in Markdown format.',
)]
class Requirements extends Command {
public const Name = Package::Name.':requirements';
public const Name = Package::Name.':requirements';
private const HEAD = 'HEAD';

/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
Expand Down Expand Up @@ -76,7 +77,7 @@ class Requirements extends Command {
public function __invoke(PackageViewer $viewer, Git $git, Serializer $serializer): void {
// Get Versions
$cwd = Cast::toString($this->argument('cwd') ?? getcwd());
$tags = $this->getPackageVersions($git, $cwd, ['HEAD']);
$tags = $this->getPackageVersions($git, $cwd, [self::HEAD]);

// Collect requirements
$storage = new Storage($serializer, $cwd);
Expand All @@ -88,7 +89,7 @@ public function __invoke(PackageViewer $viewer, Git $git, Serializer $serializer

foreach ($tags as $tag) {
// Cached?
if ($tag !== 'HEAD') {
if ($tag !== self::HEAD) {
$cached = $metadata->requirements[$tag] ?? [];

if (array_diff_key($packages, $cached) === [] && array_diff_key($cached, $packages) === []) {
Expand Down Expand Up @@ -127,6 +128,15 @@ public function __invoke(PackageViewer $viewer, Git $git, Serializer $serializer
}
}

// Unreleased
if (
$metadata->version
&& !isset($metadata->requirements[$metadata->version])
&& isset($metadata->requirements[self::HEAD])
) {
$metadata->requirements[$metadata->version] = $metadata->requirements[self::HEAD];
}

// Save
$storage->save($metadata);

Expand Down
2 changes: 1 addition & 1 deletion packages/documentator/src/Metadata/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Metadata implements Serializable {
* @param array<string, array<string, list<string>>> $requirements
*/
public function __construct(
public string $version = '0.0.0',
public ?string $version = null,
public array $require = [],
public array $requirements = [],
) {
Expand Down

0 comments on commit 993d002

Please sign in to comment.