Add tasks that shall be executed before the given stage

@param string $stage
@param array|string $tasks
@param \TYPO3\Surf\Domain\Model\Application $application

@return \TYPO3\Surf\Domain\Model\Workflow
976709
public function beforeStage($stage, $tasks, Application $application = null)
    {
        $this->addTaskToStage($tasks, $stage, $application, 'before');

        return $this;
    }
726280
def workflow_add_stage(object_id, input_params={}, always_retry=True, **kwargs):
    
    return DXHTTPRequest('/%s/addStage' % object_id, input_params, always_retry=always_retry, **kwargs)
1207688
public function addActions(array $actions): self
    {
        foreach ($actions as $action) {
            $this->addAction($action);
        }

        return $this;
    }
366054
public function processStages(array $stages, $payload)
    {
        // Take the stage to handle
        $currentStage = \array_shift($stages);

        // If is a string get the instance in the container
        if (\is_string($currentStage) && $this->container->has($currentStage)) {
            $currentStage = $this->container->get($currentStage);
        }

        // If the current stage is a RequestHandler use it and return the Response
        if ($currentStage instanceof RequestHandlerInterface) {
            return $currentStage->handle($payload);
        }

        // Process the current stage, and proceed to the stack
        if (false !== \current($stages) && \is_callable($currentStage)) {
            return $this->processStages($stages, $currentStage($payload));
        }

        // If there's not next stage in the stack, return the result for this one
        if (\is_callable($currentStage)) {
            return $currentStage($payload);
        }

        throw new UnprocessableStageException($currentStage, 'The stage can\'t be handled');
    }
1290809
public function applyChange(
        MenuInterface $menu,
        $stage
    ) {
        $menuBuilders = $this->getElementsByMenuCodeAndStage(
            $menu->getCode(),
            $stage
        );

        /**
         * @var MenuBuilderInterface $menuBuilder
         */
        foreach ($menuBuilders as $menuBuilder) {
            $menuBuilder->build($menu);
        }

        return $this;
    }
563223
public function addBulk(array $tasks) {

        $result = [];

        foreach($tasks as $name => $task) {

            if ( empty($task['class']) ) {

                $this->logger->warning("Missing class for task $name");
                $result[] = false;

            } else {

                $result[] = $this->add($name, $task['class'], empty($task['description']) ? null : $task['description']);

            }

        }

        return $result;

    }
651958
private function populateTaskEvents(array &$process)
    {
        foreach ($process['tasks'] as &$task) {
            $task['events'] = [];
            foreach ($process['events'] as $event) {
                if ($event['task_id'] == $task['id']) {
                    $task['events'][] = $event;
                }
            }
        }
    }
1184498
public function listTasks($project, $taskqueue, $optParams = array())
  {
    $params = array('project' => $project, 'taskqueue' => $taskqueue);
    $params = array_merge($params, $optParams);
    return $this->call('list', array($params), "Taskqueue_Tasks2");
  }
934088
protected function taskDeployerDeploy($stage, $branch)
    {
        $deployerBin = $this->config(Config::KEY_ENV . '/' . Config::KEY_DEPLOYER_BIN);

        $task = $this->taskDeployerDeployTask($deployerBin);

        if ($this->isTag($branch)) {
            $task->tag($branch);
        } else {
            $task->branch($branch);
        }

        $task->stage($stage);

        // Map Verbosity
        $output = $this->output();
        if ($output->isDebug()) {
            $task->debug();
        } elseif ($output->isVeryVerbose()) {
            $task->veryVerbose();
        } elseif ($output->isVerbose()) {
            $task->verbose();
        } elseif ($output->isQuiet()) {
            $task->quiet();
        }

        return $task;
    }
