Skip to content

Commit

Permalink
Merge pull request #3 from rosven9856/0.1.3
Browse files Browse the repository at this point in the history
0.1.3
rosven9856 authored Aug 21, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 8a53c51 + e1b7334 commit 107827e
Showing 6 changed files with 489 additions and 415 deletions.
68 changes: 34 additions & 34 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -40,23 +40,23 @@ jobs:
tools: composer:v2
coverage: none
- run: composer validate --strict --ansi
# composer-require-checker:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# php:
# - 8.3
# steps:
# - uses: actions/checkout@v4
# - uses: shivammathur/setup-php@v2
# with:
# php-version: ${{ matrix.php }}
# tools: composer:v2
# coverage: none
# - uses: ramsey/composer-install@v2
# with:
# composer-options: --optimize-autoloader
# - run: composer require-checker
composer-require-checker:
runs-on: ubuntu-latest
strategy:
matrix:
php:
- 8.3
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none
- uses: ramsey/composer-install@v2
with:
composer-options: --optimize-autoloader
- run: composer require-checker
composer-unused:
runs-on: ubuntu-latest
strategy:
@@ -91,23 +91,23 @@ jobs:
with:
composer-options: --optimize-autoloader
- run: composer normalize --dry-run --diff --ansi
# php-cs-fixer:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# php:
# - 8.3
# steps:
# - uses: actions/checkout@v4
# - uses: shivammathur/setup-php@v2
# with:
# php-version: ${{ matrix.php }}
# tools: composer:v2, cs2pr
# coverage: none
# - uses: ramsey/composer-install@v2
# with:
# composer-options: --optimize-autoloader
# - run: composer fixcs -- --dry-run --diff --format=checkstyle --ansi | cs2pr
php-cs-fixer:
runs-on: ubuntu-latest
strategy:
matrix:
php:
- 8.3
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2, cs2pr
coverage: none
- uses: ramsey/composer-install@v2
with:
composer-options: --optimize-autoloader
- run: composer fixcs -- --dry-run --diff --format=checkstyle --ansi | cs2pr
rector:
runs-on: ubuntu-latest
strategy:
6 changes: 4 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -2,9 +2,11 @@

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PHPyh\CodingStandard\PhpCsFixerCodingStandard;

$finder = PhpCsFixer\Finder::create()
$finder = Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
@@ -16,7 +18,7 @@
'benchmark.php',
]);

$config = (new PhpCsFixer\Config())
$config = (new Config())
->setFinder($finder)
->setCacheFile(__DIR__ . '/var/.php-cs-fixer.cache');

679 changes: 388 additions & 291 deletions composer.lock

Large diffs are not rendered by default.

32 changes: 11 additions & 21 deletions src/Action.php
Original file line number Diff line number Diff line change
@@ -4,28 +4,24 @@

namespace App;

use Automattic\IgnoreFile;
use App\Configuration\Configuration;
use Automattic\IgnoreFile;

class Action
final readonly class Action
{
protected Configuration $configuration;
private Configuration $configuration;

/**
*
*/
public function __construct()
{
$this->configuration = new Configuration();
}

/**
* @return void
* @throws \Exception
*/
public function run()
public function run(): void
{
if (!extension_loaded('zip')) {
if (!\extension_loaded('zip')) {
throw new \Exception('ZIP extension is not loaded');
}

@@ -37,7 +33,7 @@ public function run()

// rights

mkdir($directory, 0755, true);
mkdir($directory, 0o755, true);

$ignore = new IgnoreFile();

@@ -50,24 +46,22 @@ public function run()

$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($rootDirectory),
\RecursiveIteratorIterator::CHILD_FIRST
\RecursiveIteratorIterator::CHILD_FIRST,
);

foreach ($iterator as $path) {

/**
* @var \SplFileInfo $path
*/
if ($path->getBasename() === '.gitignore') {
$ignore->add(
file_get_contents($path->getRealPath()),
dirname($path->getRealPath()) . '/'
\dirname($path->getRealPath()) . '/',
);
}
}

foreach ($iterator as $path) {

/**
* @var \SplFileInfo $path
*/
@@ -76,28 +70,24 @@ public function run()
}

if (!$ignore->ignores($path->getPathname())) {
$zip->addFile($path->getPathname(), str_replace($rootDirectory . DIRECTORY_SEPARATOR, '', $path->getPathname()));
$zip->addFile($path->getPathname(), str_replace($rootDirectory . \DIRECTORY_SEPARATOR, '', $path->getPathname()));
}
}

$zip->close();



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

if (!empty($GITHUB_OUTPUT)) {

$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');

file_put_contents($GITHUB_OUTPUT, "$name=$value\n", FILE_APPEND);
file_put_contents($GITHUB_OUTPUT, "{$name}={$value}\n", FILE_APPEND);
}
}
}
23 changes: 8 additions & 15 deletions src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
@@ -6,38 +6,34 @@

