Skip to content

Commit 3777380

Browse files
authored
Merge pull request #81 from eliashaeussler/feature/guides-xml
[FEATURE] Support guides.xml in documentation version replacement
2 parents 66f4215 + 0c832a0 commit 3777380

File tree

4 files changed

+104
-40
lines changed

4 files changed

+104
-40
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ be done using the `set-version` command.
175175
./vendor/bin/tailor set-version 1.2.0
176176
```
177177

178-
If your extension also contains a `Documentation/Settings.cfg`
179-
file, the command will also update the `release` and `version`
180-
information in it. You can disable this feature by either
181-
using `--no-docs` or by setting the environment variable
182-
`TYPO3_DISABLE_DOCS_VERSION_UPDATE=1`.
178+
If your extension also contains a `Documentation/guides.xml`
179+
or `Documentation/Settings.cfg` file, the command will also
180+
update the `release` and `version` information in it. You
181+
can disable this feature by either using `--no-docs` or by
182+
setting the environment variable `TYPO3_DISABLE_DOCS_VERSION_UPDATE=1`.
183183

184184
> [!TIP]
185185
> It's also possible to use the `--path` option to

src/Command/Extension/SetExtensionVersionCommand.php

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,19 @@
2424

2525
/**
2626
* Command for updating the extension version in ext_emconf.php and
27-
* the extension documentation configuration file Settings.cfg.
27+
* the extension documentation configuration files guides.xml and Settings.cfg.
2828
*/
2929
class SetExtensionVersionCommand extends Command
3030
{
3131
private const EMCONF_PATTERN = '["\']version["\']\s=>\s["\']((?:[0-9]+)\.[0-9]+\.[0-9]+\s*)["\']';
32-
private const DOCUMENTATION_VERSION_PATTERN = 'version\s*=\s*([0-9]+\.[0-9]+)';
33-
private const DOCUMENTATION_RELEASE_PATTERN = 'release\s*=\s*([0-9]+\.[0-9]+\.[0-9]+)';
32+
33+
// Documentation/guides.xml
34+
private const DOCUMENTATION_RELEASE_PATTERN = 'release="([0-9]+\.[0-9]+\.[0-9]+)"';
35+
private const DOCUMENTATION_VERSION_PATTERN = 'version="([0-9]+\.[0-9]+)"';
36+
37+
// Documentation/Settings.cfg
38+
private const DOCUMENTATION_RELEASE_LEGACY_PATTERN = 'release\s*=\s*([0-9]+\.[0-9]+\.[0-9]+)';
39+
private const DOCUMENTATION_VERSION_LEGACY_PATTERN = 'version\s*=\s*([0-9]+\.[0-9]+)';
3440

3541
protected function configure(): void
3642
{
@@ -80,28 +86,47 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8086
return 0;
8187
}
8288

83-
$documentationSettingsFile = rtrim($path, '/') . '/Documentation/Settings.cfg';
84-
if (!file_exists($documentationSettingsFile)) {
85-
$io->note(
86-
'Documentation version update is enabled but was not performed because the file '
87-
. $documentationSettingsFile . ' does not exist. To disable this operation use the \'--no-docs\' '
88-
. 'option or set the \'TYPO3_DISABLE_DOCS_VERSION_UPDATE\' environment variable.'
89-
);
90-
return 0;
89+
$documentationVersionReplaced = false;
90+
$documentationSettingsFiles = [
91+
rtrim($path, '/') . '/Documentation/guides.xml' => [
92+
self::DOCUMENTATION_RELEASE_PATTERN,
93+
self::DOCUMENTATION_VERSION_PATTERN,
94+
],
95+
rtrim($path, '/') . '/Documentation/Settings.cfg' => [
96+
self::DOCUMENTATION_RELEASE_LEGACY_PATTERN,
97+
self::DOCUMENTATION_VERSION_LEGACY_PATTERN,
98+
],
99+
];
100+
101+
foreach ($documentationSettingsFiles as $documentationSettingsFile => [$documentationReleasePattern, $documentationVersionPattern]) {
102+
if (!file_exists($documentationSettingsFile)) {
103+
continue;
104+
}
105+
106+
try {
107+
$versionReplacer->setVersion($documentationSettingsFile, $documentationReleasePattern);
108+
} catch (\InvalidArgumentException $e) {
109+
$io->error(sprintf('An error occurred while updating the release number in %s', $documentationSettingsFile));
110+
return 1;
111+
}
112+
113+
try {
114+
$versionReplacer->setVersion($documentationSettingsFile, $documentationVersionPattern, 2);
115+
} catch (\InvalidArgumentException $e) {
116+
$io->error(sprintf('An error occurred while updating the version number in %s', $documentationSettingsFile));
117+
return 1;
118+
}
119+
120+
$documentationVersionReplaced = true;
91121
}
92122

93-
try {
94-
$versionReplacer->setVersion($documentationSettingsFile, self::DOCUMENTATION_RELEASE_PATTERN);
95-
} catch (\InvalidArgumentException $e) {
96-
$io->error(sprintf('An error occurred while updating the release number in %s', $documentationSettingsFile));
97-
return 1;
98-
}
99-
100-
try {
101-
$versionReplacer->setVersion($documentationSettingsFile, self::DOCUMENTATION_VERSION_PATTERN, 2);
102-
} catch (\InvalidArgumentException $e) {
103-
$io->error(sprintf('An error occurred while updating the version number in %s', $documentationSettingsFile));
104-
return 1;
123+
if (!$documentationVersionReplaced) {
124+
$io->note(
125+
'Documentation version update is enabled but was not performed because the files '
126+
. implode(' and ', array_keys($documentationSettingsFiles)) . ' do not exist. '
127+
. 'To disable this operation use the \'--no-docs\' option or set the '
128+
. '\'TYPO3_DISABLE_DOCS_VERSION_UPDATE\' environment variable.'
129+
);
105130
}
106131

107132
return 0;

tests/Unit/Filesystem/VersionReplacerTest.php

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,58 @@ public function replaceVersionReplacesProperVersionOfEmConf(): void
3333
}
3434

3535
/**
36-
* @test
36+
* @return \Generator<string, array{string, string, string}>
3737
*/
38-
public function replaceVersionReplacesProperReleaseOfDocumentationConfiguration(): void
38+
public static function replaceVersionReplacesProperReleaseOfDocumentationConfigurationDataProvider(): \Generator
3939
{
40-
$docSettings = file_get_contents(__DIR__ . '/../Fixtures/Documentation/Settings.cfg');
41-
$tempFile = tempnam('/tmp/', 'tailor_settings.cfg');
40+
yield 'guides.xml' => ['guides.xml', 'release="([0-9]+\.[0-9]+\.[0-9]+)"', 'release="6.9.0"'];
41+
yield 'Settings.cfg' => ['Settings.cfg', 'release\s*=\s*([0-9]+\.[0-9]+\.[0-9]+)', 'release=6.9.0'];
42+
}
43+
44+
/**
45+
* @test
46+
* @dataProvider replaceVersionReplacesProperReleaseOfDocumentationConfigurationDataProvider
47+
*/
48+
public function replaceVersionReplacesProperReleaseOfDocumentationConfiguration(
49+
string $docSettingsFile,
50+
string $docReleasePattern,
51+
string $expected
52+
): void {
53+
$docSettings = file_get_contents(__DIR__ . '/../Fixtures/Documentation/' . $docSettingsFile);
54+
$tempFile = tempnam(sys_get_temp_dir(), 'tailor_' . $docSettingsFile);
4255
file_put_contents($tempFile, $docSettings);
4356
$subject = new VersionReplacer('6.9.0');
44-
$subject->setVersion($tempFile, 'release\s*=\s*([0-9]+\.[0-9]+\.[0-9]+)');
57+
$subject->setVersion($tempFile, $docReleasePattern);
4558
$contents = file_get_contents($tempFile);
46-
self::assertStringContainsString('release=6.9.0', preg_replace('/\s+/', '', $contents));
59+
self::assertStringContainsString($expected, preg_replace('/\s+/', '', $contents));
4760
unlink($tempFile);
4861
}
4962

5063
/**
51-
* @test
64+
* @return \Generator<string, array{string, string, string}>
5265
*/
53-
public function replaceVersionReplacesProperVersionOfDocumentationConfiguration(): void
66+
public static function replaceVersionReplacesProperVersionOfDocumentationConfigurationDataProvider(): \Generator
5467
{
55-
$docSettings = file_get_contents(__DIR__ . '/../Fixtures/Documentation/Settings.cfg');
56-
$tempFile = tempnam('/tmp/', 'tailor_settings.cfg');
68+
yield 'guides.xml' => ['guides.xml', 'version="([0-9]+\.[0-9]+)"', 'version="6.9"'];
69+
yield 'Settings.cfg' => ['Settings.cfg', 'version\s*=\s*([0-9]+\.[0-9]+)', 'version=6.9'];
70+
}
71+
72+
/**
73+
* @test
74+
* @dataProvider replaceVersionReplacesProperVersionOfDocumentationConfigurationDataProvider
75+
*/
76+
public function replaceVersionReplacesProperVersionOfDocumentationConfiguration(
77+
string $docSettingsFile,
78+
string $docVersionPattern,
79+
string $expected
80+
): void {
81+
$docSettings = file_get_contents(__DIR__ . '/../Fixtures/Documentation/' . $docSettingsFile);
82+
$tempFile = tempnam(sys_get_temp_dir(), 'tailor_' . $docSettingsFile);
5783
file_put_contents($tempFile, $docSettings);
5884
$subject = new VersionReplacer('6.9.0');
59-
$subject->setVersion($tempFile, 'version\s*=\s*([0-9]+\.[0-9]+)', 2);
85+
$subject->setVersion($tempFile, $docVersionPattern, 2);
6086
$contents = file_get_contents($tempFile);
61-
self::assertStringContainsString('version=6.9', preg_replace('/\s+/', '', $contents));
87+
self::assertStringContainsString($expected, preg_replace('/\s+/', '', $contents));
6288
unlink($tempFile);
6389
}
6490

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<guides xmlns="https://www.phpdoc.org/guides"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="https://www.phpdoc.org/guides ../vendor/phpdocumentor/guides-cli/resources/schema/guides.xsd"
5+
links-are-relative="true"
6+
>
7+
<extension class="\T3Docs\Typo3DocsTheme\DependencyInjection\Typo3DocsThemeExtension"/>
8+
<project
9+
title="My extension"
10+
release="1.0.0"
11+
version="1.0"
12+
copyright="2021"/>
13+
</guides>

0 commit comments

Comments
 (0)