PHP code example of mbpcoder / grandpa

1. Go to this page and download the library: Download mbpcoder/grandpa library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mbpcoder / grandpa example snippets




task('deploy', function () {
    $revision = storage()->ftp()->get('.revision');

    storage()->ftp()->upload(git()->changedFiles($revision));
    storage()->ftp()->delete(git()->deletedFiles($revision));

    storage()->ftp()->put('.revision', git()->currentHead());

    ssh()->run('cd /var/www/app && composer install --no-dev && php artisan migrate --force');
    ssh()->run('cd /var/www/app && php artisan config:cache && php artisan optimize');

    say('Deployed');
});



task('deploy', function () {
    $revision = storage()->ftp()->get('.revision');   // last deployed commit hash, or null on first deploy

    storage()->ftp()->upload(git()->changedFiles($revision));    // upload added/modified files
    storage()->ftp()->delete(git()->deletedFiles($revision));    // remove files deleted from git

    storage()->ftp()->purge('public/build');             // wipe a remote directory
    storage()->ftp()->uploadDir('public/build');        // push a whole local directory (e.g. built assets)

    storage()->ftp()->put('.revision', git()->currentHead());    // record the deployed commit on the server

    ssh()->run('cd /var/www/app && php artisan migrate --force && php artisan optimize');

    say('Deployed');
});



task('deploy', function () {
    $revision = storage()->ftp()->get('.revision');

    storage()->ftp()->upload(git()->changedFiles($revision));
    storage()->ftp()->delete(git()->deletedFiles($revision));

    storage()->ftp()->put('.revision', git()->currentHead());

    // Hit a route on the live site to clear cache / warm up / health-check.
    $response = http()->get('https://example.com/__deploy/clear-cache');

    say('Deployed and cache cleared: ' . $response);
});



task('deploy', function () {
    $revision = storage()->ftp()->get('.revision');

    storage()->ftp()->upload(git()->changedFiles($revision));
    storage()->ftp()->delete(git()->deletedFiles($revision));

    storage()->ftp()->purge('public/build');
    storage()->ftp()->uploadDir('public/build');

    storage()->ftp()->put('.revision', git()->currentHead());

    ssh()->run('cd /var/www/app && composer install --no-dev && php artisan migrate --force');
    ssh()->run('cd /var/www/app && php artisan optimize:clear && php artisan optimize');

    say('Deployed');
});



task('deploy', function () {
    try {
        $revision = storage()->ftp()->get('.revision');

        storage()->ftp()->upload(git()->changedFiles($revision));
        storage()->ftp()->delete(git()->deletedFiles($revision));

        storage()->ftp()->put('.revision', git()->currentHead());

        telegram()->message('Deploy succeeded for ' . git()->currentBranch())->send();
    } catch (\Throwable $e) {
        telegram()->message('Deploy failed: ' . $e->getMessage())->send();

        throw $e;
    }
});



task('git:update-all', function () {
    foreach (subDirectories('/var/www/projects') as $dir) {
        if (!git()->isRepository($dir)) {
            continue;
        }

        say($dir);
        say('  branch: ' . git()->currentBranch($dir));

        foreach (git()->pull($dir) as $line) {
            say('  ' . $line);
        }
    }
});



task('deploy', function () {
    // ...
})->everyMinute();

task('clear-old-logs', function () {
    // ...
})->dailyAt('1:00');

task('ping-health-check', function () {
    http()->get('https://example.com/health');
})->repeat(5, 10_000); // run 5 times, 10s apart

task('flaky-deploy', function () {
    return deploy() ? TaskStatus::Success : TaskStatus::Error;
})->retry(3, 500);

task('warm-caches', function () {
    http()->get('https://example.com/cache-warm');
})->repeat(10)->asParallel(5); // 10 runs total, 5 at a time

php vendor/bin/grandpa deploy

composer global 

curl -LO https://raw.githubusercontent.com/mbpcoder/grandpa/claude/tender-davinci-rkpskn/grandpa.phar
chmod +x grandpa.phar
php grandpa.phar deploy

@echo off
php "%~dp0grandpa.phar" %*

   php bin/grandpa init
   

php bin/grandpa deploy

php bin/grandpa deploy --force

php bin/grandpa runner.php deploy
php bin/grandpa --file=runner.php deploy

php bin/grandpa runner.php

php bin/grandpa deploy --dir=/path/to/some-other-project
php bin/grandpa --dir=../another-project deploy --force

php bin/grandpa schedule:run