-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathcastor.php
More file actions
188 lines (148 loc) · 6.24 KB
/
castor.php
File metadata and controls
188 lines (148 loc) · 6.24 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
declare(strict_types=1);
use Castor\Attribute\AsTask;
use function Castor\context;
use function Castor\http_download;
use function Castor\io;
use function Castor\PHPQa\php_cs_fixer;
use function Castor\PHPQa\phpstan;
use function Castor\run;
#[AsTask('cs:check', namespace: 'qa', description: 'Check for coding standards without fixing them')]
function qa_cs_check()
{
php_cs_fixer(['fix', '--config', __DIR__ . '/.php-cs-fixer.php', '--dry-run', '--diff'], '3.92.3', [
'kubawerlos/php-cs-fixer-custom-fixers' => '^3.21',
]);
}
#[AsTask('cs:fix', namespace: 'qa', description: 'Fix all coding standards', aliases: ['cs'])]
function qa_cs_fix()
{
php_cs_fixer(['fix', '--config', __DIR__ . '/.php-cs-fixer.php', '-v'], '3.92.3', [
'kubawerlos/php-cs-fixer-custom-fixers' => '^3.21',
]);
}
#[AsTask('phpstan', namespace: 'qa', description: 'Run PHPStan for static analysis', aliases: ['phpstan'])]
function qa_phpstan(bool $generateBaseline = false)
{
$params = ['analyse', '--configuration', __DIR__ . '/phpstan.neon', '--memory-limit=-1', '-v'];
if ($generateBaseline) {
$params[] = '--generate-baseline';
}
phpstan($params, '1.12.23');
}
#[AsTask('mapper', namespace: 'debug', description: 'Debug a mapper', aliases: ['debug'])]
function debug_mapper(string $source, string $target, string $load = '')
{
require_once __DIR__ . '/vendor/autoload.php';
// special autoloader for "AutoMapperTests"
spl_autoload_register(function (string $class) {
if (!str_starts_with($class, 'AutoMapper\\Tests\\AutoMapperTest\\')) {
return false;
}
// split on namespace separator
$parts = explode('\\', $class);
// get second part
$testDirectory = $parts[3] ?? '';
$mapFile = __DIR__ . '/tests/AutoMapperTest/' . $testDirectory . '/map.php';
if (file_exists($mapFile)) {
require_once $mapFile;
}
});
$automapper = AutoMapper\AutoMapper::create();
// get private property loader value
$loader = new ReflectionProperty($automapper, 'classLoader');
$loader = $loader->getValue($automapper);
// get metadata factory
$metadataFactory = new ReflectionProperty($loader, 'metadataFactory');
$metadataFactory = $metadataFactory->getValue($loader);
$command = new AutoMapper\Symfony\Bundle\Command\DebugMapperCommand($metadataFactory);
$input = new Symfony\Component\Console\Input\ArrayInput([
'source' => $source,
'target' => $target,
]);
$command->run($input, \Castor\output());
}
#[AsTask('install', namespace: 'doc', description: 'Install tool for documentation (need poetry)')]
function doc_install()
{
run('poetry install');
}
#[AsTask('server', namespace: 'doc', description: 'Serve documentation')]
function doc_serve()
{
run('poetry run mkdocs serve -a localhost:8000');
}
#[AsTask(description: 'Fetch external assets and customize theme', namespace: 'doc')]
function build_assets(): void
{
io()->title('Fetching external assets for MkDocs documentation');
http_download('https://raw.githubusercontent.com/jolicode/oss-theme/refs/heads/main/MkDocs/extra.css', __DIR__ . '/docs/assets/stylesheets/jolicode.css');
http_download('https://raw.githubusercontent.com/jolicode/oss-theme/refs/heads/main/snippet-joli-footer.html', __DIR__ . '/docs/overrides/jolicode-footer.html');
$html = <<<'HTML'
AutoMapper is licensed under
<a href="https://github.com/jolicode/automapper/blob/main/LICENSE" target="_blank" rel="noreferrer noopener" class="jf-link">
MIT license
</a>
HTML;
$footer = file_get_contents(__DIR__ . '/docs/overrides/jolicode-footer.html');
$footer = str_replace('#GITHUB_REPO', 'jolicode/automapper', $footer);
$footer = str_replace('<!-- #SUBTITLE -->', $html, $footer);
file_put_contents(__DIR__ . '/docs/overrides/jolicode-footer.html', $footer);
}
#[AsTask('build-github-pages', namespace: 'doc', description: 'Serve documentation')]
function doc_build_github_pages()
{
// clean .build directory
run('rm -rf ./.build', context: context()->withAllowFailure());
// create .build directory
@mkdir(__DIR__ . '/.build');
run('git config user.name ci-bot');
run('git config user.email ci-bot@example.org');
run('git remote add gh-pages ./.build', context: context()->withAllowFailure());
$context = context()->withWorkingDirectory(__DIR__ . '/.build');
run('git init', context: $context);
run('git checkout -b gh-pages', context: $context);
run('git config receive.denyCurrentBranch ignore', context: $context);
// build documentation for main branch
run('poetry run mike deploy --push --remote gh-pages dev');
// get the list of tags
$tags = run('git tag --list', context: context()->withQuiet())->getOutput();
$tags = array_filter(array_map('trim', explode("\n", $tags)));
$minVersion = '8.2.2';
$latestVersion = $minVersion;
$buildTags = [];
foreach ($tags as $tag) {
if (!version_compare($tag, $minVersion, '>=')) {
continue;
}
// version is X.Y.Z we want the X.Y part
$parts = explode('.', $tag);
if (count($parts) !== 3) {
continue;
}
$majorMinor = $parts[0] . '.' . $parts[1];
// get only the last version for this major.minor
if (isset($buildTags[$majorMinor]) && version_compare($tag, $buildTags[$majorMinor], '<=')) {
continue;
}
if (version_compare($tag, $latestVersion, '>')) {
$latestVersion = $tag;
}
$buildTags[$majorMinor] = $tag;
}
foreach ($buildTags as $tag) {
run('git checkout tags/' . $tag);
if ($tag === $latestVersion) {
run('poetry run mike deploy --push --remote gh-pages ' . $tag . ' latest');
} else {
run('poetry run mike deploy --push --remote gh-pages --update-aliases ' . $tag);
}
}
run('git reset --hard gh-pages', context: $context);
}
#[AsTask('serve', namespace: 'test', description: 'Serve the symfony app in tests')]
function test_serve($prod = false): void
{
$file = $prod ? 'index.php' : 'dev.php';
run('php -S localhost:8000 tests/Bundle/Resources/public/' . $file, context: context()->withAllowFailure());
}