Skip to content

Commit

Permalink
Merge pull request #2 from rosven9856/0.1.0
Browse files Browse the repository at this point in the history
0.1.0
  • Loading branch information
rosven9856 authored Aug 16, 2024
2 parents 7629370 + 5f41ac9 commit 8a53c51
Show file tree
Hide file tree
Showing 15 changed files with 431 additions and 52 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.github
var
vendor
.build
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: tests
on:
pull_request: ~
push:
branches: ['*.*.x']
branches: ['*.*.*']

env:
BRANCH: ${{ github.head_ref || github.ref_name }}
Expand Down
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.idea
/.env
/vendor
.git
.idea
.env
vendor
.build
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG PHP_VERSION=8.3.7-1
ARG PHP_VERSION=8.3.10-1

FROM rosven9856/php:$PHP_VERSION

Expand All @@ -20,7 +20,4 @@ VOLUME ["/usr/bin/app"]

USER php

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

# CMD ["php", "-f", "/usr/bin/app/app.php"]
CMD ["php", "-f", "/usr/bin/app/app.php"]
56 changes: 51 additions & 5 deletions README.md

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions action.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ARG PHP_VERSION=8.3.10-1

FROM rosven9856/php:$PHP_VERSION

COPY . /usr/bin/app
WORKDIR /usr/bin/app

RUN composer install

VOLUME ["/usr/bin/app"]

ENTRYPOINT ["php", "-f", "/usr/bin/app/app.php"]
18 changes: 13 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
name: "Composer package build"
description: "Composer package build from repository using GitHub Actions"
name: "Composer package action"
description: "With this GitHub Action, you can build a package for the PHP Composer package manager."
inputs:
BUILD_DIRECTORY_NAME:
description: "build directory name"
description: "The name of the directory for package building"
default: ".build"
BUILD_FILE_NAME:
description: "package file name"
description: "The name of the built package file"
default: "package.zip"
outputs:
directory:
description: 'The path to the building directory'
path:
description: 'The path to the compiled package archive'
runs:
using: "docker"
image: "Dockerfile"
image: "action.Dockerfile"
args:
- ${{ inputs.BUILD_DIRECTORY_NAME }}
- ${{ inputs.BUILD_FILE_NAME }}
branding:
icon: 'package'
color: 'purple'
2 changes: 0 additions & 2 deletions app.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

require __DIR__ . '/vendor/autoload.php';

const ROOT = __DIR__;

try {
$core = new App\Action();
$core->run();
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
],
"require": {
"php": "^8.3",
"ext-zip": "*"
"ext-zip": "*",
"automattic/ignorefile": "^2.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.42",
Expand Down
52 changes: 50 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions entrypoint.sh

This file was deleted.

2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
]);
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_83,
DowngradeLevelSetList::DOWN_TO_PHP_81,
// DowngradeLevelSetList::DOWN_TO_PHP_81,
]);
};
54 changes: 47 additions & 7 deletions src/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App;

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

class Action
Expand All @@ -20,26 +21,29 @@ public function __construct()

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

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

if (is_dir($directory)) {
// throw
throw new \Exception('Directory "' . $directory . '" is already exists');
}

// rights

mkdir($directory, 0755, true);

$ignore = new IgnoreFile();

$zip = new \ZipArchive();
if (!$zip->open($this->configuration->get('build.file'), \ZipArchive::CREATE)) {
// throw
if ($zip->open((string) $this->configuration->get('build.file'), \ZipArchive::CREATE) !== true) {
throw new \Exception('Failed to create zip archive');
}

$rootDirectory = $this->configuration->getRootDirectory();
Expand All @@ -51,13 +55,49 @@ public function run()

foreach ($iterator as $path) {

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

foreach ($iterator as $path) {

if ($path->isFile()) {
/**
* @var \SplFileInfo $path
*/
if (!$path->isFile()) {
continue;
}

if (!$ignore->ignores($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);


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

file_put_contents($GITHUB_OUTPUT, "$name=$value\n", FILE_APPEND);
}
}
}
27 changes: 15 additions & 12 deletions src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@

namespace App\Configuration;

use const ROOT;

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

/**
* @use
*/
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';
$dirName = !empty($dirName) ? $dirName : '.build';
$fileName = !empty($fileName) ? $fileName : 'package.zip';

if (!defined('ROOT')) {
define('ROOT', '');
}

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

Expand Down Expand Up @@ -57,8 +57,11 @@ public function get (string $option): mixed
return $target;
}

/**
* @return string
*/
public function getRootDirectory (): string
{
return realpath($this->get('build.directory') . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
return (string) $this->get('GITHUB_WORKSPACE');
}
}
Loading

0 comments on commit 8a53c51

Please sign in to comment.