Continuous integration with Git & CI Joe

6,983 views

Published on

Published in: Technology

Continuous integration with Git & CI Joe

  1. 1. <ul>Simple Continuous Integration using Git and  CI Joe </ul><ul>Shawn Price drupal.org: langworthy twitter: @sprice </ul>
  2. 2. <ul>Continuous Integration Defined </ul><ul>&quot;Continuous Integration is a software development practice where members of a team integrate their work frequently...&quot; &quot;Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly&quot; - Martin Fowler </ul><ul>martinfowler.com/articles/continuousIntegration.html </ul>
  3. 3. <ul>Continuous Integration Defined </ul><ul>Continuous Integration is a fancy term for “run your project’s tests after someone pushes to the repository and notify interested parties if they fail” - Chris Wanstrath </ul><ul>github.com/blog/471-continuous-integration-spring-cleaning </ul>
  4. 4. <ul>Components of Continuous Integration </ul><ul><ul><li>Use a code repository
  5. 5. Test your code
  6. 6. Automate the testing </li></ul></ul>
  7. 7. <ul>Use a code repository </ul>
  8. 8. <ul>Use a code repository </ul><ul>In the beginning there was FTP. </ul>
  9. 9. <ul>Use a code repository </ul><ul>In the beginning there was FTP. And things were good. </ul>
  10. 10. <ul>Use a code repository </ul><ul>5 minutes later.... </ul>
  11. 11. <ul>Use a code repository </ul><ul>5 minutes later.... Things were bad. </ul>
  12. 12. <ul>Use a code repository </ul><ul>5 minutes later.... Things were bad. &quot;Who made that change?&quot; &quot;There's a bug, lets put the previous version of the file back&quot; etc. </ul>
  13. 13. <ul>Use a code repository </ul><ul>Greetings Git! </ul>
  14. 14. <ul>Use a code repository </ul><ul>Greetings Git! A free & open source distributed version control system. </ul><ul><ul><li>git-scm.com/
  15. 15. progit.org/book/
  16. 16. drupal.org/community-initiatives/git </li></ul></ul>
  17. 17. <ul>Use a code repository </ul><ul>Using a code repository allows teams to: </ul><ul><ul><li>track the history of changes
  18. 18. use branches to manage feature integration
  19. 19. efficiently deploy to production
  20. 20. efficiently roll-back changes </li></ul></ul>
  21. 21. <ul>Use a code repository </ul><ul>Meet the Amazing Module! </ul>
  22. 22. <ul>Use a code repository </ul><ul>DEMO time:  </ul><ul><ul><li>Create a new git repository
  23. 23. Include Drupal and the Amazing module </li></ul></ul>
  24. 24. <ul>Test your code </ul>
  25. 25. <ul>Test your code </ul><ul>Drupal 6: drupal.org/project/simpletest Simpletest is in Drupal 7 core. </ul>
  26. 26. <ul>Test your code </ul><ul>amazing.test </ul><ul><?php </ul><ul>class AmazingTestCase extends DrupalWebTestCase {    public static function getInfo () {      return array (        'name' => t( 'Amazing functionality' ),        'description' => ( 'Test for amazingness' ),        'group' => t( 'Amazing' ),      );    }    function setUp () {      parent:: setUp ( 'amazing' );    }    public function testAmazingPageContent () {      $this -> drupalGet ( &quot;amazing&quot; );      $this -> assertResponse ( 200 );      $this -> assertText (t( 'Simply amazing!' ));    } } </ul>
  27. 27. <ul>Test your code </ul><ul>DEMO time: </ul><ul><ul><li>running tests in the Drupal UI
  28. 28. running tests with drush -  github.com/yhahn/drush_test </li></ul></ul>
  29. 29. <ul>Automate the testing </ul>
  30. 30. <ul>Automate the testing </ul><ul>Choosing a Continuous Integration server </ul>
  31. 31. <ul>Automate the testing </ul><ul>Choosing a Continuous Integration server </ul><ul><ul><li>Hudson?
  32. 32. Cruise Control?
  33. 33. and more... </li></ul></ul>
  34. 34. <ul>Automate the testing </ul><ul>Choosing a Continuous Integration server </ul><ul><ul><li>Hudson? (Java)
  35. 35. Cruise Control? (Java)
  36. 36. and more... (many are tricky to install) </li></ul></ul>
  37. 37. <ul>Automate the testing </ul><ul>Meet CI Joe! github.com/defunkt/cijoe </ul>
  38. 38. <ul>Automate the testing </ul><ul>CI Joe was created out of the desire to do CI simply </ul><ul><ul><li>configure via git config
  39. 39. $ git config --add cijoe.runner &quot;drush test MyTestCase&quot;
  40. 40. use git hooks for notifications
  41. 41. easy to install with few dependencies (Ruby)
  42. 42. $ gem install cijoe
  43. 43. $ git clone git://github.com/you/yourrepo.git
  44. 44. $ cijoe yourrepo </li></ul></ul>
  45. 45. <ul>Automate the testing </ul><ul><ul><li>CI Joe runs when it receives a POST </li></ul></ul>
  46. 46. <ul>Automate the testing </ul><ul><ul><li>CI Joe runs when it receives a POST
  47. 47. $ curl -d &quot;payload&quot; http://ci.example.com:4567 </li></ul></ul>
  48. 48. <ul>Automate the testing </ul><ul><ul><li>Notifications are sent via git hooks </li></ul></ul>
  49. 49. <ul>Automate the testing </ul><ul><ul><li>Notifications are sent via git hooks </li></ul></ul><ul>     .git/hooks/build-worked </ul><ul><ul><li>#!/bin/bash
  50. 50. EMAIL=&quot;me@example.com&quot;
  51. 51. /usr/sbin/sendmail &quot;$EMAIL&quot; <<EOD
  52. 52. To: $EMAIL
  53. 53. Subject: Your tests passed
  54. 54. From: Testbot <testbot@ci.example.com>
  55. 55. The latest integrations are good. The tests passed.
  56. 56. EOD </li></ul></ul>
  57. 57. <ul>Automate the testing </ul><ul><ul><li>Notifications are sent via git hooks </li></ul></ul><ul>     .git/hooks/build-failed </ul><ul><ul><li>#!/bin/bash
  58. 58. EMAIL=&quot;me@example.com&quot;
  59. 59. /usr/sbin/sendmail &quot;$EMAIL&quot; <<EOD
  60. 60. To: $EMAIL
  61. 61. Subject: Your tests failed
  62. 62. From: Testbot <testbot@ci.example.com>
  63. 63. The latest integrations are bad. The tests failed. Better luck next time.
  64. 64. EOD </li></ul></ul>
  65. 65. <ul>Bringing it all together </ul><ul><ul><li>push changes to remote git repository </li></ul></ul>
  66. 66. <ul>Bringing it all together </ul><ul><ul><li>push changes to remote git repository
  67. 67. Post-Receive URL triggers a POST to CI Joe </li></ul></ul>
  68. 68. <ul>Bringing it all together </ul><ul><ul><li>push changes to remote git repository
  69. 69. Post-Receive URL triggers a POST to CI Joe
  70. 70. CI Joe runs tests </li></ul></ul>
  71. 71. <ul>Bringing it all together </ul><ul><ul><li>push changes to remote git repository
  72. 72. Post-Receive URL triggers a POST to CI Joe
  73. 73. CI Joe runs tests
  74. 74. CI Joe sends notification via git hook </li></ul></ul>
  75. 75. <ul>Bringing it all together </ul><ul>DEMO TIME! </ul>
  76. 76. <ul>Questions? </ul>
  77. 77. <ul>Thank You. </ul>

×