Repository navigation
Expand file tree
/
Copy pathbump
More file actions
executable file
·279 lines (240 loc) · 12 KB
/
Copy pathbump
File metadata and controls
executable file
·279 lines (240 loc) · 12 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/usr/bin/env php
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require __DIR__.'/vendor/autoload.php';
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\SingleCommandApplication;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
/**
* Bumps the version and updates version constraints for symfony/ai-* dependencies across the monorepo.
* Reads the current version from src/mate/src/App.php.
*
* For release, run this script with one of the following options:
* ./bump --major : Bump major version (X.0.0)
* ./bump --minor : Bump minor version (x.X.0)
* ./bump --patch : Bump patch version (x.x.X)
*
* Before a major release, run through pre-releases with:
* ./bump --beta : Start or continue the betas of the next major version (X.0.0-BETA1, X.0.0-BETA2, ...)
* ./bump --rc : Start or continue the release candidates (X.0.0-RC1, X.0.0-RC2, ...)
* ./bump --major : Release the pre-released version as stable (X.0.0)
*
* This will also update all symfony/ai-* composer constraints to match the new version.
*
* Alternatively, you can specify an explicit version with:
* ./bump --release=1.2.3 : Set explicit release version (e.g., 1.2.3 or 1.2.3-RC1)
* ./bump --constraint="^1.2" : Set explicit composer constraint
*
* @author Christopher Hertel <mail@christopher-hertel.de>
*/
(new SingleCommandApplication())
->setName('Symfony AI Version Bump')
->setDescription('Bumps the version and updates version constraints for symfony/ai-* dependencies across the monorepo.')
->addOption('major', null, InputOption::VALUE_NONE, 'Bump major version (X.0.0)')
->addOption('minor', null, InputOption::VALUE_NONE, 'Bump minor version (x.X.0)')
->addOption('patch', null, InputOption::VALUE_NONE, 'Bump patch version (x.x.X)')
->addOption('beta', null, InputOption::VALUE_NONE, 'Bump beta version of the next major (X.0.0-BETAn)')
->addOption('rc', null, InputOption::VALUE_NONE, 'Bump release candidate of the next major (X.0.0-RCn)')
->addOption('release', null, InputOption::VALUE_REQUIRED, 'Set explicit release version (e.g., 1.2.3 or 1.2.3-RC1)')
->addOption('constraint', null, InputOption::VALUE_REQUIRED, 'Set explicit composer constraint (e.g., ^1.2)')
->setCode(function (InputInterface $input, OutputInterface $output): int {
$filesystem = new Filesystem();
$io = new SymfonyStyle($input, $output);
$isMajor = $input->getOption('major');
$isMinor = $input->getOption('minor');
$isPatch = $input->getOption('patch');
$isBeta = $input->getOption('beta');
$isRc = $input->getOption('rc');
$releaseVersion = $input->getOption('release');
$composerConstraint = $input->getOption('constraint');
$bumpOptions = array_filter([
'major' => $isMajor,
'minor' => $isMinor,
'patch' => $isPatch,
'beta' => $isBeta,
'rc' => $isRc,
'release' => $releaseVersion,
]);
if (1 !== \count($bumpOptions)) {
$io->error('You must specify exactly one of --major, --minor, --patch, --beta, --rc, or --release');
return Command::FAILURE;
}
$appPhpPath = __DIR__.'/src/mate/src/App.php';
$appPhpContent = $filesystem->readFile($appPhpPath);
if (!preg_match('/public const VERSION = \'(([0-9]+)\.([0-9]+)\.([0-9]+)(?:-(BETA|RC)([0-9]+))?)\';/', $appPhpContent, $matches)) {
$io->error('Could not find VERSION constant in App.php');
return Command::FAILURE;
}
$currentVersion = $matches[1];
[, , $major, $minor, $patch] = $matches;
$stability = $matches[5] ?? null;
$stabilityNumber = (int) ($matches[6] ?? 0);
$io->writeln(\sprintf('Current version: <info>%s</info>', $currentVersion));
// Calculate new version
if ($releaseVersion) {
$newVersion = $releaseVersion;
if (!preg_match('/^([0-9]+)\.([0-9]+)\.([0-9]+)(-(BETA|RC)[0-9]+)?$/', $newVersion, $releaseMatches)) {
$io->error('Version must be in format X.Y.Z or X.Y.Z-BETAn or X.Y.Z-RCn (e.g., 1.2.3 or 1.2.3-RC1)');
return Command::FAILURE;
}
[, $newMajor, $newMinor, $newPatch] = $releaseMatches;
} elseif (null !== $stability && !$isMajor && !$isBeta && !$isRc) {
$io->error(\sprintf('Current version %s is a pre-release, use --beta, --rc or --major to continue.', $currentVersion));
return Command::FAILURE;
} elseif ($isBeta || $isRc) {
if ('RC' === $stability && $isBeta) {
$io->error(\sprintf('Current version %s is already a release candidate, use --rc or --major to continue.', $currentVersion));
return Command::FAILURE;
}
$newStability = $isBeta ? 'BETA' : 'RC';
if (null === $stability) {
$newMajor = (int) $major + 1;
$newMinor = 0;
$newPatch = 0;
} else {
$newMajor = (int) $major;
$newMinor = (int) $minor;
$newPatch = (int) $patch;
}
$newStabilityNumber = $newStability === $stability ? $stabilityNumber + 1 : 1;
$newVersion = \sprintf('%s.%s.%s-%s%d', $newMajor, $newMinor, $newPatch, $newStability, $newStabilityNumber);
} elseif ($isMajor && null !== $stability) {
$newMajor = (int) $major;
$newMinor = (int) $minor;
$newPatch = (int) $patch;
$newVersion = \sprintf('%s.%s.%s', $newMajor, $newMinor, $newPatch);
} elseif ($isMajor) {
$newMajor = (int) $major + 1;
$newMinor = 0;
$newPatch = 0;
$newVersion = \sprintf('%s.%s.%s', $newMajor, $newMinor, $newPatch);
} elseif ($isMinor) {
$newMajor = (int) $major;
$newMinor = (int) $minor + 1;
$newPatch = 0;
$newVersion = \sprintf('%s.%s.%s', $newMajor, $newMinor, $newPatch);
} elseif ($isPatch) {
$newMajor = (int) $major;
$newMinor = (int) $minor;
$newPatch = (int) $patch + 1;
$newVersion = \sprintf('%s.%s.%s', $newMajor, $newMinor, $newPatch);
}
$io->writeln(\sprintf('New version: <info>%s</info>', $newVersion));
// Calculate composer constraint
if (!$composerConstraint) {
// For patch bumps, keep the current minor version constraint (^X.Y)
// For minor bumps, use the new minor version constraint (^X.Y)
// For major bumps, use the new major version constraint (^X.0)
if ($isPatch) {
$composerConstraint = \sprintf('^%s.%s', $newMajor, $newMinor);
} elseif ($isMinor || $isMajor || $isBeta || $isRc) {
$composerConstraint = \sprintf('^%s.%s', $newMajor, $newMinor);
} elseif ($releaseVersion) {
// For explicit version, use ^X.Y
$composerConstraint = \sprintf('^%s.%s', $newMajor, $newMinor);
}
}
$io->writeln(\sprintf('Composer constraint: <info>%s</info>', $composerConstraint));
$io->newLine();
if (!$io->confirm('Proceed with these changes?')) {
$io->warning('Aborted by user.');
return Command::SUCCESS;
}
$newAppPhpContent = preg_replace(
'/public const VERSION = \'[0-9]+\.[0-9]+\.[0-9]+(-(BETA|RC)[0-9]+)?\';/',
\sprintf("public const VERSION = '%s';", $newVersion),
$appPhpContent
);
$filesystem->dumpFile($appPhpPath, $newAppPhpContent);
$io->writeln('<info>✓</info> Updated VERSION constant in App.php');
$totalUpdates = 0;
$finder = new Finder();
$finder->files()
->name('composer.json')
->in([__DIR__.'/src', __DIR__.'/demo', __DIR__.'/examples'])
->exclude('vendor');
$io->writeln(\sprintf('Found %d composer.json files to process:', $finder->count()));
foreach ($finder as $file) {
$composerFile = $file->getRealPath();
$content = $file->getContents();
$data = json_decode($content, true);
if (!$data) {
$io->writeln(\sprintf(' <comment>⚠</comment> Skipping "%s" (invalid JSON)', $file->getRelativePathname()));
continue;
}
$modified = false;
$fileUpdates = 0;
foreach (['require', 'require-dev'] as $section) {
foreach ($data[$section] ?? [] as $package => $constraint) {
if (str_starts_with($package, 'symfony/ai-') || 'symfony/mcp-bundle' === $package) {
$data[$section][$package] = $composerConstraint;
$modified = true;
++$fileUpdates;
}
}
}
// Unreleased packages are wired up through local "path" repositories, since no
// constraint can resolve a package that has never been tagged. Releasing tags
// them, so the constraints above now resolve from Packagist and the repositories
// are obsolete. Only drop the ones pointing inside the monorepo.
$removedRepositories = 0;
foreach ($data['repositories'] ?? [] as $key => $repository) {
if ('path' !== ($repository['type'] ?? null) || !isset($repository['url'])) {
continue;
}
$target = realpath($file->getPath().'/'.$repository['url']);
if (false === $target || !str_starts_with($target, __DIR__.'/')) {
continue;
}
unset($data['repositories'][$key]);
$modified = true;
++$removedRepositories;
}
if ($removedRepositories > 0) {
if ([] === $data['repositories']) {
unset($data['repositories']);
} else {
$data['repositories'] = array_values($data['repositories']);
}
}
// Write back if modified
if ($modified) {
$newContent = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n";
$filesystem->dumpFile($composerFile, $newContent);
$totalUpdates += $fileUpdates;
$io->writeln(\sprintf(' <info>✓</info> Saved "%s" with %d change(s)', str_replace(__DIR__.'/', '', $file->getRealPath()), $fileUpdates));
if ($removedRepositories > 0) {
$io->writeln(\sprintf(' <info>✓</info> Removed %d local "path" %s', $removedRepositories, 1 === $removedRepositories ? 'repository' : 'repositories'));
}
}
}
$rstPath = __DIR__.'/docs/components/mate/creating-extensions.rst';
$rstContent = $filesystem->readFile($rstPath);
$newRstContent = preg_replace(
'/("symfony\/ai-mate":\s*")[^"]+(")/',
\sprintf('$1%s$2', $composerConstraint),
$rstContent,
-1,
$rstReplacements,
);
if ($rstReplacements > 0) {
$filesystem->dumpFile($rstPath, $newRstContent);
$io->writeln(' <info>✓</info> Saved "docs/components/mate/creating-extensions.rst" with %d change');
}
$io->newLine();
$io->success(\sprintf('Successfully bumped version to %s and updated %d dependency constraints in %d files to "%s".', $newVersion, $totalUpdates, $finder->count(), $composerConstraint));
return Command::SUCCESS;
})
->run();