final readonly class Configuration
{
protected array $options;
private array $options;

/**
* @use
*/
public function __construct ()
public function __construct()
{
$GITHUB_WORKSPACE = (string) getenv('GITHUB_WORKSPACE');
$GITHUB_OUTPUT = (string) getenv('GITHUB_OUTPUT');
$dirName = (string) getenv('BUILD_DIRECTORY_NAME');
$fileName = (string) getenv('BUILD_FILE_NAME');

$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';
$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 = [
'GITHUB_WORKSPACE' => $GITHUB_WORKSPACE,
'GITHUB_OUTPUT' => $GITHUB_OUTPUT,
'build' => [
'directory' => $GITHUB_WORKSPACE . DIRECTORY_SEPARATOR . $dirName,
'file' => $GITHUB_WORKSPACE . DIRECTORY_SEPARATOR . $dirName . DIRECTORY_SEPARATOR . $fileName,
'directory' => $GITHUB_WORKSPACE . \DIRECTORY_SEPARATOR . $dirName,
'file' => $GITHUB_WORKSPACE . \DIRECTORY_SEPARATOR . $dirName . \DIRECTORY_SEPARATOR . $fileName,
],
];
}

/**
* @param string $option
* @return mixed
*/
public function get (string $option): mixed
public function get(string $option): mixed
{
$keys = explode('.', $option);
$target = $this->options;
@@ -57,10 +53,7 @@ public function get (string $option): mixed
return $target;
}

/**
* @return string
*/
public function getRootDirectory (): string
public function getRootDirectory(): string
{
return (string) $this->get('GITHUB_WORKSPACE');
}
96 changes: 44 additions & 52 deletions tests/Configuration/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

declare(strict_types=1);

namespace App\Configuration;

use PHPUnit\Framework\TestCase;

/**
* @uses Configuration
* @uses \Configuration
*/
class ConfigurationTest extends TestCase
final class ConfigurationTest extends TestCase
{
/**
* @var string
@@ -49,19 +51,18 @@ class ConfigurationTest extends TestCase
*/
private const string OTHER_ENV_BUILD_FILE_NAME = 'build_file.zip';

//protected Configuration $configuration;
// protected Configuration $configuration;

#[\Override]
protected function setUp(): void
{
//putenv('GITHUB_WORKSPACE=' . self::DEFAULT_ENV_GITHUB_WORKSPACE);
// putenv('GITHUB_WORKSPACE=' . self::DEFAULT_ENV_GITHUB_WORKSPACE);

//$this->configuration = new Configuration();
// $this->configuration = new Configuration();
}

/**
* @covers Configuration::get
* @return void
* @covers \Configuration::get
*/
public function testCheckDefaultOptionGitHubWorkspace(): void
{
@@ -72,15 +73,14 @@ public function testCheckDefaultOptionGitHubWorkspace(): void

$configuration = new Configuration();

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

/**
* @covers Configuration::get
* @return void
* @covers \Configuration::get
*/
public function testCheckDefaultGetRootDirectory(): void
{
@@ -91,15 +91,14 @@ public function testCheckDefaultGetRootDirectory(): void

$configuration = new Configuration();

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

/**
* @covers Configuration::get
* @return void
* @covers \Configuration::get
*/
public function testCheckDefaultOptionGitHubOutput(): void
{
@@ -110,17 +109,16 @@ public function testCheckDefaultOptionGitHubOutput(): void

$configuration = new Configuration();

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

/**
* @covers Configuration::get
* @return void
* @covers \Configuration::get
*/
public function testCheckDefaultOptionBuildDirectory()
public function testCheckDefaultOptionBuildDirectory(): void
{
putenv('GITHUB_WORKSPACE=' . self::DEFAULT_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::DEFAULT_ENV_GITHUB_OUTPUT);
@@ -129,17 +127,16 @@ public function testCheckDefaultOptionBuildDirectory()

$configuration = new Configuration();

$this->assertEquals(
self::assertEquals(
$configuration->get('build.directory'),
self::DEFAULT_ENV_GITHUB_WORKSPACE . DIRECTORY_SEPARATOR . self::DEFAULT_ENV_BUILD_DIRECTORY_NAME
self::DEFAULT_ENV_GITHUB_WORKSPACE . \DIRECTORY_SEPARATOR . self::DEFAULT_ENV_BUILD_DIRECTORY_NAME,
);
}

/**
* @covers Configuration::get
* @return void
* @covers \Configuration::get
*/
public function testCheckDefaultOptionBuildFile()
public function testCheckDefaultOptionBuildFile(): void
{
putenv('GITHUB_WORKSPACE=' . self::DEFAULT_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::DEFAULT_ENV_GITHUB_OUTPUT);
@@ -148,18 +145,17 @@ public function testCheckDefaultOptionBuildFile()

$configuration = new Configuration();

$this->assertEquals(
self::assertEquals(
$configuration->get('build.file'),
self::DEFAULT_ENV_GITHUB_WORKSPACE . DIRECTORY_SEPARATOR . self::DEFAULT_ENV_BUILD_DIRECTORY_NAME .
DIRECTORY_SEPARATOR . self::DEFAULT_ENV_BUILD_FILE_NAME
self::DEFAULT_ENV_GITHUB_WORKSPACE . \DIRECTORY_SEPARATOR . self::DEFAULT_ENV_BUILD_DIRECTORY_NAME .
\DIRECTORY_SEPARATOR . self::DEFAULT_ENV_BUILD_FILE_NAME,
);
}

/**
* @covers Configuration::get
* @return void
* @covers \Configuration::get
*/
public function testCheckOtherOptionOptionGitHubOutput()
public function testCheckOtherOptionOptionGitHubOutput(): void
{
putenv('GITHUB_WORKSPACE=' . self::OTHER_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::OTHER_ENV_GITHUB_OUTPUT);
@@ -168,15 +164,14 @@ public function testCheckOtherOptionOptionGitHubOutput()

$configuration = new Configuration();

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

/**
* @covers Configuration::get
* @return void
* @covers \Configuration::get
*/
public function testCheckOtherGetRootDirectory(): void
{
@@ -187,15 +182,14 @@ public function testCheckOtherGetRootDirectory(): void

$configuration = new Configuration();

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

/**
* @covers Configuration::get
* @return void
* @covers \Configuration::get
*/
public function testCheckOtherOptionGitHubOutput(): void
{
@@ -206,17 +200,16 @@ public function testCheckOtherOptionGitHubOutput(): void

$configuration = new Configuration();

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

/**
* @covers Configuration::get
* @return void
* @covers \Configuration::get
*/
public function testCheckOtherOptionBuildDirectory()
public function testCheckOtherOptionBuildDirectory(): void
{
putenv('GITHUB_WORKSPACE=' . self::OTHER_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::OTHER_ENV_GITHUB_OUTPUT);
@@ -225,17 +218,16 @@ public function testCheckOtherOptionBuildDirectory()

$configuration = new Configuration();

$this->assertEquals(
self::assertEquals(
$configuration->get('build.directory'),
self::OTHER_ENV_GITHUB_WORKSPACE . DIRECTORY_SEPARATOR . self::OTHER_ENV_BUILD_DIRECTORY_NAME
self::OTHER_ENV_GITHUB_WORKSPACE . \DIRECTORY_SEPARATOR . self::OTHER_ENV_BUILD_DIRECTORY_NAME,
);
}

/**
* @covers Configuration::get
* @return void
* @covers \Configuration::get
*/
public function testCheckOtherOptionBuildFile()
public function testCheckOtherOptionBuildFile(): void
{
putenv('GITHUB_WORKSPACE=' . self::OTHER_ENV_GITHUB_WORKSPACE);
putenv('GITHUB_OUTPUT=' . self::OTHER_ENV_GITHUB_OUTPUT);
@@ -244,10 +236,10 @@ public function testCheckOtherOptionBuildFile()

$configuration = new Configuration();

$this->assertEquals(
self::assertEquals(
$configuration->get('build.file'),
self::OTHER_ENV_GITHUB_WORKSPACE . DIRECTORY_SEPARATOR . self::OTHER_ENV_BUILD_DIRECTORY_NAME .
DIRECTORY_SEPARATOR . self::OTHER_ENV_BUILD_FILE_NAME
self::OTHER_ENV_GITHUB_WORKSPACE . \DIRECTORY_SEPARATOR . self::OTHER_ENV_BUILD_DIRECTORY_NAME .
\DIRECTORY_SEPARATOR . self::OTHER_ENV_BUILD_FILE_NAME,
);
}
}

0 comments on commit 107827e

Please sign in to comment.