Repository navigation
Expand file tree
/
Copy pathverify-v3-graph.php
More file actions
executable file
·131 lines (104 loc) · 5.06 KB
/
Copy pathverify-v3-graph.php
File metadata and controls
executable file
·131 lines (104 loc) · 5.06 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
declare(strict_types=1);
/*
|--------------------------------------------------------------------------
| Verify the embedded dependency graph is HydePHP v3
|--------------------------------------------------------------------------
|
| HydePHP v3 is unreleased: there is no 3.x tag on Packagist, and the version
| numbers on the development branch have deliberately not been bumped, so
| `HydeKernel::VERSION` still reads `2.0.3` on both lines. The generation of
| the embedded framework therefore cannot be read off a version string.
|
| This checks the two things that do distinguish the lines: where the package
| came from, and whether the code carries v3's removals and additions. It is
| run by the build before the executable is assembled, so that resolving to a
| published v2 package breaks the build instead of shipping quietly.
|
*/
$root = dirname(__DIR__);
$failures = [];
$fail = static function (string $message) use (&$failures): void {
$failures[] = $message;
};
$lock = json_decode((string) file_get_contents("$root/composer.lock"), true);
if (! is_array($lock)) {
fwrite(STDERR, "Could not read composer.lock\n");
exit(1);
}
$packages = [];
foreach ($lock['packages'] ?? [] as $package) {
$packages[$package['name']] = $package;
}
// The development packages must come from the local develop@master checkout. A `path`
// dist type is what proves the monorepo source won the resolution, since a published
// package would carry a `zip` dist pointing at a GitHub zipball instead.
foreach (['hyde/framework', 'hyde/realtime-compiler'] as $name) {
if (! isset($packages[$name])) {
$fail("$name is not installed");
continue;
}
$package = $packages[$name];
$type = $package['dist']['type'] ?? null;
$version = $package['version'] ?? '?';
if ($type !== 'path') {
$fail("$name resolved to a published package ($version, dist type '$type') rather than the develop@master checkout");
}
if ($version !== 'dev-master') {
$fail("$name is at '$version', expected 'dev-master'");
}
}
$framework = "$root/vendor/hyde/framework";
if (! is_dir($framework)) {
$fail('hyde/framework is not present in vendor');
}
// v3 removed the rebuild command outright, along with the filepath comment processor
// that the title modifier replaced. Their presence means a v2 framework is installed.
foreach ([
'src/Console/Commands/RebuildPageCommand.php' => 'the rebuild command, removed in v3',
'src/Markdown/Processing/CodeblockFilepathProcessor.php' => 'the filepath comment processor, removed in v3',
'src/Framework/Actions/PostBuildTasks/GenerateSitemap.php' => 'the GenerateSitemap post-build task, removed in v3',
'src/Framework/Actions/PostBuildTasks/GenerateRssFeed.php' => 'the GenerateRssFeed post-build task, removed in v3',
] as $path => $what) {
if (file_exists("$framework/$path")) {
$fail("The installed framework still carries $what ($path)");
}
}
// And these arrived with v3.
foreach ([
'src/Markdown/Processing/BladeBlockProcessor.php' => 'Blade Blocks',
'src/Markdown/Extensions/CodeBlockViewModel.php' => 'composable code blocks',
'src/Markdown/Extensions/TerminalBlockViewModel.php' => 'terminal code blocks',
] as $path => $what) {
if (! file_exists("$framework/$path")) {
$fail("The installed framework is missing $what ($path), which v3 added");
}
}
// The version was deliberately unbumped for most of v3's development, reading 2.0.3 on
// both lines. Now that it distinguishes them it is worth checking, but only alongside the
// structural checks above: a constant states what the code claims to be, while the `path`
// dist type is what proves the local monorepo won the resolution.
$kernel = "$framework/src/Foundation/HydeKernel.php";
if (is_file($kernel) && preg_match("/const VERSION = '([^']+)'/", (string) file_get_contents($kernel), $matches) === 1) {
if (! str_starts_with($matches[1], '3.')) {
$fail("The installed framework reports version {$matches[1]}, which is not a v3 version");
}
}
$provider = "$framework/src/Console/ConsoleServiceProvider.php";
if (is_file($provider) && str_contains((string) file_get_contents($provider), 'RebuildPageCommand')) {
$fail('The console service provider still registers RebuildPageCommand');
}
if ($failures !== []) {
fwrite(STDERR, "\n The embedded dependency graph is not HydePHP v3.\n\n");
foreach ($failures as $failure) {
fwrite(STDERR, " - $failure\n");
}
// `composer update` does not help here: a path package is mirrored, and Composer sees
// no version change when the checkout moves, so it leaves the stale copy in place.
fwrite(STDERR, "\n Run `bin/sync-develop.sh`, then\n");
fwrite(STDERR, " `composer reinstall hyde/framework hyde/realtime-compiler`.\n\n");
exit(1);
}
fwrite(STDOUT, "The embedded dependency graph is HydePHP v3 (develop@master).\n");
fwrite(STDOUT, " Pre-release scaffolding: when v3 is tagged, drop the path repositories for ^3.0\n");
fwrite(STDOUT, " and delete this script, bin/sync-develop.sh and tests/Fixtures/project-template.\n");