1+ #!/usr/bin/env php
2+ <?php
3+
4+ /**
5+ * The following is heavily borrowed from Ecotone.
6+ *
7+ * This script allows us to dynamically retrieve the package namespace
8+ * and directory from our composer file. This is then used by our GitHub
9+ * action to publish the packages to their appropriate repositories.
10+ *
11+ * @link https://github.com/ecotoneframework/ecotone-dev/blob/main/bin/get-packages
12+ */
13+
14+ const PACKAGES_DIRECTORY = __DIR__ . '/../src/Tempest/ ' ;
15+
16+ function getPackageNameFromComposerFile (string $ composerFile )
17+ {
18+ $ composer = json_decode (file_get_contents ($ composerFile ), true );
19+
20+ $ name = $ composer ['name ' ] ?? throw new UnexpectedValueException (
21+ 'The referenced package is invalid because it is missing a name: ' . $ composerFile
22+ );
23+
24+ return str_replace ('tempest/ ' , '' , $ name );
25+ }
26+
27+ /**
28+ * @return array<array-key, array{
29+ * basename: string,
30+ * directory: string,
31+ * name: string,
32+ * package: string,
33+ * organization: string,
34+ * repository: string
35+ * }>
36+ */
37+ function getPackages (): array {
38+ $ packages = [];
39+ $ directoryIterator = new DirectoryIterator (realpath (PACKAGES_DIRECTORY ));
40+
41+ /**
42+ * @var DirectoryIterator $directory
43+ */
44+ foreach ($ directoryIterator as $ directory ) {
45+ if ($ directory ->isDot ()) {
46+ continue ;
47+ }
48+
49+ $ file = $ directory ->getRealPath () . DIRECTORY_SEPARATOR . 'composer.json ' ;
50+
51+ if (! file_exists ($ file )) {
52+ continue ;
53+ }
54+
55+ $ name = getPackageNameFromComposerFile ($ file );
56+ $ packages [] = [
57+ 'basename ' => $ directory ->getBasename (),
58+ 'directory ' => $ directory ->getRealPath (),
59+ 'name ' => $ name ,
60+ 'package ' => 'tempest/ ' . $ name ,
61+ 'organization ' => 'tempestphp ' ,
62+ 'repository ' => sprintf ('tempest-%s ' , $ name ),
63+ ];
64+ }
65+
66+ return $ packages ;
67+ }
68+
69+ foreach (getPackages () as $ package ) {
70+ $ config = $ package ['directory ' ] . '/phpunit.xml ' ;
71+
72+ passthru (__DIR__ . "/../vendor/bin/phpunit -c $ config --bootstrap " . __DIR__ . "/../vendor/autoload.php --stop-on-failure --stop-on-risky " , $ result );
73+
74+ if ($ result !== 0 ) {
75+ exit ;
76+ }
77+ }
0 commit comments