-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate-file-sums.php
117 lines (88 loc) · 3.91 KB
/
generate-file-sums.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
include 'functions.php';
$forceGenerate = isset($_SERVER['FORCE_GENERATE']) && $_SERVER['FORCE_GENERATE'] === '1';
echo "Force generate mode: " . var_export($forceGenerate, true) . PHP_EOL;
function getMissingVersions(array $releases): array
{
global $forceGenerate;
$missing = [];
foreach ($releases as $release) {
$folder = dirname(__DIR__) . '/api-doc/version/' . ltrim($release['name'], 'v');
$filename = $folder . '/Files.md5sums';
if (!$forceGenerate && is_file($filename)) {
continue;
}
if (!file_exists($folder)) {
if (!mkdir($concurrentDirectory = $folder) && !is_dir($concurrentDirectory)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
}
}
$missing[] = $release + ['output' => $folder];
}
return $missing;
}
$tags = fetch_tags();
$missingVersions = getMissingVersions($tags);
$ignoredFiles = [
'Recovery/Common/vendor/autoload.php',
'Recovery/Common/vendor/composer/ClassLoader.php',
'Recovery/Common/vendor/composer/InstalledVersions.php',
'Recovery/Common/vendor/composer/autoload_classmap.php',
'Recovery/Common/vendor/composer/autoload_files.php',
'Recovery/Common/vendor/composer/autoload_namespaces.php',
'Recovery/Common/vendor/composer/autoload_psr4.php',
'Recovery/Common/vendor/composer/autoload_real.php',
'Recovery/Common/vendor/composer/autoload_static.php',
'Recovery/Common/vendor/composer/installed.php',
'Recovery/vendor/autoload.php',
'Recovery/vendor/composer/ClassLoader.php',
'Recovery/vendor/composer/InstalledVersions.php',
'Recovery/vendor/composer/autoload_classmap.php',
'Recovery/vendor/composer/autoload_namespaces.php',
'Recovery/vendor/composer/autoload_psr4.php',
'Recovery/vendor/composer/autoload_real.php',
'Recovery/vendor/composer/autoload_static.php',
'Recovery/vendor/composer/installed.php',
'Recovery/vendor/composer/autoload_files.php',
];
$ignoredFilesFilter = [];
foreach ($ignoredFiles as $ignoredFile) {
$ignoredFilesFilter[] = '-not -iwholename \'' . $ignoredFile . '\'';
}
/**
* @param $output
* @return void
*/
function fixPaths($output)
{
$filePath = $output;
$tmpFilePath = $filePath . '.tmp';
$reading = fopen($filePath, 'r');
$writing = fopen($tmpFilePath, 'w');
while (!feof($reading)) {
$line = fgets($reading);
$newLine = preg_replace_callback('/shopware-shopware-\w+\/src\/(\w+)/', function ($matches) {
return 'vendor/shopware/' . strtolower($matches[1]);
}, $line);
fputs($writing, $newLine);
}
fclose($reading);
fclose($writing);
rename($tmpFilePath, $filePath);
}
foreach ($missingVersions as $release) {
$installFolder = sys_get_temp_dir() . '/' . uniqid('sw', true);
if (!mkdir($installFolder) && !is_dir($installFolder)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $installFolder));
}
chdir($installFolder);
printf('> Unpacking Shopware with Version: %s in %s' . PHP_EOL, $release['name'], $installFolder);
exec('wget -O install.zip -qq ' . $release['zipball_url']);
exec('unzip -q install.zip');
$outputFolder = $release['output'];
exec("find */src -type f \( " . implode(' ', $ignoredFilesFilter) . " -iname '*.php' -o -iname '*.twig' -o -iname '*.js' -o -iname '*.scss' -o -iname '*.xml' \) -print0 | xargs -0 md5sum | sort -k 2 -d > " . $outputFolder . '/Files.md5sums');
exec("find */src -type f \( " . implode(' ', $ignoredFilesFilter) . " -iname '*.php' -o -iname '*.twig' -o -iname '*.js' -o -iname '*.scss' -o -iname '*.xml' \) -print0 | xargs -0 xxhsum | sort -k 2 -d > " . $outputFolder . '/Files.xxhsums');
exec('rm -rf ' . escapeshellarg($installFolder));
fixPaths($outputFolder . '/Files.md5sums');
fixPaths($outputFolder . '/Files.xxhsums');
}