698886
protected function runTasks(OutputInterface $output, $tasks)
    {
        if (count($tasks) == 0) {
            $output->writeln(sprintf('    No tasks defined for <fg=black;options=bold>%s</> stage', $this->getStageName()));
            $output->writeln('');
            return true;
        }

        if ($this->runtime->getHostName() !== null) {
            $output->writeln(sprintf('    Starting <fg=black;options=bold>%s</> tasks on host <fg=black;options=bold>%s</>:', $this->getStageName(), $this->runtime->getHostName()));
        } else {
            $output->writeln(sprintf('    Starting <fg=black;options=bold>%s</> tasks:', $this->getStageName()));
        }

        $totalTasks = count($tasks);
        $succeededTasks = 0;

        foreach ($tasks as $taskName) {
            /** @var AbstractTask $task */
            $task = $this->taskFactory->get($taskName);
            $output->write(sprintf('        Running <fg=magenta>%s</> ... ', $task->getDescription()));
            $this->log(sprintf('Running task %s (%s)', $task->getDescription(), $task->getName()));

            if ($this->runtime->inRollback() && !$task instanceof ExecuteOnRollbackInterface) {
                $succeededTasks++;
                $output->writeln('<fg=yellow>SKIPPED</>');
                $this->log(sprintf('Task %s (%s) finished with SKIPPED, it was in a Rollback', $task->getDescription(), $task->getName()));
            } else {
                try {
                    if ($task->execute()) {
                        $succeededTasks++;
                        $output->writeln('<fg=green>OK</>');
                        $this->log(sprintf('Task %s (%s) finished with OK', $task->getDescription(), $task->getName()));
                    } else {
                        $output->writeln('<fg=red>FAIL</>');
                        $this->statusCode = 180;
                        $this->log(sprintf('Task %s (%s) finished with FAIL', $task->getDescription(), $task->getName()));
                    }
                } catch (SkipException $exception) {
                    $succeededTasks++;
                    $output->writeln('<fg=yellow>SKIPPED</>');
                    $this->log(sprintf('Task %s (%s) finished with SKIPPED, thrown SkipException', $task->getDescription(), $task->getName()));
                } catch (ErrorException $exception) {
                    $output->writeln(sprintf('<fg=red>ERROR</> [%s]', $exception->getTrimmedMessage()));
                    $this->log(sprintf('Task %s (%s) finished with FAIL, with Error "%s"', $task->getDescription(), $task->getName(), $exception->getMessage()));
                    $this->statusCode = 190;
                }
            }

            if ($this->statusCode !== 0) {
                break;
            }
        }

        $alertColor = 'red';
        if ($succeededTasks == $totalTasks) {
            $alertColor = 'green';
        }

        $output->writeln(sprintf('    Finished <fg=%s>%d/%d</> tasks for <fg=black;options=bold>%s</>.', $alertColor, $succeededTasks, $totalTasks, $this->getStageName()));
        $output->writeln('');

        return ($succeededTasks == $totalTasks);
    }
607422
private function runTask($workflow, $taskServiceId, $taskId)
    {
        $task = $this->container->get("{$workflow}.task.{$taskServiceId}");

        if (!$task instanceof ExecutableTaskInterface) {
            throw new InvalidTaskClassException(
                "The service {$taskServiceId} must implement the ExecutableTaskInterface interface."
            );
        }

        if ($task instanceof ContainerAwareInterface) {
            $task->setContainer($this->container);
        }

        if ($task instanceof LoggerAwareInterface) {
            /** @var LoggerInterface $logger */
            $logger = $this->container->get('logger');
            $task->setLogger($logger);
        }

        $parameters = new ParameterBag();
        $parameterBagId = "{$workflow}{$taskId}";

        /** @var ProviderInterface $stateStorage */
        $stateStorage = $this->container->get('state_storage');

        // Try to load the state file.
        try {
            $stateStorage->load($parameterBagId, $parameters);
        } catch (IOException $ignored) {
        }

        if ($task instanceof ParameterAwareInterface) {
            $task->setParameters($parameters);
        }

        $task->execute();

        $stateStorage->persist($parameterBagId, $parameters);
    }
149222
@Override
    public void addAction(final LifecycleStage stage, final LifecycleAction<T> action)
    {
        stageEvents.add(new StageEvent(stage, action));
    }
1042752
public function onQueue(TasksHandler $tasks)
    {
        // Create the task instance
        $notify = new Notify($this->container);
        $notify->setNotifier($this);

        $tasks->addTaskListeners('deploy', 'before', [clone $notify], -10);
        $tasks->addTaskListeners('deploy', 'after', [clone $notify], -10);
        $tasks->addTaskListeners('deploy', 'halt', [clone $notify], -10);
        $tasks->addTaskListeners('rollback', 'after', [clone $notify], -10);
    }
561933
public function addTask(Task $t)
    {
        if ($this->nestedTask !== null) {
            throw new BuildException(
                'The retry task container accepts a single nested task'
                . ' (which may be a sequential task container)'
            );
        }
        $this->nestedTask = $t;
    }
211087
public function process(array $stages, $payload, $extra = [])
    {
        if (!is_array($extra)) {
            $extra = ['source' => $extra];
        }

        return $this->processStages($stages, $payload, $extra);
    }
807659
void addTaskToChain(Task[] tasks, Task task, int index) {
        task.setNext(tasks[index]);
        tasks[index] = task;
    }
698040
public static function registerTasks(array $tasks)
    {
        // Register Tasks
        foreach ($tasks as $key => $task) {
            $roles = array_key_exists('roles', $task) ? $task['roles'] : null;
            self::registerTask($key, $task['desc'], $task['callback'], $roles);
        }
    }