Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
dcb6912
fix: update Laravel version and badge links in README
MoamenEltouny Sep 4, 2025
23e36b9
feat: add GitHub Actions workflow for running tests
MoamenEltouny Sep 4, 2025
b077e88
feat: add PHP Coding Standards Fixer workflow and configuration
MoamenEltouny Sep 4, 2025
5ab8a60
Fixing php-cs
MoamenEltouny Sep 4, 2025
6e90da2
feat: add funding configuration for GitHub Sponsors
MoamenEltouny Sep 4, 2025
94b637d
fix: update .gitignore to include phpunit and php-cs-fixer cache files
MoamenEltouny Sep 4, 2025
ed12eb1
refactor: update Executor model and migration for improved attributes…
MoamenEltouny Sep 4, 2025
1008d71
feat: update configuration files for Laravel compatibility and add ex…
MoamenEltouny Sep 4, 2025
635128e
fix: add .phpunit.cache to .gitignore
MoamenEltouny Sep 4, 2025
e8f41c9
fix: update database connection settings in TestCase for consistency …
MoamenEltouny Sep 4, 2025
fc1db27
fix: update database connection setting in executor config for consis…
MoamenEltouny Sep 4, 2025
a9f4e34
feat: update executor stubs and tests for improved structure and func…
MoamenEltouny Sep 4, 2025
e453bce
feat: add ExecutorManager and ExecutorPool classes for managing execu…
MoamenEltouny Sep 4, 2025
d11c5a1
feat: implement abstract Executor class for managing execution logic
MoamenEltouny Sep 4, 2025
2b73b71
Fixing php-cs
MoamenEltouny Sep 4, 2025
44816c0
fix: add missing documentation comments for database connection and t…
MoamenEltouny Sep 4, 2025
75deaa1
fix: update executor configuration to use environment variables for c…
MoamenEltouny Sep 4, 2025
facd9aa
refactor: consolidate executor properties into a single stub; remove …
MoamenEltouny Sep 4, 2025
4109694
Fixing php-cs
MoamenEltouny Sep 4, 2025
3d5d0f9
feat: add Executor class with job dispatching and command execution m…
MoamenEltouny Sep 4, 2025
6049048
fix: update executor class import and initialize tags and servers pro…
MoamenEltouny Sep 4, 2025
8687938
Fixing php-cs
MoamenEltouny Sep 4, 2025
42a14b6
chore: remove .php-cs-fixer.cache and clean up .gitignore
MoamenEltouny Sep 4, 2025
4539d14
feat: create Executor facade for pharaonic.executor.manager
MoamenEltouny Sep 4, 2025
34c94d9
feat: implement info and run methods in ExecutorManager class
MoamenEltouny Sep 4, 2025
e0266df
feat: add ExecutorItem class and refactor ExecutorPool to manage exec…
MoamenEltouny Sep 4, 2025
bb43870
Fixing php-cs
MoamenEltouny Sep 4, 2025
01ffa24
feat: add servers column to executors table and update ExecutorItem t…
MoamenEltouny Sep 4, 2025
836f251
refactor: remove unused options from ExecuteMakeCommand and clean up …
MoamenEltouny Sep 4, 2025
de14e5e
Fixing php-cs
MoamenEltouny Sep 4, 2025
34e9cbf
feat: add AboutCommand to display version information in console
MoamenEltouny Sep 4, 2025
fae3afb
fix: implement info method in ExecutorManager and update addPath and …
MoamenEltouny Sep 4, 2025
353a357
feat: enhance ExecutorItem and ExecutorPool to include model data and…
MoamenEltouny Sep 4, 2025
7fd264a
fix: update docblock for file property in ExecutorItem to include par…
MoamenEltouny Sep 4, 2025
5448636
fix: reorder keys in info method return array for consistency
MoamenEltouny Sep 4, 2025
c705ddd
refactor: simplify ExecuteStatusCommand by removing ExecutorService d…
MoamenEltouny Sep 4, 2025
d34e89b
fix: enable ExecuteStatusCommand in ExecutorServiceProvider
MoamenEltouny Sep 4, 2025
74b3340
fix: prevent duplicate Executor names during collection in ExecutorPool
MoamenEltouny Sep 4, 2025
72fcf26
feat: add pharaonic/php-dot-array dependency and enhance Executor fun…
MoamenEltouny Sep 4, 2025
8199802
fix: uncomment ExecuteCommand and ExecuteFreshCommand in ExecutorServ…
MoamenEltouny Sep 4, 2025
e4a09cf
fix: add comments for clarity in ExecuteCommand handling logic
MoamenEltouny Sep 4, 2025
0519cae
Fixing php-cs
MoamenEltouny Sep 4, 2025
496d654
refactor: remove unused seed method and update model handling in Exec…
MoamenEltouny Sep 4, 2025
f5db08c
fix: improve rollback logic in ExecuteRollbackCommand and correct suc…
MoamenEltouny Sep 4, 2025
eedfca0
fix: uncomment ExecuteRollbackCommand in ExecutorServiceProvider
MoamenEltouny Sep 4, 2025
dacef35
fix: change model visibility to public in ExecutorItem
MoamenEltouny Sep 4, 2025
a9673bc
fix: rename reverse method to rollback in ExecutorItem for clarity
MoamenEltouny Sep 4, 2025
9789867
fix: change error message to warning and adjust return value in Execu…
MoamenEltouny Sep 4, 2025
4d836c1
refactor: remove ExecutorService and InteractsWithIO traits for code …
MoamenEltouny Sep 5, 2025
871821f
fix: use strict comparison in isNew method for accuracy
MoamenEltouny Sep 5, 2025
e40e09e
fix: correct class closing syntax in Executor class
MoamenEltouny Sep 5, 2025
246e569
fix: update method documentation in Executor facade for clarity
MoamenEltouny Sep 5, 2025
c0b0be4
fix: replace manager references with ExecutorFacade for consistency
MoamenEltouny Sep 5, 2025
87fd7cd
fix: correct description text and replace manager references with Exe…
MoamenEltouny Sep 5, 2025
23bdbe3
fix: refactor ExecutorTest and TestCase setup methods for clarity and…
MoamenEltouny Sep 5, 2025
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
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: MoamenEltouny
buy_me_a_coffee: moameneltouny
23 changes: 23 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: PHP Coding Standards Fixer

