Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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/')
8 changes: 0 additions & 8 deletions .phpunit.xml

This file was deleted.

1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev-unversioned
2 changes: 2 additions & 0 deletions bin/migrate-confluence
Original file line number Diff line number Diff line change
Expand Up @@ -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' ],
Expand Down Expand Up @@ -38,4 +39,5 @@ $config = [

$application = new CliApp( $config );
$application->add( new CheckResult() );
$application->add( new GetVersion() );
$application->run();
23 changes: 23 additions & 0 deletions bin/mkversion.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="Converter">
<testsuite name="all">
<directory suffix="Test.php">./tests/phpunit</directory>
</testsuite>
</testsuites>
</phpunit>
</phpunit>
7 changes: 7 additions & 0 deletions src/Analyzer/ConfluenceAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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( '[%s] use version %s', date( 'c' ), Version::getVersion() )
);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/Command/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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( '[%s] use version %s', date( 'c' ), Version::getVersion() )
);
}

if ( $workers > 1 && !$isWorker ) {
return $this->spawnWorkers( $input, $output, $workers );
}
Expand Down
38 changes: 38 additions & 0 deletions src/Command/GetVersion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

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;

class GetVersion extends Command {

/**
* @return void
*/
protected function configure(): void {
$this
->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;
}

}
7 changes: 7 additions & 0 deletions src/Composer/ConfluenceComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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( '[%s] use version %s', date( 'c' ), Version::getVersion() )
);
$composerDataLookup = new DBComposerDataLookup( $workspaceDB );
$deploymentInfo = new ComposerDeploymentInfo();
$processors = [
Expand Down
7 changes: 7 additions & 0 deletions src/Extractor/ConfluenceExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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( '[%s] use version %s', date( 'c' ), Version::getVersion() )
);
}

/**
Expand Down
28 changes: 28 additions & 0 deletions src/Utility/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace HalloWelt\MigrateConfluence\Utility;

/**
* provide the tool's version
*/
class Version {

/**
* @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';
}

}
43 changes: 43 additions & 0 deletions tests/phpunit/Utility/Version/VersionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace HalloWelt\MigrateConfluence\Tests\Utility;

use HalloWelt\MigrateConfluence\Utility\Version;
use PHPUnit\Framework\TestCase;

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();
$this->assertSame( $first, $second );
}
}
Loading