Automated Tasks with Robo

Robo

SuiteCRM utilises Robo tasks to provide automation for common tasks.

Robo <3.0.7 fails to call autoload.php relative to the vendor/bin. This may cause errors when trying to run any of SuiteCRM’s robo commands. Recommdation is to update the instance’s robo composer libraries to 3.0.7+. Alternatively replace the following commands pathname reference of ./vendor/bin/robo to ./vendor/consolidation/robo/robo

Listing the available automated tasks in Robo

Linux:

Open bash terminal and run robo

./vendor/bin/robo list

You get help for each task using:

./vendor/bin/robo [taskname] -h

Windows:

Open Command Prompt and run robo

.\vendor\bin\robo list

You can get help for each task using:

.\vendor\bin\robo [taskname] -h

Making your own custom Robo tasks

You can create custom commands for SuiteCRM in the custom/lib/Robo/Plugin/Commands/ directory. For example, you can have a file called custom/lib/Robo/Plugin/Commands/DeployCommands.php with some custom tasks for deploying SuiteCRM.

You can use any Robo functions from within the task, see the Robo documentation for more info on what Robo provides.

You can also use PHP’s various scripting functions, like exec.

Here’s an example Robo task:

<?php
namespace SuiteCRM\Custom\Robo\Plugin\Commands;

use Robo\Task\Base\loadTasks;

class DeployCommands extends \Robo\Tasks
{
    use loadTasks;

    /**
     * This Robo task will deploy a given git branch.
     *
     * @param array $opts
     * @option $branch The branch to deploy, e.g. master, development, etc.
     * @usage deploy --branch=master
     */
    public function deploy(array $opts = ['branch' => 'master'])
    {
        // You can print to stdout with $this->say
        $this->say("Hello, world.");

        // Or get values from the user with $this->ask
        $name = $this->ask("What is your name?");

        // Run arbitrary shell commands, e.g. git.
        $this->_exec("git fetch");

        // You can fail the task at any time with a RuntimeException.
        $check = true;
        if ($check !== true) {
            throw new \RuntimeException("Unable to continue, check failed!");
        }

        // You can also use Symfony Console's io methods to provide better styling for your Robo tasks.
        $checkedFiles = ['file.txt', 'file2.txt'];
        $this->io()->section("{count($checkedFiles)} checked files");
        $this->io()->listing($checkedFiles);

        // Or use the io methods to show success or error messages.
        $this->io->success('Success!');
        $this->io->error('Failed!');

        // Read more about Symfony Console in the documentation:
        // https://symfony.com/doc/current/console/style.html
    }
}

As mentioned above, you can use ./vendor/bin/robo list to list all available Robo commands, including your custom tasks. You may need to run composer install to make sure Composer has installed Robo, and you’ll also need to run composer dump-autoload when you add a new Robo task to make sure that Composer picks up the new files.

Content is available under GNU Free Documentation License 1.3 or later unless otherwise noted.