• Stars
    star
    116
  • Rank 293,290 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 1 year ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A package to write Shell scripts like Blade Components and run them locally or on a remote server

Laravel Task Runner

A package to write Shell scripts like Blade Components and run them locally or on a remote server. Support for running tasks in the background and test assertions. Built upon the Process feature in Laravel 10.

Latest Version on Packagist run-tests Total Downloads Buy us a tree

Sponsor this package

❤️ We proudly support the community by developing Laravel packages and giving them away for free. If this package saves you time or if you're relying on it professionally, please consider sponsoring the maintenance and development. Keeping track of issues and pull requests takes time, but we're happy to help!

Laravel Splade

Did you hear about Laravel Splade? 🤩

It's the magic of Inertia.js with the simplicity of Blade. Splade provides a super easy way to build Single Page Applications using Blade templates. Besides that magic SPA-feeling, it comes with more than ten components to sparkle your app and make it interactive, all without ever leaving Blade.

Want to see this package in action?

Check out Eddy Server Management, our open-source solution for Server Provisioning and Zero-Downtime PHP Deployment!

Installation

This package requires Laravel 10 and PHP 8.1 or higher. You can install the package via composer:

composer require protonemedia/laravel-task-runner

Optionally, you can publish the config file with:

php artisan vendor:publish --provider="ProtoneMedia\LaravelTaskRunner\ServiceProvider"

Basic usage

You may use the Artisan make:task command to create a Task class:

php artisan make:task ComposerGlobalUpdate

This will generate two files: app/Tasks/ComposerGlobalUpdate.php and resources/views/tasks/composer-global-update.blade.php.

Once you've added your script to the Blade template, you may run it on your local machine by calling the dispatch() method:

ComposerGlobalUpdate::dispatch();

Alternatively, if you don't want a separate Blade template, you may use the --class option (or -c):

php artisan make:task ComposerGlobalUpdate -c

This allows you to specify the script inline:

class ComposerGlobalUpdate extends Task
{
    public function render(): string
    {
        return 'composer global update';
    }
}

Task output

The dispatch() method returns an instance of ProcessOutput, which can return the output and exit code:

$output = ComposerGlobalUpdate::dispatch();

$output->getBuffer();
$output->getExitCode();

$output->getLines();    // returns the buffer as an array
$output->isSuccessful();    // returns true when the exit code is 0
$output->isTimeout();    // returns true on a timeout

To interact with the underlying ProcessResult, you may call the getIlluminateResult() method:

$output->getIlluminateResult();

Script variables

Just like Blade Components, the public properties and methods of the Task class are available in the template:

class GetFile extends Task
{
    public function __construct(public string $path)
    {
    }

    public function options()
    {
        return '-n';
    }
}

Blade template:

cat {{ $options() }} {{ $path }}

You can create a new instance of the Task using the static make() method:

GetFile::make('/etc/hosts')->dispatch();

Task options

You may specify a timeout. By default, the timeout is based on the task-runner.default_timeout config value.

class ComposerGlobalUpdate extends Task
{
    protected int $timeout = 60;
}

Run in background

You may run a task in the background:

ComposerGlobalUpdate::inBackground()->dispatch();

It allows you to write the output to a file, as the dispatch() method won't return anything when the Task is still running in the background.

ComposerGlobalUpdate::inBackground()
    ->writeOutputTo(storage_path('script.output'))
    ->dispatch();

Run tasks on a remote server

In the task-runner configuration file, you may specify one or more remote servers:

return [
    'connections' => [
        // 'production' => [
        //     'host' => '',
        //     'port' => '',
        //     'username' => '',
        //     'private_key' => '',
        //     'passphrase' => '',
        //     'script_path' => '',
        // ],
    ],
];

Now you may call the onConnection() method before calling other methods:

ComposerGlobalUpdate::onConnection('production')->dispatch();

ComposerGlobalUpdate::onConnection('production')->inBackground()->dispatch();

Task test assertions

You may call the fake() method to prevent tasks from running and make assertions after acting:

