Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- directory fix #3

Merged
merged 3 commits into from
Sep 18, 2024
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
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"scripts": {
"cs": "./vendor/bin/php-cs-fixer fix --dry-run --diff --config codestyle.php",
"csf": "./vendor/bin/php-cs-fixer fix --diff --config codestyle.php",
"test": "./vendor/bin/phpunit tests --colors=always"
"test": "./vendor/bin/phpunit tests --colors=always",
"post-install-cmd": [
"chmod +x src/scripts/version.sh",
"chmod +x src/scripts/check.sh"
]
}
}
12 changes: 8 additions & 4 deletions src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@

class Version
{
public const string SCRIPTS_DIRECTORY = "src/scripts/";
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 string $pathToVersionScript = self::PATH_TO_VERSION_SCRIPT,
public string $pathToCheckScript = self::PATH_TO_CHECK_SCRIPT,
public bool $long = false,
) {}

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
16 changes: 10 additions & 6 deletions src/VersionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@

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, $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($pathToVersionScript, $pathToCheckScript, long: true))->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(
pathToVersionScript: "./version.sh",
pathToCheckScript: "./check.sh",
long: true,
))->generate();
$versionHash = trim(shell_exec("git log --format='%h' -n 1"));

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