on: [push]

jobs:
php-cs-fixer:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fixing php-cs
15 changes: 9 additions & 6 deletions .github/workflows/build.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
name: build
name: Tests

on: [push, pull_request]
on:
push:
branches: [ main, develop ]
pull_request:

jobs:
run:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ["8.1", "8.2", "8.3"]
php-versions: ['8.2', '8.3', '8.4']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}

steps:
Expand All @@ -19,7 +22,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, pdo, pdo_sqlite, sqlite3, intl, zip
extensions: mbstring, pdo, intl, zip
coverage: none

- name: Check PHP Version
Expand All @@ -35,7 +38,7 @@ jobs:
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
run: composer install --prefer-dist --no-progress

- name: Run test suite
run: vendor/bin/phpunit
run: vendor/bin/phpunit --testdox
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
/vendor
composer.lock
.phpunit.cache
.phpunit.result.cache
.php-cs-fixer.cache
39 changes: 39 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->notPath('bootstrap/*')
->notPath('storage/*')
->notPath('storage/*')
->notPath('resources/view/mail/*')
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'indentation_type' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
])
->setFinder($finder);
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<p align="center"><a href="https://pharaonic.io" target="_blank"><img src="https://raw.githubusercontent.com/Pharaonic/logos/main/executor.jpg"></a></p>

<p align="center">
<a href="https://laravel.com" target="_blank"><img src="https://img.shields.io/static/v1?label=Laravel&message=10.x, 11.x&color=F05340&style=flat-square" alt="Laravel Version : 10.x, 11.x"></a>
<img src="https://img.shields.io/static/v1?label=License&message=MIT&color=brightgreen&style=flat-square" alt="License">
<img src="https://img.shields.io/github/actions/workflow/status/pharaonic/laravel-executor/build.yml" alt="GitHub Actions Workflow Status">
<br>
<a href="https://packagist.org/packages/Pharaonic/laravel-executor" target="_blank"><img src="https://img.shields.io/static/v1?label=Packagist&message=pharaonic/laravel-executor&color=blue&logo=packagist&logoColor=white" alt="Source"></a>
<a href="https://packagist.org/packages/pharaonic/laravel-executor" target="_blank"><img src="https://poser.pugx.org/pharaonic/laravel-executor/v" alt="Packagist Version"></a>
<a href="https://packagist.org/packages/pharaonic/laravel-executor" target="_blank"><img src="https://poser.pugx.org/pharaonic/laravel-executor/downloads" alt="Packagist Downloads"></a>
<a href="https://github.com/Pharaonic/laravel-executor/actions"><img src="https://github.com/Pharaonic/laravel-executor/workflows/tests/badge.svg" alt="Build Status"></a>
<a href="https://laravel.com" target="_blank"><img src="https://img.shields.io/static/v1?label=Laravel&message=11.x&color=F05340&style=flat-square" alt="Laravel Version : 11.x"></a>
<a href="https://packagist.org/packages/pharaonic/laravel-executor" target="_blank"><img src="https://poser.pugx.org/pharaonic/laravel-executor/downloads" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/Pharaonic/laravel-executor"><img src="https://img.shields.io/packagist/v/Pharaonic/laravel-executor" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/Pharaonic/laravel-executor"><img src="https://img.shields.io/static/v1?label=License&message=MIT&color=brightgreen&style=flat-square" alt="License"></a>
</p>