use ProtoneMedia\LaravelTaskRunner\Facades\TaskRunner;

/** @test */
public function it_updates_composer_globally()
{
    TaskRunner::fake();

    $this->post('/api/composer/global-update');

    TaskRunner::assertDispatched(ComposerGlobalUpdate::class);
}

You may also use a callback to investigate the Task further:

TaskRunner::assertDispatched(function (ComposerGlobalUpdate $task) {
    return $task->foo === 'bar';
});

If you type-hint the Task with PendingTask, you may verify the configuration:

use ProtoneMedia\LaravelTaskRunner\PendingTask;

TaskRunner::assertDispatched(ComposerGlobalUpdate::class, function (PendingTask $task) {
    return $task->shouldRunInBackground();
});

TaskRunner::assertDispatched(ComposerGlobalUpdate::class, function (PendingTask $task) {
    return $task->shouldRunOnConnection('production');
});

To fake just some of the tasks, you may call the fake() method with a class or array of classes:

TaskRunner::fake(ComposerGlobalUpdate::class);
TaskRunner::fake([ComposerGlobalUpdate::class]);

Alternatively, you may fake everything except a specific task:

TaskRunner::fake()->dontFake(ComposerGlobalUpdate::class);

You may also supply a fake Task output:

TaskRunner::fake([
    ComposerGlobalUpdate::class => 'Updating dependencies'
]);

Or use the ProcessOutput class to set the exit code as well:

use ProtoneMedia\LaravelTaskRunner\ProcessOutput;

TaskRunner::fake([
    ComposerGlobalUpdate::class => ProcessOutput::make('Updating dependencies')->setExitCode(1);
]);

When you specify the Task output, you may also prevent unlisted Tasks from running:

TaskRunner::preventStrayTasks();

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Other Laravel packages

  • Laravel Analytics Event Tracking: Laravel package to easily send events to Google Analytics.
  • Laravel Blade On Demand: Laravel package to compile Blade templates in memory.
  • Laravel Cross Eloquent Search: Laravel package to search through multiple Eloquent models.
  • Laravel Dusk Fakes: Persistent Fakes for Laravel Dusk (Bus, Mail, Notifications, Queue).
  • Laravel Eloquent Scope as Select: Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes and constraints by adding them as a subquery.
  • Laravel Eloquent Where Not: This Laravel package allows you to flip/invert an Eloquent scope, or really any query constraint.
  • Laravel Form Components: Blade components to rapidly build forms with Tailwind CSS Custom Forms and Bootstrap 4. Supports validation, model binding, default values, translations, includes default vendor styling and fully customizable!
  • Laravel MinIO Testing Tools: This package provides a trait to run your tests against a MinIO S3 server.
  • Laravel Mixins: A collection of Laravel goodies.
  • Laravel Paddle: Paddle.com API integration for Laravel with support for webhooks/events.
  • Laravel Splade: Splade provides a super easy way to build Single Page Applications using Blade templates. Besides that magic SPA-feeling, it comes with more than ten components to sparkle your app and make it interactive, all without ever leaving Blade.
  • Laravel Verify New Email: This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.
  • Laravel WebDAV: WebDAV driver for Laravel's Filesystem.
  • Laravel XSS Protection Middleware: Laravel Middleware to protect your app against Cross-site scripting (XSS). It sanitizes request input by utilising the Laravel Security package, and it can sanatize Blade echo statements as well.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

More Repositories

1

laravel-ffmpeg

This package provides an integration with FFmpeg for Laravel. Laravel's Filesystem handles the storage of the files.
PHP
1,511
star
2

laravel-splade

💫 The magic of Inertia.js with the simplicity of Blade 💫 - Splade provides a super easy way to build Single Page Applications (SPA) using standard Laravel Blade templates, and sparkle it to make it interactive. All without ever leaving Blade.
PHP
1,382
star
3

laravel-cross-eloquent-search

Laravel package to search through multiple Eloquent models. Supports sorting, pagination, scoped queries, eager load relationships and searching through single or multiple columns.
PHP
990
star
4

