-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate-composer-info.php
95 lines (68 loc) · 2.64 KB
/
generate-composer-info.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
<?php
include 'functions.php';
$forceGenerate = isset($_SERVER['FORCE_GENERATE']) && $_SERVER['FORCE_GENERATE'] === '1';
$tags = fetch_tags();
$workDir = tempnam(sys_get_temp_dir(), uniqid('composer', true));
$components = ['shopware/core', 'shopware/storefront', 'shopware/administration', 'shopware/elasticsearch'];
$composerFolder = __DIR__ . '/composer';
if (!file_exists($composerFolder)) {
mkdir($composerFolder);
}
$availableVersions = [];
foreach ($tags as $tag) {
if (!isset($tag['name'])) {
throw new \RuntimeException('Invalid tag data');
}
$versionRaw = trim(ltrim($tag['name'], 'v'));
$folderPath = __DIR__ . '/composer/' . $versionRaw . '/';
$availableVersions[] = $versionRaw;
if (!$forceGenerate && file_exists($folderPath)) {
continue;
}
$phpVersion = "7.2.0";
if (version_compare('6.6.0.0', $versionRaw, '>=')) {
$phpVersion = "8.2.0";
} else if (version_compare('6.5.0.0', $versionRaw, '>=')) {
$phpVersion = "8.1.0";
} else if (version_compare('6.4.0.0', $versionRaw, '>=')) {
$phpVersion = "7.4.0";
}
$stabilityFlags = [];
if (stripos($versionRaw, 'rc') !== false) {
$stabilityFlags = [
'minimum-stability' => 'RC',
'prefer-stable' => true
];
}
foreach ($components as $component) {
exec('rm -rf ' . escapeshellarg($workDir));
mkdir($workDir);
$composerJson = [
'require' => [
$component => $tag['name']
],
'config' => [
'platform' => [
'php' => $phpVersion,
]
]
] + $stabilityFlags;
file_put_contents($workDir . '/composer.json', json_encode($composerJson));
exec('composer install --no-dev --no-scripts --no-plugins --ignore-platform-reqs -d ' . escapeshellarg($workDir));
if (!file_exists($workDir . '/composer.lock')) {
throw new RuntimeException('No composer.lock found');
}
$locks = [];
$composerLock = json_decode(file_get_contents($workDir . '/composer.lock'), true);
foreach ($composerLock['packages'] as $package) {
$locks[$package['name']] = $package['version'];
}
if (!file_exists($folderPath)) {
mkdir($folderPath);
}
file_put_contents($folderPath . str_replace('shopware/', '', $component) . '.json', json_encode($locks, JSON_PRETTY_PRINT));
}
}
// @todo remove when 6.6 is out
$availableVersions[] = '6.6.0.0';
file_put_contents($composerFolder . '/versions.json', json_encode($availableVersions, JSON_PRETTY_PRINT));