-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix current version resolving for clients (#97)
- Loading branch information
Showing
11 changed files
with
141 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...Paysera/Bundle/ClientReleaseBundle/Service/VersionResolver/ClientAwareVersionResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Paysera/Bundle/ClientReleaseBundle/Service/VersionResolver/GitTagVersionResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...Paysera/Bundle/ClientReleaseBundle/Service/VersionResolver/PackageJsonVersionResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Paysera/Bundle/ClientReleaseBundle/Service/VersionResolver/VersionResolverInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |