Successfully reported this slideshow.
Your SlideShare is downloading. ×

Php task runners

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Zend Framework 1.8 workshop
Zend Framework 1.8 workshop
Loading in …3
×

Check these out next

1 of 46 Ad

More Related Content

Slideshows for you (20)

Similar to Php task runners (20)

Advertisement

Php task runners

  1. 1. task runners for php ignacio velazquez ……….
  2. 2. /toc • what is it? • why? • task runners • phing • robo • summary
  3. 3. about me
  4. 4. /about-me/nass600 Software Engineer @ Hostelworld nass600 nass600 nass600
  5. 5. what is it?
  6. 6. /what-is-it/project-stages installation build qa doc deploy
  7. 7. /what-is-it/project-stages?p=2 down deps installation create db run migrat load fixt
  8. 8. /what-is-it/project-stages?p=3 unit tests qa funct tests code qual gen report
  9. 9. /what-is-it/definition a task runner is a tool which provides the mechanisms to run tasks in an ordered and controlled fashion
  10. 10. why?
  11. 11. /why/lovely-script
  12. 12. /why/main-concept automation
  13. 13. /why/main-concept?need-more=true • Simplify repetitive task • Save time • Less human errors • Easier to explain over the phone • Deployment • Builds/Packaging • Single script entry point
  14. 14. task runners
  15. 15. /task-runners
  16. 16. phing
  17. 17. /phing/intro • PHing Is Not Gnu make • Started in 2004 • Ported previously to PHP 5 • 777 stars • 3315 commits • Very similar to Apache Ant • Manifest in XML
  18. 18. /phing/installation "require-dev": { "phing/phing": "^2.16" }
  19. 19. /phing/hello-world <?xml version="1.0" encoding="UTF-8"?> <project name="talk-php-task-runners" default="setup:install"> <property name="bin_dir" value="bin"/> <target name="setup:install" depends="setup:vendors, setup:run" description="First install after the first clone"/> <target name="setup:vendors" description="Remove and download latest version of all vendors"> <echo msg="Updating vendors..."/> <delete dir="vendors"/> <exec passthru="true" logoutput="true" checkreturn="true" command="composer install --ansi" /> <exec passthru="true" checkreturn="true" command="npm install" /> </target> <target name="setup:run" description="Run server with hot reload"> <exec passthru="true" logoutput="true" checkreturn="true" command="${bin_dir}/console server:run" spawn="true"/> <exec passthru="true" logoutput="true" checkreturn="true" command="npm run serve" /> </target> </project>
  20. 20. /phing/config build.dir=build bin.dir=./bin web.dir=./web var.dir=./var source=src <?xml version="1.0" encoding="UTF-8"?> <project name="portfolio" default="setup:run"> <property file="./build.properties"/> <target name="setup:run" description="Run server with hot reload"> <exec passthru="true" logoutput="true" checkreturn="true" command="${bin.dir}/console server:run" spawn="true"/> <exec passthru="true" logoutput="true" checkreturn="true" command="npm run serve" /> </target> </project>
  21. 21. /phing/io <echo msg="Phing rocks!" /> <echo message="Binarycloud, too." /> <echo>And don't forget Propel.</echo> <echo file="test.txt" append="false"> This is a test message </echo>
  22. 22. /phing/filesystem <target name="list-files"> <delete dir="app-clone"/> <mkdir dir="app-clone"/> <copy todir="app-clone" includeemptydirs="true"> <fileset dir="./app" id="app-files"> <include name="**/*.yml"/> <exclude name="**/parameters.yml"/> </fileset> </copy> <foreach param="filename" target="echo-files"> <fileset refid="app-files"/> </foreach> </target> <target name="echo-files" hidden="true"> <echo>file: ${filename}</echo> </target>
  23. 23. /phing/filters-mappers <fileset dir="src" id="assets"> <include name="**/*.css"/> </fileset> <delete dir="replica"/> <mkdir dir="replica"/> <copy todir="replica"> <fileset refid="assets"/> <mapper type="flatten" /> <filterchain> <replaceregexp> <regexp pattern="n" replace=""/> </replaceregexp> </filterchain> </copy>
  24. 24. /phing/integrations/vcs <gitclone repository="git://github.com/path/to/repo/repo.git" targetPath="${repo.dir.resolved}" /> <gitcheckout repository="${repo.dir.resolved}" branchname="mybranch" quiet="true" forceCreate="true" />
  25. 25. /phing/integrations/deps <composer command="install" composer="${dir.release}/composer.phar"> <arg value="--optimize-autoloader" /> <arg value="--working-dir" /> <arg path="${dir.release}" /> </composer>
  26. 26. /phing/integrations/testing <phpunit printsummary="true" pharlocation="vendor/bin/phpunit" configuration="./phpunit.xml.dist"> <formatter type="xml" todir="${xmlreport.dir}" outfile="${report.name}"/> </phpunit>
  27. 27. /phing/extending <?php require_once "phing/Task.php"; class MyEchoTask extends Task { /** * The message passed in the buildfile. */ private $message = null; /** * The setter for the attribute "message" */ public function setMessage($str) { $this->message = $str; } /** * The init method: Do init steps. */ public function init() { // nothing to do here } /** * The main entry point method. */ public function main() { print($this->message); } } <includepath classpath="src/AppBundle/Phing" /> <taskdef name="myecho" classname="MyEchoTask" /> <myecho message="Hello World" />
  28. 28. robo
  29. 29. /robo/intro • First release in 2014 • 1739 stars • 1338 commits • Written in PHP • Manifest in PHP • Symfony Components (console, finder, filesystem..)
  30. 30. /robo/installation "require-dev": { "consolidation/robo": "^1.1" }
  31. 31. /robo/hello-world <?php use RoboTasks; /** * This is project's console commands configuration for Robo task runner. * * @see http://robo.li/ */ class RoboFile extends Tasks { /** * @var string Production environment */ const ENV_PROD = 'prod'; /** * @var string Development environment */ const ENV_DEV = 'dev'; /** * First install command * * @param string $env * @return bool */ public function setupInstall($env = self::ENV_DEV) { $task = $this->taskComposerInstall(); if (self::ENV_PROD === $env) { $task->noDev()->optimizeAutoloader(); putenv('SYMFONY_ENV=prod'); } $result = $task->run(); if (!$result->wasSuccessful()) { $this->say('Aborting installation due to some errors'); return false; } } }
  32. 32. /robo/config dir: src: 'src' bin: 'bin' build: 'build' bin: composer: 'vendor/bin' npm: 'node_modules/.bin' public function setupInstall($env = self::ENV_DEV) { $config = RoboRobo::Config()->export(); // ... }
  33. 33. /robo/io public function identify() { $this->yell('Hey!!! Welcome to Winterfel', 'blue'); $this->io()->choice('Who are you?', [ 'John Snow', 'Tyrion Lannister', 'Danaerys Targaryen' ]); $this->ask('What do you do?'); $this->say('Best answer ever'); }
  34. 34. /robo/filesystem public function logsWarmup() { $this->taskFilesystemStack() ->mkdir('logs') ->touch('logs/.gitignore') ->chgrp('www', 'www-data') ->symlink('/var/log/nginx/error.log', 'logs/error.log') ->run(); }
  35. 35. /robo/collections $this->collectionBuilder() ->taskExec('uname -n') ->printOutput(false) ->storeState('system-name') ->taskFilesystemStack() ->defer( function ($task, $state) { $task->mkdir($state['system-name']); } ) ->run();
  36. 36. /robo/integrations/vcs $this->taskGitStack() ->stopOnFail() ->add('-A') ->commit('adding everything') ->push('origin','master') ->tag('0.6.0') ->push('origin','0.6.0') ->run();
  37. 37. /robo/integrations/deps $this->taskComposerCreateProject() ->source('foo/bar') ->target('myBar')->run(); $this->taskNpmInstall()->run(); $this->taskBowerUpdate('path/to/my/bower') ->noDev() ->run(); $this->taskGulpRun('clean') ->silent() ->run();
  38. 38. /robo/integrations/testing $this->taskPHPUnit() ->group('core') ->bootstrap('test/bootstrap.php') ->run(); $this->taskBehat() ->format('pretty') ->noInteraction() ->run();
  39. 39. /robo/integrations/sysadmin $test = $this->taskDockerRun('test_env') ->detached() ->run(); $this->taskDockerExec($test) ->interactive() ->exec('./runtests') ->run();
  40. 40. /robo/extending <?php namespace BoedahRoboTaskDrush; use RoboCommonCommandArguments; use RoboTaskCommandStack; class DrushStack extends CommandStack { use CommandArguments; protected $argumentsForNextCommand; protected $siteAlias; protected $drushVersion; public function __construct($pathToDrush = 'drush') { $this->executable = $pathToDrush; } public function drupalRootDirectory($drupalRootDirectory) { $this->printTaskInfo('Drupal root: <info>' . $drupalRootDirectory . '</info>'); $this->option('-r', $drupalRootDirectory); return $this; } public function uri($uri) { $this->printTaskInfo('URI: <info>' . $uri . '</info>'); $this->option('-l', $uri); return $this; } } <?php namespace BoedahRoboTaskDrush; trait loadTasks { protected function taskDrushStack($pathToDrush = 'drush') { return $this->task(DrushStack::class, $pathToDrush); } }
  41. 41. /robo/extending?page=2 <?php use RoboTasks; class RoboFile extends Tasks { use BoedahRoboTaskDrushloadTasks; public function install() { $this->taskDrushStack() ->drupalRootDirectory('/var/www/html/some-site') ->uri('sub.example.com') ->maintenanceOn() ->updateDb() ->revertAllFeatures() ->maintenanceOff() ->run(); } }
  42. 42. summary
  43. 43. /summary/comparison phing robo Started in 2004 2014 Written in PHP yes yes Config format xml php Parallel execution yes yes Extendable yes yes Verbose yes no Learning Curve hard easy IDE support yes yes I/0 poor rich Scalable yes yes Symfony Components no yes
  44. 44. /summary/comparison?page=2 phing robo Github stars 776 1691 Github commits 3314 1335 Github PR 21 4 Github Issues 46 53 Github contributors 150 95
  45. 45. questions
  46. 46. thanks!!! https://slideshare.net/nass600/php-task-runners

Editor's Notes

  • animate
  • animate
  • Animate to show parallel
  • animate
  • Purple color
  • Fix this or remove it
  • Fix this or remove it

×