From 9a5aaef9683524c3dd0fb3e443bf0aaf881f3db2 Mon Sep 17 00:00:00 2001 From: Manuel Strehl Date: Fri, 22 May 2026 09:20:20 +0200 Subject: [PATCH 1/5] add version information to the tool A bit of automation is sketched with the release.yaml workflow, but at the moment updating VERSION is still a manual process. ERM47998 --- .github/workflows/release.yaml | 38 +++++++++++++++++++++++++++ VERSION | 1 + bin/migrate-confluence | 2 ++ bin/mkversion.sh | 23 ++++++++++++++++ src/Analyzer/ConfluenceAnalyzer.php | 7 +++++ src/Command/GetVersion.php | 38 +++++++++++++++++++++++++++ src/Composer/ConfluenceComposer.php | 7 +++++ src/Converter/ConfluenceConverter.php | 1 + src/Extractor/ConfluenceExtractor.php | 7 +++++ src/Utility/Version.php | 22 ++++++++++++++++ 10 files changed, 146 insertions(+) create mode 100644 .github/workflows/release.yaml create mode 100644 VERSION create mode 100755 bin/mkversion.sh create mode 100644 src/Command/GetVersion.php create mode 100644 src/Utility/Version.php diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..9f80a382 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,38 @@ +name: prepare-release +# +# Currently this workflow is rather useless. It creates an updated VERSION file that is +# then discarded. The aim is later to produce releases semi-automatically with it. +# + +on: + workflow_run: + workflows: ["basic-tests"] + types: + - completed + push: + tags: + - '*' + +jobs: + set-version: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Set version from tag + id: set_version + run: | + ./bin/mkversion.sh --from-env + + # TODO we could let git-archive do this job and define exclusions in .gitattributes. + - name: create zip file for release + run: zip -r "migrate-confluence-{{ github.ref_name }}" bin doc docker src tests .phpcs.xml box.json composer.json Dockerfile LICENSE README.md VERSION + if: startsWith(github.ref, 'refs/tags/') + + # TODO do we want to auto-create releases for each tag? If yes, how do we handle release notes? + # - name: create release + # uses: softprops/action-gh-release@v2 + # with: + # files: "migrate-confluence-{{ github.ref_name }}".zip + # if: startsWith(github.ref, 'refs/tags/') \ No newline at end of file diff --git a/VERSION b/VERSION new file mode 100644 index 00000000..63eb6eac --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +dev-unversioned \ No newline at end of file diff --git a/bin/migrate-confluence b/bin/migrate-confluence index c59ddc38..3b60c13c 100755 --- a/bin/migrate-confluence +++ b/bin/migrate-confluence @@ -5,6 +5,7 @@ require __DIR__.'/../vendor/autoload.php'; use HalloWelt\MediaWiki\Lib\Migration\CliApp; use HalloWelt\MigrateConfluence\Command\CheckResult; +use HalloWelt\MigrateConfluence\Command\GetVersion; $config = [ 'file-extension-whitelist' => [ 'xml' ], @@ -38,4 +39,5 @@ $config = [ $application = new CliApp( $config ); $application->add( new CheckResult() ); +$application->add( new GetVersion() ); $application->run(); diff --git a/bin/mkversion.sh b/bin/mkversion.sh new file mode 100755 index 00000000..bce50c11 --- /dev/null +++ b/bin/mkversion.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -euo pipefail + +cd "$(dirname "$0")" + +COMMIT_HASH="$(git rev-parse HEAD)" + +case "${1:-}" in + "--clean") + printf 'dev-unversioned' > ../VERSION + ;; + "--from-env") + printf "${GITHUB_REF_NAME:-dev-no-env-$COMMIT_HASH}" > ../VERSION + ;; + "") + printf 'dev-%s' "$COMMIT_HASH" > ../VERSION + ;; + *) + echo "Usage: $(basename "$0") [--clean|--from-env]" >&2 + exit 1 + ;; +esac \ No newline at end of file diff --git a/src/Analyzer/ConfluenceAnalyzer.php b/src/Analyzer/ConfluenceAnalyzer.php index 2e3d1675..5c843371 100644 --- a/src/Analyzer/ConfluenceAnalyzer.php +++ b/src/Analyzer/ConfluenceAnalyzer.php @@ -28,6 +28,7 @@ use HalloWelt\MigrateConfluence\Utility\MigrationConfig; use HalloWelt\MigrateConfluence\Utility\TitleBuilder; use HalloWelt\MigrateConfluence\Utility\TitleValidityChecker; +use HalloWelt\MigrateConfluence\Utility\Version; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; @@ -94,6 +95,12 @@ private function initWorkspaceDB(): void { */ private function initDBLog(): void { $this->dbLog = new DBLog( $this->workspaceDB ); + $this->dbLog->addLogEntry( + 'info', + 'analyze', + __CLASS__, + sprintf( 'use version %s', Version::getVersion() ) + ); } /** diff --git a/src/Command/GetVersion.php b/src/Command/GetVersion.php new file mode 100644 index 00000000..dd7019bc --- /dev/null +++ b/src/Command/GetVersion.php @@ -0,0 +1,38 @@ +setName( 'version' ) + ->setDescription( 'Print version information' ); + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + * @return int + */ + protected function execute( InputInterface $input, OutputInterface $output ): int { + $version = Version::getVersion(); + if ( !$version ) { + $output->getErrorOutput()->writeln( 'Version information not found in composer.json' ); + return Command::FAILURE; + } + + $output->writeln( sprintf( $output->isVerbose() ? "tool: %s\nphp: %s" : '%s', $version, PHP_VERSION ) ); + + return Command::SUCCESS; + } + +} diff --git a/src/Composer/ConfluenceComposer.php b/src/Composer/ConfluenceComposer.php index 164fc87f..f6a6ef8d 100644 --- a/src/Composer/ConfluenceComposer.php +++ b/src/Composer/ConfluenceComposer.php @@ -17,6 +17,7 @@ use HalloWelt\MigrateConfluence\Utility\DBComposerDataLookup; use HalloWelt\MigrateConfluence\Utility\DBLog; use HalloWelt\MigrateConfluence\Utility\MigrationConfig; +use HalloWelt\MigrateConfluence\Utility\Version; use Symfony\Component\Console\Output\Output; class ConfluenceComposer extends ComposerBase implements IOutputAwareInterface, IDestinationPathAware { @@ -68,6 +69,12 @@ public function setDestinationPath( string $dest ): void { public function buildXML( Builder $builder ): void { $workspaceDB = new WorkspaceDB( $this->dest . '/workspace.sqlite' ); $dbLog = new DBLog( $workspaceDB ); + $dbLog->addLogEntry( + 'info', + 'compose', + __CLASS__, + sprintf( 'use version %s', Version::getVersion() ) + ); $composerDataLookup = new DBComposerDataLookup( $workspaceDB ); $deploymentInfo = new ComposerDeploymentInfo(); $processors = [ diff --git a/src/Converter/ConfluenceConverter.php b/src/Converter/ConfluenceConverter.php index aa7379e4..65f22cbc 100644 --- a/src/Converter/ConfluenceConverter.php +++ b/src/Converter/ConfluenceConverter.php @@ -88,6 +88,7 @@ use HalloWelt\MigrateConfluence\Utility\MigrationConfig; use HalloWelt\MigrateConfluence\Utility\PipeToDB; use HalloWelt\MigrateConfluence\Utility\TocMacroUsage; +use HalloWelt\MigrateConfluence\Utility\Version; use SplFileInfo; use Symfony\Component\Console\Output\Output; diff --git a/src/Extractor/ConfluenceExtractor.php b/src/Extractor/ConfluenceExtractor.php index fd2a48a6..04bacf26 100644 --- a/src/Extractor/ConfluenceExtractor.php +++ b/src/Extractor/ConfluenceExtractor.php @@ -9,6 +9,7 @@ use HalloWelt\MigrateConfluence\IDestinationPathAware; use HalloWelt\MigrateConfluence\Utility\DBLog; use HalloWelt\MigrateConfluence\Utility\MigrationConfig; +use HalloWelt\MigrateConfluence\Utility\Version; use SplFileInfo; class ConfluenceExtractor extends ExtractorBase implements IDestinationPathAware { @@ -53,6 +54,12 @@ private function initWorkspaceDB(): void { */ private function initDBLog(): void { $this->dbLog = new DBLog( $this->workspaceDB ); + $this->dbLog->addLogEntry( + 'info', + 'extract', + __CLASS__, + sprintf( 'use version %s', Version::getVersion() ) + ); } /** diff --git a/src/Utility/Version.php b/src/Utility/Version.php new file mode 100644 index 00000000..df21f105 --- /dev/null +++ b/src/Utility/Version.php @@ -0,0 +1,22 @@ + Date: Fri, 22 May 2026 09:23:29 +0200 Subject: [PATCH 2/5] remove duplicate phpunit config file --- .phpunit.xml | 8 -------- composer.json | 2 +- phpunit.xml | 4 ++-- 3 files changed, 3 insertions(+), 11 deletions(-) delete mode 100644 .phpunit.xml diff --git a/.phpunit.xml b/.phpunit.xml deleted file mode 100644 index eceb78fc..00000000 --- a/.phpunit.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - ./tests/phpunit - - - \ No newline at end of file diff --git a/composer.json b/composer.json index df6792c5..3bfcf7c3 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ }, "scripts": { "unittest": [ - "vendor/phpunit/phpunit/phpunit --configuration .phpunit.xml" + "vendor/phpunit/phpunit/phpunit --configuration phpunit.xml" ], "test": [ "parallel-lint . --exclude vendor --exclude node_modules", diff --git a/phpunit.xml b/phpunit.xml index ed6965a0..0e6f0c31 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,8 +1,8 @@ - + ./tests/phpunit - \ No newline at end of file + From dcbfd73fd593f98e3cfafc7688da17f1c05ae540 Mon Sep 17 00:00:00 2001 From: Manuel Strehl Date: Fri, 22 May 2026 09:46:06 +0200 Subject: [PATCH 3/5] add unittests for Version --- tests/phpunit/Utility/Version/VersionTest.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/phpunit/Utility/Version/VersionTest.php diff --git a/tests/phpunit/Utility/Version/VersionTest.php b/tests/phpunit/Utility/Version/VersionTest.php new file mode 100644 index 00000000..49bb7ef4 --- /dev/null +++ b/tests/phpunit/Utility/Version/VersionTest.php @@ -0,0 +1,31 @@ +assertIsString( $version ); + $this->assertNotEmpty( $version ); + } + + public function testGetVersionMatchesVersionFile(): void { + $expectedVersion = trim( file_get_contents( __DIR__ . '/../../../../VERSION' ) ); + $this->assertSame( $expectedVersion, Version::getVersion() ); + } + + public function testGetVersionIsTrimmed(): void { + $version = Version::getVersion(); + $this->assertSame( trim( $version ), $version ); + } + + public function testGetVersionIsStable(): void { + $first = Version::getVersion(); + $second = Version::getVersion(); + $this->assertSame( $first, $second ); + } +} From 1182cc77c8c2998acc5fe5ac4a9a76b9d464ec30 Mon Sep 17 00:00:00 2001 From: Manuel Strehl Date: Fri, 22 May 2026 09:56:10 +0200 Subject: [PATCH 4/5] format according to phpcs tests --- src/Command/Convert.php | 10 ++++++ src/Command/GetVersion.php | 2 +- src/Converter/ConfluenceConverter.php | 1 - src/Utility/Version.php | 34 +++++++++++-------- tests/phpunit/Utility/Version/VersionTest.php | 12 +++++++ 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/Command/Convert.php b/src/Command/Convert.php index 2c7acc48..794a5ac6 100644 --- a/src/Command/Convert.php +++ b/src/Command/Convert.php @@ -10,6 +10,7 @@ use HalloWelt\MigrateConfluence\IDestinationPathAware; use HalloWelt\MigrateConfluence\Utility\DBLog; use HalloWelt\MigrateConfluence\Utility\PipeToDB; +use HalloWelt\MigrateConfluence\Utility\Version; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -89,6 +90,15 @@ protected function execute( InputInterface $input, OutputInterface $output ): in $workers = (int)$input->getOption( 'workers' ); $isWorker = $input->hasParameterOption( '--worker' ); + if ( !$isWorker ) { + $this->dbLog->addLogEntry( + 'info', + 'convert', + __CLASS__, + sprintf( 'use version %s', Version::getVersion() ) + ); + } + if ( $workers > 1 && !$isWorker ) { return $this->spawnWorkers( $input, $output, $workers ); } diff --git a/src/Command/GetVersion.php b/src/Command/GetVersion.php index dd7019bc..012da1b8 100644 --- a/src/Command/GetVersion.php +++ b/src/Command/GetVersion.php @@ -2,10 +2,10 @@ namespace HalloWelt\MigrateConfluence\Command; +use HalloWelt\MigrateConfluence\Utility\Version; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use HalloWelt\MigrateConfluence\Utility\Version; class GetVersion extends Command { diff --git a/src/Converter/ConfluenceConverter.php b/src/Converter/ConfluenceConverter.php index 65f22cbc..aa7379e4 100644 --- a/src/Converter/ConfluenceConverter.php +++ b/src/Converter/ConfluenceConverter.php @@ -88,7 +88,6 @@ use HalloWelt\MigrateConfluence\Utility\MigrationConfig; use HalloWelt\MigrateConfluence\Utility\PipeToDB; use HalloWelt\MigrateConfluence\Utility\TocMacroUsage; -use HalloWelt\MigrateConfluence\Utility\Version; use SplFileInfo; use Symfony\Component\Console\Output\Output; diff --git a/src/Utility/Version.php b/src/Utility/Version.php index df21f105..03e1918e 100644 --- a/src/Utility/Version.php +++ b/src/Utility/Version.php @@ -2,21 +2,27 @@ namespace HalloWelt\MigrateConfluence\Utility; +/** + * provide the tool's version + */ class Version { - private static $version = null; + /** + * @var string|null deduced version + */ + private static $version = null; - public static function getVersion(): string { - if ( static::$version === null ) { - $rawVersion = file_get_contents( __DIR__ . '/../../VERSION' ); - if ( is_string( $rawVersion ) ) { - $rawVersion = trim( $rawVersion ); - } - if ( $rawVersion ) { - static::$version = $rawVersion; - } - } - return static::$version ?? 'unknown'; - } + public static function getVersion(): string { + if ( static::$version === null ) { + $rawVersion = file_get_contents( __DIR__ . '/../../VERSION' ); + if ( is_string( $rawVersion ) ) { + $rawVersion = trim( $rawVersion ); + } + if ( $rawVersion ) { + static::$version = $rawVersion; + } + } + return static::$version ?? 'unknown'; + } -} \ No newline at end of file +} diff --git a/tests/phpunit/Utility/Version/VersionTest.php b/tests/phpunit/Utility/Version/VersionTest.php index 49bb7ef4..7128f251 100644 --- a/tests/phpunit/Utility/Version/VersionTest.php +++ b/tests/phpunit/Utility/Version/VersionTest.php @@ -7,22 +7,34 @@ class VersionTest extends TestCase { + /** + * @covers \HalloWelt\MigrateConfluence\Utility\Version::getVersion + */ public function testGetVersionReturnsNonemptyString(): void { $version = Version::getVersion(); $this->assertIsString( $version ); $this->assertNotEmpty( $version ); } + /** + * @covers \HalloWelt\MigrateConfluence\Utility\Version::getVersion + */ public function testGetVersionMatchesVersionFile(): void { $expectedVersion = trim( file_get_contents( __DIR__ . '/../../../../VERSION' ) ); $this->assertSame( $expectedVersion, Version::getVersion() ); } + /** + * @covers \HalloWelt\MigrateConfluence\Utility\Version::getVersion + */ public function testGetVersionIsTrimmed(): void { $version = Version::getVersion(); $this->assertSame( trim( $version ), $version ); } + /** + * @covers \HalloWelt\MigrateConfluence\Utility\Version::getVersion + */ public function testGetVersionIsStable(): void { $first = Version::getVersion(); $second = Version::getVersion(); From 31461d319d4db20b6496629f50cd1514a3edd3de Mon Sep 17 00:00:00 2001 From: Manuel Strehl Date: Thu, 28 May 2026 11:11:21 +0200 Subject: [PATCH 5/5] note date of run in logs --- src/Analyzer/ConfluenceAnalyzer.php | 2 +- src/Command/Convert.php | 2 +- src/Composer/ConfluenceComposer.php | 2 +- src/Extractor/ConfluenceExtractor.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Analyzer/ConfluenceAnalyzer.php b/src/Analyzer/ConfluenceAnalyzer.php index 5c843371..5cad8983 100644 --- a/src/Analyzer/ConfluenceAnalyzer.php +++ b/src/Analyzer/ConfluenceAnalyzer.php @@ -99,7 +99,7 @@ private function initDBLog(): void { 'info', 'analyze', __CLASS__, - sprintf( 'use version %s', Version::getVersion() ) + sprintf( '[%s] use version %s', date( 'c' ), Version::getVersion() ) ); } diff --git a/src/Command/Convert.php b/src/Command/Convert.php index 794a5ac6..725047f4 100644 --- a/src/Command/Convert.php +++ b/src/Command/Convert.php @@ -95,7 +95,7 @@ protected function execute( InputInterface $input, OutputInterface $output ): in 'info', 'convert', __CLASS__, - sprintf( 'use version %s', Version::getVersion() ) + sprintf( '[%s] use version %s', date( 'c' ), Version::getVersion() ) ); } diff --git a/src/Composer/ConfluenceComposer.php b/src/Composer/ConfluenceComposer.php index f6a6ef8d..e59702f1 100644 --- a/src/Composer/ConfluenceComposer.php +++ b/src/Composer/ConfluenceComposer.php @@ -73,7 +73,7 @@ public function buildXML( Builder $builder ): void { 'info', 'compose', __CLASS__, - sprintf( 'use version %s', Version::getVersion() ) + sprintf( '[%s] use version %s', date( 'c' ), Version::getVersion() ) ); $composerDataLookup = new DBComposerDataLookup( $workspaceDB ); $deploymentInfo = new ComposerDeploymentInfo(); diff --git a/src/Extractor/ConfluenceExtractor.php b/src/Extractor/ConfluenceExtractor.php index 04bacf26..76d6303e 100644 --- a/src/Extractor/ConfluenceExtractor.php +++ b/src/Extractor/ConfluenceExtractor.php @@ -58,7 +58,7 @@ private function initDBLog(): void { 'info', 'extract', __CLASS__, - sprintf( 'use version %s', Version::getVersion() ) + sprintf( '[%s] use version %s', date( 'c' ), Version::getVersion() ) ); }