<h3 align="center">Allows you to execute commands, actions, jobs, and automated tasks on your production server.</h3>
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
}
],
"require": {
"php": ">=8.1",
"laravel/framework": ">=10.0"
"php": "~8.2|~8.3|~8.4",
"laravel/framework": "^11.0",
"pharaonic/php-dot-array": "^2.0"
},
"require-dev": {
"orchestra/testbench": "^8.0"
"orchestra/testbench": "^9.15"
},
"config": {
"sort-packages": true
Expand Down
13 changes: 13 additions & 0 deletions config/executor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

return [
/**
* The database connection that should be used by the executor.
*/
'connection' => env('EXECUTOR_CONNECTION', config('database.default')),

/**
* The table that should be used to store the executors.
*/
'table' => env('EXECUTOR_TABLE', 'executors'),
];
23 changes: 13 additions & 10 deletions database/migrations/2024_07_07_000001_create_executors_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ class CreateExecutorsTable extends Migration
*/
public function up()
{
Schema::create('executors', function (Blueprint $table) {
$table->id();
$table->unsignedTinyInteger('type')->default(ExecutorType::Always);
$table->string('executor');
$table->string('tag')->nullable();
$table->integer('batch')->default(1);
$table->integer('executed')->default(0);
$table->timestamp('last_executed_at')->nullable();
});
Schema::connection(config('pharaonic.executor.connection', config('database.default')))
->create(config('pharaonic.executor.table', 'executors'), function (Blueprint $table) {
$table->id();
$table->unsignedTinyInteger('type')->default(ExecutorType::Always);
$table->string('name');
$table->json('tags')->nullable();
$table->json('servers')->nullable();
$table->integer('batch')->nullable();
$table->integer('executed')->default(0);
$table->timestamp('last_executed_at')->nullable();
});
}

/**
Expand All @@ -32,6 +34,7 @@ public function up()
*/
public function down()
{
Schema::dropIfExists('executors');
Schema::connection(config('pharaonic.executor.connection', config('database.default')))
->dropIfExists(config('pharaonic.executor.table', 'executors'));
}
}
22 changes: 11 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="laravel-executor Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src/</directory>
</include>
</source>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">

<testsuites>
<testsuite name="laravel-executor Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

</phpunit>
51 changes: 39 additions & 12 deletions src/Executor.php → src/Classes/Executor.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
<?php

namespace Pharaonic\Laravel\Executor;
namespace Pharaonic\Laravel\Executor\Classes;

use Illuminate\Console\Concerns\InteractsWithIO;
use Illuminate\Console\OutputStyle;
use Illuminate\Foundation\Bus\PendingDispatch;
use Illuminate\Support\Facades\Artisan;
use Pharaonic\Laravel\Executor\Enums\ExecutorType;
use Pharaonic\Laravel\Executor\Traits\InteractsWithIO;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;

/**
* @property ExecutorType $type
* @property array $tags
* @property array $servers
* @method void up()
* @method void down()
* @method PendingDispatch job(string|object $job, ...$arguments)
* @method int command(string $command, array $parameters = [])
*/
abstract class Executor
{
use InteractsWithIO;
Expand All @@ -22,32 +31,50 @@ abstract class Executor
public $type = ExecutorType::Always;

/**
* The tag of the executor.
* The tags of the executor.
*
* @var string|null
* @var array
*/
public $tag = null;
public $tags = [];

/**
* Execute it.
*
* The servers of the executor.
*
* @var array
*/
public $servers = [];

/**
* Run the executor.
*
* @return void
*/
abstract public function handle(): void;
abstract public function up(): void;

/**
* Reverse the executor.
*
* @return void
*/
abstract public function down(): void;

/**
* Create a new Executor instance.
*
*
* @return void
*/
public function __construct()
{
if (!($this->type instanceof ExecutorType)) {
if (! ($this->type instanceof ExecutorType)) {
throw new \Exception('The type of the executor must be an instance of ExecutorType.');
}

if (!is_null($this->tag) && !is_string($this->tag) && !is_array($this->tag)) {
throw new \Exception('The tag of the executor must be a string or an array or null.');
if (! is_array($this->tags)) {
throw new \Exception('The tags of the executor must be an array.');
}

if (! is_array($this->servers)) {
throw new \Exception('The servers of the executor must be an array of ips.');
}

$this->output = new OutputStyle(new ArgvInput(), new ConsoleOutput());
Expand Down
Loading