Skip to content

Commit

Permalink
- fixed directories
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilpiech97 committed Sep 18, 2024
1 parent 270c286 commit 762c776
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
10 changes: 7 additions & 3 deletions src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
class Version
{
public const string SCRIPTS_DIRECTORY = __DIR__ . "/scripts/";
public const string PATH_TO_VERSION_SCRIPT = "cd ../../../ && ./version/src/scripts/version.sh";
public const string PATH_TO_CHECK_SCRIPT = "cd ../../../ && ./version/src/scripts/check.sh";

public function __construct(
public bool $long = false,
public string $pathToVersionScript = self::PATH_TO_VERSION_SCRIPT,
public string $pathToCheckScript = self::PATH_TO_CHECK_SCRIPT,
) {}

public function setLong(bool $long): void
Expand All @@ -21,17 +25,17 @@ public function setLong(bool $long): void

public function generate(): string
{
return (new Process(["./check.sh"], self::SCRIPTS_DIRECTORY))->run()
return (new Process(["sh", "-c", $this->pathToCheckScript], self::SCRIPTS_DIRECTORY))->run()
? $this->getVersionBasedOnGit()
: $this->getVersionBasedOnTimestamp();
}

private function getVersionBasedOnGit(): string
{
$process = new Process(["./version.sh"], self::SCRIPTS_DIRECTORY);
$process = new Process(["sh", "-c", $this->pathToVersionScript], self::SCRIPTS_DIRECTORY);

if ($this->long) {
$process = new Process(["./version.sh", "--long"], self::SCRIPTS_DIRECTORY);
$process = new Process(["sh", "-c", "$this->pathToVersionScript --long"], self::SCRIPTS_DIRECTORY);
}

$process->mustRun();
Expand Down
23 changes: 17 additions & 6 deletions src/VersionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@

class VersionHelper
{
public static function generateShortVersion(): string
{
return (new Version())->generate();
public static function generateShortVersion(
string $pathToVersionScript = Version::PATH_TO_VERSION_SCRIPT,
string $pathToCheckScript = Version::PATH_TO_CHECK_SCRIPT,
): string {
return (new Version(
pathToVersionScript: $pathToVersionScript,
pathToCheckScript: $pathToCheckScript,
))->generate();
}

public static function generateLongVersion(): string
{
return (new Version(long: true))->generate();
public static function generateLongVersion(
string $pathToVersionScript = Version::PATH_TO_VERSION_SCRIPT,
string $pathToCheckScript = Version::PATH_TO_CHECK_SCRIPT,
): string {
return (new Version(
long: true,
pathToVersionScript: $pathToVersionScript,
pathToCheckScript: $pathToCheckScript,
))->generate();
}
}
10 changes: 8 additions & 2 deletions tests/VersionHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ class VersionHelperTest extends TestCase
{
public function testGeneratingVersionBasedOnGit(): void
{
$version = VersionHelper::generateShortVersion();
$version = VersionHelper::generateShortVersion(
pathToVersionScript: "./version.sh",
pathToCheckScript: "./check.sh",
);

$this->assertIsString($version);
$this->assertStringNotContainsString("|", $version);
}

public function testGeneratingLongVersionBasedOnGit(): void
{
$version = VersionHelper::generateLongVersion();
$version = VersionHelper::generateLongVersion(
pathToVersionScript: "./version.sh",
pathToCheckScript: "./check.sh",
);
$versionHash = trim(shell_exec("git log --format='%h' -n 1"));

$this->assertIsString($version);
Expand Down
11 changes: 9 additions & 2 deletions tests/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@ class VersionTest extends TestCase
{
public function testGeneratingVersionBasedOnGit(): void
{
$version = (new Version())->generate();
$version = (new Version(
pathToVersionScript: "./version.sh",
pathToCheckScript: "./check.sh",
))->generate();

$this->assertIsString($version);
$this->assertStringNotContainsString("|", $version);
}

public function testGeneratingLongVersionBasedOnGit(): void
{
$version = (new Version(true))->generate();
$version = (new Version(
long: true,
pathToVersionScript: "./version.sh",
pathToCheckScript: "./check.sh",
))->generate();
$versionHash = trim(shell_exec("git log --format='%h' -n 1"));

$this->assertIsString($version);
Expand Down

0 comments on commit 762c776

Please sign in to comment.