Skip to content

Commit

Permalink
do not lose anymore previous contents of meta-data file when adding a…
Browse files Browse the repository at this point in the history
… new manifest
  • Loading branch information
llaville committed Aug 26, 2024
1 parent 0db3d19 commit 4b0ae27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Pipeline/AbstractStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*/
abstract readonly class AbstractStage
{
protected const META_DATA_FILE = '.box.manifests.bin';

private ?HelperInterface $debugFormatterHelper;

/**
Expand Down
16 changes: 13 additions & 3 deletions src/Pipeline/BuildStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
use Bartlett\BoxManifest\Composer\ManifestFactory;
use Bartlett\BoxManifest\Composer\ManifestOptions;
use Bartlett\BoxManifest\Helper\ManifestFile;
use Bartlett\BoxManifest\Helper\ManifestFormat;

use Symfony\Component\Console\Input\ArrayInput;

use function array_merge;
use function file_exists;
use function file_get_contents;
use function serialize;
use function sprintf;
use function unserialize;

/**
* @author Laurent Laville
Expand Down Expand Up @@ -63,8 +66,15 @@ public function __invoke(array $payload): array
}
}

$manifests = serialize($payload['response']['artifacts'] ?? []);
$this->writeToStream('.box.manifests.bin', $manifests, 'Unable to write Manifests Metadata');
if (file_exists(self::META_DATA_FILE)) {
// @phpstan-ignore argument.type
$metadata = unserialize(file_get_contents(self::META_DATA_FILE));
} else {
$metadata = [];
}

$manifests = serialize(array_merge($metadata, $payload['response']['artifacts'] ?? []));
$this->writeToStream(self::META_DATA_FILE, $manifests, 'Unable to write Manifests Metadata');

$this->debugPrintStage(
sprintf(
Expand Down

0 comments on commit 4b0ae27

Please sign in to comment.