Skip to content

Commit

Permalink
updated configuration and writing output action
Browse files Browse the repository at this point in the history
  • Loading branch information
rosven9856 committed Aug 15, 2024
1 parent e051f86 commit f28429a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 21 deletions.
19 changes: 9 additions & 10 deletions src/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,20 @@ public function run()



$GITHUB_OUTPUT = getenv('GITHUB_OUTPUT');
$GITHUB_OUTPUT = (string) $this->configuration->get('GITHUB_OUTPUT');

var_dump($GITHUB_OUTPUT);
exit;
if (!empty($GITHUB_OUTPUT)) {

$name = 'directory';
$value = (string) $this->configuration->get('build.directory');

$name = 'directory';
$value = (string) $this->configuration->get('build.directory');
file_put_contents($GITHUB_OUTPUT, "$name=$value\n", FILE_APPEND);

file_put_contents($GITHUB_OUTPUT, "$name=$value\n", FILE_APPEND);

$name = 'path';
$value = (string) $this->configuration->get('build.file');

$name = 'path';
$value = (string) $this->configuration->get('build.file');

file_put_contents($GITHUB_OUTPUT, "$name=$value\n", FILE_APPEND);
file_put_contents($GITHUB_OUTPUT, "$name=$value\n", FILE_APPEND);
}
}
}
17 changes: 10 additions & 7 deletions src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@
*/
public function __construct ()
{
$root = (string) getenv('GITHUB_WORKSPACE');
$GITHUB_WORKSPACE = (string) getenv('GITHUB_WORKSPACE');
$GITHUB_OUTPUT = (string) getenv('GITHUB_OUTPUT');
$dirName = (string) getenv('BUILD_DIRECTORY_NAME');
$fileName = (string) getenv('BUILD_FILE_NAME');

$root = !empty($root) ? $root : realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..');
$GITHUB_WORKSPACE = !empty($GITHUB_WORKSPACE) ? $GITHUB_WORKSPACE : realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..');
$GITHUB_OUTPUT = !empty($GITHUB_OUTPUT) ? $GITHUB_OUTPUT : $GITHUB_WORKSPACE . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'outputcmd.txt';
$dirName = !empty($dirName) ? $dirName : '.build';
$fileName = !empty($fileName) ? $fileName : 'package.zip';

$this->options = [
'root' => $root,
'GITHUB_WORKSPACE' => $GITHUB_WORKSPACE,
'GITHUB_OUTPUT' => $GITHUB_OUTPUT,
'build' => [
'directory' => $root . DIRECTORY_SEPARATOR . $dirName,
'file' => $root . DIRECTORY_SEPARATOR . $dirName . DIRECTORY_SEPARATOR . $fileName,
]
'directory' => $GITHUB_WORKSPACE . DIRECTORY_SEPARATOR . $dirName,
'file' => $GITHUB_WORKSPACE . DIRECTORY_SEPARATOR . $dirName . DIRECTORY_SEPARATOR . $fileName,
],
];
}

Expand Down Expand Up @@ -59,6 +62,6 @@ public function get (string $option): mixed
*/
public function getRootDirectory (): string
{
return (string) $this->get('root');
return (string) $this->get('GITHUB_WORKSPACE');
}
}
100 changes: 96 additions & 4 deletions tests/Configuration/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class ConfigurationTest extends TestCase
*/
private const string DEFAULT_ENV_GITHUB_WORKSPACE = '/usr/bin/app';

/**
* @var string
*/
private const string DEFAULT_ENV_GITHUB_OUTPUT = '/usr/bin/app/var/outputcmd.txt';

/**
* @var string
*/
Expand All @@ -29,6 +34,11 @@ class ConfigurationTest extends TestCase
*/
private const string OTHER_ENV_GITHUB_WORKSPACE = '/app';

/**
* @var string
*/
private const string OTHER_ENV_GITHUB_OUTPUT = '/usr/bin/app/var/otheroutputcmd.txt';

/**
* @var string
*/
Expand All @@ -53,27 +63,67 @@ protected function setUp(): void
* @covers Configuration::get
* @return void
*/
public function testCheckDefaultOptionRoot()
public function testCheckDefaultOptionGitHubWorkspace(): void
{
putenv('GITHUB_WORKSPACE=' . self::DEFAULT_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::DEFAULT_ENV_GITHUB_OUTPUT);
putenv('BUILD_DIRECTORY_NAME=' . self::DEFAULT_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::DEFAULT_ENV_BUILD_FILE_NAME);

$configuration = new Configuration();

$this->assertEquals(
$configuration->get('root'),
$configuration->get('GITHUB_WORKSPACE'),
self::DEFAULT_ENV_GITHUB_WORKSPACE
);
}