laravel-form-components

A set of Blade components to rapidly build forms with Tailwind CSS (v1.0 and v2.0) and Bootstrap 4/5. Supports validation, model binding, default values, translations, Laravel Livewire, includes default vendor styling and fully customizable!
PHP
807
star
5

inertiajs-tables-laravel-query-builder

Inertia.js Tables for Laravel Query Builder
PHP
425
star
6

eddy-server-management

Open-Source Solution for Server Provisioning and Zero-Downtime PHP Deployment
PHP
423
star
7

laravel-verify-new-email

This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.
PHP
384
star
8

laravel-analytics-event-tracking

Laravel package to easily send events to Google Analytics
PHP
243
star
9

laravel-paddle

Paddle.com API integration for Laravel with support for webhooks/events
PHP
195
star
10

laravel-mixins

A collection of Laravel goodies.
PHP
135
star
11

laravel-eloquent-scope-as-select

Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes and constraints by adding them as a subquery.
PHP
102
star
12

laravel-single-session

This package prevents a User from being logged in more than once. It destroys the previous session when a User logs in and thereby allowing only one session per user.
PHP
101
star
13

laravel-xss-protection

Laravel XSS Protection Middleware
PHP
99
star
14

laravel-guidelines

Not necessarily coding standards (naming conventions, avoid else, etc.), but more like 'app'-guidelines - things you don't want to forget.
PHP
91
star
15

laravel-api-health

Monitor first and third-party services and get notified when something goes wrong!
PHP
87
star
16

form-components-pro

A set of Vue 3 components to rapidly build forms with Tailwind CSS 3. It supports validation, model binding, integrates with Autosize/Choices.js/Flatpickr, includes default vendor styling and is fully customizable! Even better in conjunction with Laravel Jetstream + Inertia.js.
JavaScript
82
star
17

laravel-webdav

WebDAV Serivce Provider for Laravel
PHP
59
star
18

laravel-blade-on-demand

Compile Blade templates in memory
PHP
50
star
19

inertia-vue-modal-poc

Proof of Concept: Load any route into a modal with Inertia.js
Vue
49
star
20

laravel-splade-core

A package to use Vue 3's Composition API in Laravel Blade components.
PHP
42
star
21

laravel-eloquent-where-not

This Laravel package allows you to flip/invert an Eloquent scope, or really any query constraint.
PHP
27
star
22

laravel-content

You provide the WYSIWYG editor, Media uploader, etc., and the package handles the validation, multi-language, storage, caching, sanitizing, etc.
PHP
23
star
23

inertiajs-events-laravel-dusk

Inertia.js Events for Laravel Dusk
PHP
22
star
24

laravel-dusk-fakes

Persistent Fakes for Laravel Dusk
PHP
17
star
25

laravel-minio-testing-tools

This package provides a trait to run your tests against a MinIO S3 server.
PHP
11
star
26

splade.dev

Source code for https://splade.dev
PHP
8
star
27

laravel-splade-docs

7
star
28

laravel-viewi

[WIP] Viewi for Laravel proof-of-concept: Build full-stack and completely reactive user interfaces with PHP.
PHP
5
star
29

eddy-backup-cli

Backup CLI for Eddy Server Management
PHP
3
star
30

form-components-pro-docs

A set of Vue components to rapidly build forms with Tailwind CSS v2.0. It supports validation, model binding, includes default vendor styling and is fully customizable!
JavaScript
3
star
31

laravel-tracer

[WIP] Trace authenticated users
PHP
2
star
32

eddy-filesystem-cli

PHP
1
star
33

laravel-ffmpeg-demo-app

A demo app to show all the cool things you can do with Laravel FFmpeg
1
star
34

php-apple-mapkit-token

Create a MapKit JS Token with PHP
1
star
35

laravel-browser-kit-macro

A macro to use the Laravel 5.3 testing layer inside your Laravel >5.3 tests
PHP
1
star
36

laravel-splade-plugin-skeleton

PHP
1
star