Skip to content

Commit 8130550

Browse files
authored
Save archived version of each recipe + add "archived_recipes_template" to _links
1 parent e563c8b commit 8130550

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

src/DiffRecipeVersionsCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3030
$packages = [];
3131
$requires = [];
3232

33-
while (false !== $package = fgets(STDIN)) {
33+
while (false !== $package = fgets(\STDIN)) {
3434
$package = substr($package, 0, -1);
3535

36-
$versions = scandir($package, SCANDIR_SORT_NONE);
36+
$versions = scandir($package, \SCANDIR_SORT_NONE);
3737
usort($versions, 'version_compare');
3838

39-
if (!$versions = array_slice($versions, 2)) {
39+
if (!$versions = \array_slice($versions, 2)) {
4040
continue;
4141
}
4242

@@ -102,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
102102
foreach ($versions as $version) {
103103
$diff = shell_exec(sprintf('LC_ALL=C git diff --color=never --no-index %s/%s %1$s/%s', $package, $previousVersion, $version));
104104

105-
$output->writeln("<details>");
105+
$output->writeln('<details>');
106106
$output->writeln(sprintf("<summary>%s <em>vs</em> %s</summary>\n", $previousVersion, $version));
107107
$output->writeln("```diff\n$diff```");
108108
$output->writeln("\n</details>\n");

src/GenerateFlexEndpointCommand.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\Console\Input\InputArgument;
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Output\OutputInterface;
17-
use Symfony\Component\HttpClient\HttpClient;
1817

1918
#[AsCommand(name: 'generate:flex-endpoint', description: 'Generates the json files required by Flex')]
2019
class GenerateFlexEndpointCommand extends Command
@@ -56,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5655

5756
// stdin usually generated by `git ls-tree HEAD */*/*`
5857

59-
while (false !== $line = fgets(STDIN)) {
58+
while (false !== $line = fgets(\STDIN)) {
6059
[$tree, $package] = explode("\t", trim($line));
6160
[,, $tree] = explode(' ', $tree);
6261

@@ -98,8 +97,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9897
'repository' => sprintf('github.com/%s', $repository),
9998
'origin_template' => sprintf('{package}:{version}@github.com/%s:%s', $repository, $sourceBranch),
10099
'recipe_template' => sprintf('https://raw.githubusercontent.com/%s/%s/{package_dotted}.{version}.json', $repository, $flexBranch),
100+
'archived_recipes_template' => sprintf('https://raw.githubusercontent.com/%s/%s/archived/{package_dotted}/{ref}.json', $repository, $flexBranch),
101101
],
102-
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n");
102+
], \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES)."\n");
103103

104104
return 0;
105105
}
@@ -138,15 +138,26 @@ private function generatePackageJson(string $package, string $version, array $ma
138138

139139
ksort($files, \SORT_NATURAL);
140140

141-
file_put_contents(sprintf('%s/%s.%s.json', $outputDir, str_replace('/', '.', $package), $version), json_encode([
142-
'manifests' => [
143-
$package => [
144-
'manifest' => $manifest,
145-
'files' => $files,
146-
'ref' => $tree,
141+
$contents = json_encode(
142+
[
143+
'manifests' => [
144+
$package => [
145+
'manifest' => $manifest,
146+
'files' => $files,
147+
'ref' => $tree,
148+
],
147149
],
148150
],
149-
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n");
151+
\JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES
152+
)."\n";
153+
file_put_contents(sprintf('%s/%s.%s.json', $outputDir, str_replace('/', '.', $package), $version), $contents);
154+
155+
// save another version for the archives
156+
$archivedPath = sprintf('%s/archived/%s.%s/%s.json', $outputDir, str_replace('/', '.', $package), $version, $tree);
157+
if (!file_exists(\dirname($archivedPath))) {
158+
mkdir(\dirname($archivedPath), 0777, true);
159+
}
160+
file_put_contents($archivedPath, $contents);
150161

151162
return true;
152163
}

src/LintYamlCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
2424
{
2525
$exit = 0;
2626

27-
while (false !== $file = fgets(STDIN)) {
27+
while (false !== $file = fgets(\STDIN)) {
2828
$file = substr($file, 0, -1);
2929
$this->validate($file, $output, $exit);
3030
}

src/ListUnpatchedPackagesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3434
$client = HttpClient::create();
3535
$diff = $client->request('GET', $data['pull_request']['diff_url'], ['auth_bearer' => $input->getArgument('github_token')])->getContent();
3636

37-
preg_match_all('{^diff --git a/(([^/]++/[^/]++)/.*) b/\1$}m', $diff, $matches, PREG_PATTERN_ORDER);
37+
preg_match_all('{^diff --git a/(([^/]++/[^/]++)/.*) b/\1$}m', $diff, $matches, \PREG_PATTERN_ORDER);
3838

3939
$patchedPackages = array_flip($matches[2]);
4040

0 commit comments

Comments
 (0)