/**
* @covers Configuration::get
* @return void
*/
public function testCheckDefaultGetRootDirectory(): void
{
putenv('GITHUB_WORKSPACE=' . self::DEFAULT_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::DEFAULT_ENV_GITHUB_OUTPUT);
putenv('BUILD_DIRECTORY_NAME=' . self::DEFAULT_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::DEFAULT_ENV_BUILD_FILE_NAME);

$configuration = new Configuration();

$this->assertEquals(
$configuration->getRootDirectory(),
self::DEFAULT_ENV_GITHUB_WORKSPACE
);
}

/**
* @covers Configuration::get
* @return void
*/
public function testCheckDefaultOptionGitHubOutput(): void
{
putenv('GITHUB_WORKSPACE=' . self::DEFAULT_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::DEFAULT_ENV_GITHUB_OUTPUT);
putenv('BUILD_DIRECTORY_NAME=' . self::DEFAULT_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::DEFAULT_ENV_BUILD_FILE_NAME);

$configuration = new Configuration();

$this->assertEquals(
$configuration->get('GITHUB_OUTPUT'),
self::DEFAULT_ENV_GITHUB_OUTPUT
);
}

/**
* @covers Configuration::get
* @return void
*/
public function testCheckDefaultOptionBuildDirectory()
{
putenv('GITHUB_WORKSPACE=' . self::DEFAULT_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::DEFAULT_ENV_GITHUB_OUTPUT);
putenv('BUILD_DIRECTORY_NAME=' . self::DEFAULT_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::DEFAULT_ENV_BUILD_FILE_NAME);

Expand All @@ -92,6 +142,7 @@ public function testCheckDefaultOptionBuildDirectory()
public function testCheckDefaultOptionBuildFile()
{
putenv('GITHUB_WORKSPACE=' . self::DEFAULT_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::DEFAULT_ENV_GITHUB_OUTPUT);
putenv('BUILD_DIRECTORY_NAME=' . self::DEFAULT_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::DEFAULT_ENV_BUILD_FILE_NAME);

Expand All @@ -108,27 +159,67 @@ public function testCheckDefaultOptionBuildFile()
* @covers Configuration::get
* @return void
*/
public function testCheckOtherOptionRoot()
public function testCheckOtherOptionOptionGitHubOutput()
{
putenv('GITHUB_WORKSPACE=' . self::OTHER_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::OTHER_ENV_GITHUB_OUTPUT);
putenv('BUILD_DIRECTORY_NAME=' . self::OTHER_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::OTHER_ENV_BUILD_FILE_NAME);

$configuration = new Configuration();

$this->assertEquals(
$configuration->get('root'),
$configuration->get('GITHUB_WORKSPACE'),
self::OTHER_ENV_GITHUB_WORKSPACE
);
}

/**
* @covers Configuration::get
* @return void
*/
public function testCheckOtherGetRootDirectory(): void
{
putenv('GITHUB_WORKSPACE=' . self::OTHER_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::OTHER_ENV_GITHUB_OUTPUT);
putenv('BUILD_DIRECTORY_NAME=' . self::OTHER_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::OTHER_ENV_BUILD_FILE_NAME);

$configuration = new Configuration();

$this->assertEquals(
$configuration->getRootDirectory(),
self::OTHER_ENV_GITHUB_WORKSPACE
);
}

/**
* @covers Configuration::get
* @return void
*/
public function testCheckOtherOptionGitHubOutput(): void
{
putenv('GITHUB_WORKSPACE=' . self::OTHER_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::OTHER_ENV_GITHUB_OUTPUT);
putenv('BUILD_DIRECTORY_NAME=' . self::OTHER_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::OTHER_ENV_BUILD_FILE_NAME);

$configuration = new Configuration();

$this->assertEquals(
$configuration->get('GITHUB_OUTPUT'),
self::OTHER_ENV_GITHUB_OUTPUT
);
}

/**
* @covers Configuration::get
* @return void
*/
public function testCheckOtherOptionBuildDirectory()
{
putenv('GITHUB_WORKSPACE=' . self::OTHER_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::OTHER_ENV_GITHUB_OUTPUT);
putenv('BUILD_DIRECTORY_NAME=' . self::OTHER_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::OTHER_ENV_BUILD_FILE_NAME);

Expand All @@ -147,6 +238,7 @@ public function testCheckOtherOptionBuildDirectory()
public function testCheckOtherOptionBuildFile()
{
putenv('GITHUB_WORKSPACE=' . self::OTHER_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::OTHER_ENV_GITHUB_OUTPUT);
putenv('BUILD_DIRECTORY_NAME=' . self::OTHER_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::OTHER_ENV_BUILD_FILE_NAME);

Expand Down

0 comments on commit f28429a

Please sign in to comment.