Skip to content

Commit

Permalink
Fix current version resolving for clients (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
wkiril authored Jan 18, 2021
1 parent ba4f4f9 commit 145e3d4
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 47 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 11.3.1
### Fixed
- Wrong new release version for javascript clients

## 11.3.0
### Changed
- Generate clients with `"evp/money": "^1.0 || ^2.0"`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
class="Paysera\Bundle\ClientReleaseBundle\Service\ReleaseStep\IncreasePackageJsonVersionStep">
<argument type="service" id="paysera_client_release.semantic_version_manipulator"/>
<argument type="service" id="paysera_client_release.package_json_helper"/>
<argument type="service" id="paysera_client_release.version_resolver.package_json"/>
<tag name="paysera_client_release.release_step" type="javascript" position="35"/>
</service>

Expand All @@ -43,6 +44,7 @@
<argument type="service" id="paysera_client_release.changelog_parser.parser"/>
<argument type="service" id="paysera_client_release.changelog_parser.dumper"/>
<argument type="service" id="paysera_client_release.semantic_version_manipulator"/>
<argument type="service" id="paysera_client_release.version_resolver.client_aware_version_resolver"/>
<tag name="paysera_client_release.release_step" type="javascript" position="40"/>
<tag name="paysera_client_release.release_step" type="php" position="40"/>
</service>
Expand Down Expand Up @@ -95,6 +97,7 @@
class="Paysera\Bundle\ClientReleaseBundle\Service\ReleaseStep\PushTagToRepositoryStep">
<argument type="service" id="paysera_client_release.semantic_version_manipulator"/>
<argument type="service" id="paysera_client_release.repository_resolver"/>
<argument type="service" id="paysera_client_release.version_resolver.client_aware_version_resolver"/>
<tag name="paysera_client_release.release_step" type="javascript" position="80"/>
<tag name="paysera_client_release.release_step" type="php" position="80"/>
</service>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

<service id="paysera_client_release.semantic_version_manipulator"
class="Paysera\Bundle\ClientReleaseBundle\Service\SemanticVersionManipulator">
<argument type="service" id="paysera_client_release.package_json_helper"/>
</service>

<service id="paysera_client_release.env_helper"
Expand Down Expand Up @@ -55,5 +54,20 @@
<argument type="service" id="paysera_client_release.changelog_parser.value_extractor"/>
<argument type="service" id="paysera_client_release.changelog_parser.parser"/>
</service>

<service id="paysera_client_release.version_resolver.git_tag"
class="Paysera\Bundle\ClientReleaseBundle\Service\VersionResolver\GitTagVersionResolver">
</service>

<service id="paysera_client_release.version_resolver.package_json"
class="Paysera\Bundle\ClientReleaseBundle\Service\VersionResolver\PackageJsonVersionResolver">
<argument type="service" id="paysera_client_release.package_json_helper"/>
</service>

<service id="paysera_client_release.version_resolver.client_aware_version_resolver"
class="Paysera\Bundle\ClientReleaseBundle\Service\VersionResolver\ClientAwareVersionResolver">
<argument type="service" id="paysera_client_release.version_resolver.git_tag"/>
<argument type="service" id="paysera_client_release.version_resolver.package_json"/>
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@
use Paysera\Bundle\ClientReleaseBundle\Entity\ReleaseStepData;
use Paysera\Bundle\ClientReleaseBundle\Service\PackageJsonHelper;
use Paysera\Bundle\ClientReleaseBundle\Service\SemanticVersionManipulator;
use Paysera\Bundle\ClientReleaseBundle\Service\VersionResolver\PackageJsonVersionResolver;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class IncreasePackageJsonVersionStep implements ReleaseStepInterface
{
private $versionManipulator;
private $packageJsonHelper;
private $packageJsonVersionResolver;

public function __construct(
SemanticVersionManipulator $versionManipulator,
PackageJsonHelper $packageJsonHelper
PackageJsonHelper $packageJsonHelper,
PackageJsonVersionResolver $packageJsonVersionResolver
) {
$this->versionManipulator = $versionManipulator;
$this->packageJsonHelper = $packageJsonHelper;
$this->packageJsonVersionResolver = $packageJsonVersionResolver;
}

public function processStep(ReleaseStepData $releaseStepData, InputInterface $input, OutputInterface $output)
Expand All @@ -31,7 +35,7 @@ public function processStep(ReleaseStepData $releaseStepData, InputInterface $in
}

$packageJson['version'] = $this->versionManipulator->increase(
$this->versionManipulator->resolveCurrentVersion($releaseStepData),
$this->packageJsonVersionResolver->resolveCurrentVersion($releaseStepData),
$releaseStepData->getReleaseData()->getVersion()
);
$packageJson['dependencies'] = $generatedPackageJson['dependencies'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Paysera\Bundle\ClientReleaseBundle\Exception\ReleaseCycleException;
use Paysera\Bundle\ClientReleaseBundle\Service\RepositoryResolver;
use Paysera\Bundle\ClientReleaseBundle\Service\SemanticVersionManipulator;
use Paysera\Bundle\ClientReleaseBundle\Service\VersionResolver\VersionResolverInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;
Expand All @@ -15,13 +16,16 @@ class PushTagToRepositoryStep implements ReleaseStepInterface
{
private $versionManipulator;
private $repositoryResolver;
private $versionResolver;

public function __construct(
SemanticVersionManipulator $versionManipulator,
RepositoryResolver $repositoryResolver
RepositoryResolver $repositoryResolver,
VersionResolverInterface $versionResolver
) {
$this->versionManipulator = $versionManipulator;
$this->repositoryResolver = $repositoryResolver;
$this->versionResolver = $versionResolver;
}

public function processStep(ReleaseStepData $releaseStepData, InputInterface $input, OutputInterface $output)
Expand All @@ -33,16 +37,10 @@ public function processStep(ReleaseStepData $releaseStepData, InputInterface $in
}

$repositoryDir = $releaseStepData->getTempDir() . '/' . CloneRepositoryStep::TARGET_DIR;
$currentVersion = $this->versionManipulator->resolveCurrentVersion($releaseStepData);
if ($currentVersion === null) {
throw new ReleaseCycleException(sprintf(
'Failed to get latest tag from git for Api "%s" "%s" Client',
$releaseStepData->getApiConfig()->getApiName(),
$releaseStepData->getClientDefinition()->getClientType()
));
}

$tag = $this->versionManipulator->increase($currentVersion, $releaseStepData->getReleaseData()->getVersion());
$tag = $this->versionManipulator->increase(
$this->versionResolver->resolveCurrentVersion($releaseStepData),
$releaseStepData->getReleaseData()->getVersion()
);
$pushProcess = new Process(
sprintf('git tag %s -am "" && git push --tags', $tag),
$repositoryDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Paysera\Bundle\ClientReleaseBundle\Entity\ReleaseStepData;
use Paysera\Bundle\ClientReleaseBundle\Exception\ReleaseCycleException;
use Paysera\Bundle\ClientReleaseBundle\Service\VersionResolver\VersionResolverInterface;
use Paysera\Bundle\ClientReleaseBundle\Service\SemanticVersionManipulator;
use Paysera\Component\ChangelogParser\Entity\Changelog;
use Paysera\Component\ChangelogParser\Entity\VersionInfo;
Expand All @@ -20,15 +21,18 @@ class UpdateChangelogStep implements ReleaseStepInterface
private $parser;
private $dumper;
private $versionManipulator;
private $versionResolver;

public function __construct(
ChangelogParser $parser,
ChangelogDumper $dumper,
SemanticVersionManipulator $versionManipulator
SemanticVersionManipulator $versionManipulator,
VersionResolverInterface $versionResolver
) {
$this->parser = $parser;
$this->dumper = $dumper;
$this->versionManipulator = $versionManipulator;
$this->versionResolver = $versionResolver;
}

public function processStep(ReleaseStepData $releaseStepData, InputInterface $input, OutputInterface $output)
Expand Down Expand Up @@ -74,9 +78,8 @@ public function processStep(ReleaseStepData $releaseStepData, InputInterface $in

private function buildVersionInfo(ReleaseStepData $releaseStepData): VersionInfo
{
$currentVersion = $this->versionManipulator->resolveCurrentVersion($releaseStepData);
$futureVersion = $this->versionManipulator->increase(
$currentVersion,
$this->versionResolver->resolveCurrentVersion($releaseStepData),
$releaseStepData->getReleaseData()->getVersion()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,12 @@

namespace Paysera\Bundle\ClientReleaseBundle\Service;

use Paysera\Bundle\ClientReleaseBundle\Entity\ReleaseStepData;
use Paysera\Bundle\ClientReleaseBundle\Service\ReleaseStep\CloneRepositoryStep;
use Symfony\Component\Process\Process;

class SemanticVersionManipulator
{
const VERSION_MAJOR = 'major';
const VERSION_MINOR = 'minor';
const VERSION_PATCH = 'patch';

const VERSION_DEFAULT = '0.0.0';

private $packageJsonHelper;

public function __construct(PackageJsonHelper $packageJsonHelper)
{
$this->packageJsonHelper = $packageJsonHelper;
}

public function increase(string $current, string $constraint)
{
if (preg_match('#(\d+)\.(\d+)\.(\d+)#', $current, $matches) !== 1) {
Expand All @@ -38,21 +25,4 @@ public function increase(string $current, string $constraint)
return null;
}
}

public function resolveCurrentVersion(ReleaseStepData $releaseStepData)
{
$sourceDir = $releaseStepData->getTempDir() . '/' . CloneRepositoryStep::TARGET_DIR;
$process = new Process('git describe --tags', $sourceDir);

if ($process->run() === 0) {
return trim($process->getOutput());
}

$packageJsonVersion = $this->packageJsonHelper->getPackageVersion($releaseStepData);
if ($packageJsonVersion === null) {
return self::VERSION_DEFAULT;
}

return $packageJsonVersion;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Paysera\Bundle\ClientReleaseBundle\Service\VersionResolver;

use Paysera\Bundle\ClientReleaseBundle\Entity\JavascriptClientDefinition;
use Paysera\Bundle\ClientReleaseBundle\Entity\ReleaseStepData;

class ClientAwareVersionResolver implements VersionResolverInterface
{
private $gitTagVersionResolver;
private $packageJsonVersionResolver;

public function __construct(
GitTagVersionResolver $gitTagVersionResolver,
PackageJsonVersionResolver $packageJsonVersionResolver
) {
$this->gitTagVersionResolver = $gitTagVersionResolver;
$this->packageJsonVersionResolver = $packageJsonVersionResolver;
}

public function resolveCurrentVersion(ReleaseStepData $releaseStepData): string
{
if ($releaseStepData->getClientDefinition() instanceof JavascriptClientDefinition) {
return $this->packageJsonVersionResolver->resolveCurrentVersion($releaseStepData);
}

return $this->gitTagVersionResolver->resolveCurrentVersion($releaseStepData);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Paysera\Bundle\ClientReleaseBundle\Service\VersionResolver;

use Paysera\Bundle\ClientReleaseBundle\Entity\ReleaseStepData;
use Paysera\Bundle\ClientReleaseBundle\Service\ReleaseStep\CloneRepositoryStep;
use Symfony\Component\Process\Process;

class GitTagVersionResolver implements VersionResolverInterface
{
public function resolveCurrentVersion(ReleaseStepData $releaseStepData): string
{
$sourceDir = $releaseStepData->getTempDir() . '/' . CloneRepositoryStep::TARGET_DIR;
$process = new Process('git describe --tags', $sourceDir);

if ($process->run() === 0) {
return trim($process->getOutput());
}

return VersionResolverInterface::VERSION_DEFAULT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Paysera\Bundle\ClientReleaseBundle\Service\VersionResolver;

use Paysera\Bundle\ClientReleaseBundle\Entity\ReleaseStepData;
use Paysera\Bundle\ClientReleaseBundle\Service\PackageJsonHelper;

class PackageJsonVersionResolver implements VersionResolverInterface
{
private $packageJsonHelper;

public function __construct(PackageJsonHelper $packageJsonHelper)
{
$this->packageJsonHelper = $packageJsonHelper;
}

public function resolveCurrentVersion(ReleaseStepData $releaseStepData): string
{
$packageJsonVersion = $this->packageJsonHelper->getPackageVersion($releaseStepData);

if ($packageJsonVersion !== null) {
return $packageJsonVersion;
}

return VersionResolverInterface::VERSION_DEFAULT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Paysera\Bundle\ClientReleaseBundle\Service\VersionResolver;

use Paysera\Bundle\ClientReleaseBundle\Entity\ReleaseStepData;

interface VersionResolverInterface
{
const VERSION_DEFAULT = '0.0.0';

public function resolveCurrentVersion(ReleaseStepData $releaseStepData): string;
}

0 comments on commit 145e3d4

Please sign in to comment.