|
| 1 | +.. -*- coding: utf-8 -*- |
| 2 | +
|
| 3 | +========================================== |
| 4 | +Essential Continuous Integration Practices |
| 5 | +========================================== |
| 6 | + |
| 7 | +The CI system at `jenkins.plone.org <http://jenkins.plone.org>`_ is a shared resource for Plone core developers |
| 8 | +to notify them of regressions in Plone core code. |
| 9 | + |
| 10 | +Build breakages are a normal and expected part of the development process. |
| 11 | +Our aim is to find errors and eliminate them as quickly as possible, without expecting perfection and zero errors. |
| 12 | +Though, there are some essential rules that needs to be followed in order to achieve a stable build. |
| 13 | + |
| 14 | +1) Don’t Check In on a Broken Build |
| 15 | +=================================== |
| 16 | + |
| 17 | +Do not make things more complicated for the developer who is responsible for breaking the build. |
| 18 | + |
| 19 | +If the build breaks, the developer has to identify the cause of the breakage as soon as possible and should fix it. |
| 20 | + |
| 21 | +If we adopt this strategy, we will always be in the best position to find out what caused the breakage and fix it immediately. |
| 22 | + |
| 23 | +If one of the developers has made a check-in and broken the build as a result, we have the best chance of fixing |
| 24 | +the build if we have a clear look at the problem. |
| 25 | + |
| 26 | +Checking in further changes and triggering new builds will just lead to more problems. |
| 27 | + |
| 28 | +If the build is broken over a longer period of time (more than a couple of hours) |
| 29 | +you should either notify the developer who is responsible for the breakage, fix the problem yourself, |
| 30 | +or just revert the commit in order to be able to continue to work. |
| 31 | + |
| 32 | +.. note:: |
| 33 | + |
| 34 | + There is one exception to this rule. |
| 35 | + Sometimes there are changes or tests that depend on changes in other packages. |
| 36 | + If this is the case, |
| 37 | + there is no way around breaking a single build for a certain period of time. |
| 38 | + In this case run the all tests locally with all the changes and commit them within a time frame of 10 minutes. |
| 39 | + |
| 40 | + |
| 41 | +2) Always Run All Commit Tests Locally before Committing |
| 42 | +======================================================== |
| 43 | + |
| 44 | +Following this practice ensures the build stays green and other developers can continue to work without breaking the first rule. |
| 45 | + |
| 46 | +There might be changes that have been checked in before your last update from the version control that might |
| 47 | +lead to a build failure in Jenkins in combination with your changes. |
| 48 | + |
| 49 | +Therefore it is essential that you check out (:command:`git pull`) and run the tests again before you push your changes to GitHub. |
| 50 | + |
| 51 | +Furthermore, a common source of errors on check-in is to forget to add some files to the repository. |
| 52 | + |
| 53 | +If you follow this rule and your local build passes, you can be sure that this is because someone else checked in in the meantime, |
| 54 | +or because you forgot to add a new class or configuration file that you have been working on into the version control system. |
| 55 | + |
| 56 | + |
| 57 | +3) Wait for Commit Tests to Pass before Moving On |
| 58 | +================================================= |
| 59 | + |
| 60 | +Always monitor the build’s progress and fix the problem right away if it fails. |
| 61 | + |
| 62 | +You have a far better chance of fixing the build, if you just introduced a regression than later. |
| 63 | +Also another developer might have committed in the meantime (by breaking rule 1) |
| 64 | +making things more complicated for your. |
| 65 | + |
| 66 | + |
| 67 | +4) Never Go Home on a Broken Build |
| 68 | +================================== |
| 69 | + |
| 70 | +Taking into account the first rule of CI ("Don't check in on a broken build"), breaking the build essentially |
| 71 | +stops all other developers from working on it. |
| 72 | + |
| 73 | +Therefore going home on a broken build (or even on a build that has not finished yet) is **not** acceptable. |
| 74 | +It will prevent all the other developers to stop working on the build or fixing the errors that you introduced. |
| 75 | + |
| 76 | + |
| 77 | +5) Always Be Prepared to Revert to the Previous Revision |
| 78 | +======================================================== |
| 79 | + |
| 80 | +In order for the other developers to be able to work on the build, you should always be prepared to revert |
| 81 | +to the previous (passing) revision. |
| 82 | + |
| 83 | + |
| 84 | +6) Time-Box Fixing before Reverting |
| 85 | +=================================== |
| 86 | + |
| 87 | +When the build breaks on check-in, try to fix it for ten minutes. |
| 88 | +If, after ten minutes, you aren’t finished with the solution, revert to the previous version from your version control system. |
| 89 | +This way you will allow other developers to continue to work. |
| 90 | + |
| 91 | + |
| 92 | +7) Don’t Comment Out Failing Tests |
| 93 | +================================== |
| 94 | + |
| 95 | +Once you begin to enforce the previous rule, the result is often that developers start commenting out |
| 96 | +failing tests in order to get the build passing again as quick as possible. |
| 97 | + |
| 98 | +While this impulse is understandable, it is **wrong**. |
| 99 | + |
| 100 | +The tests have been passing for a while and then start to fail. |
| 101 | +This means that we either caused a regression, made assumptions that are no longer valid, |
| 102 | +or the application has changed the functionality being tested for a valid reason. |
| 103 | + |
| 104 | +You should always either fix the code (if a regression has been found), modify the test |
| 105 | +(if one of the assumptions has changed), or delete it (if the functionality under test no longer exists). |
| 106 | + |
| 107 | + |
| 108 | +8) Take Responsibility for All Breakages That Result from Your Changes |
| 109 | +====================================================================== |
| 110 | + |
| 111 | +If you commit a change and all the tests you wrote pass, but others break, the build is still broken. |
| 112 | +This also applies to tests that fail in ``buildout.coredev`` and don't belong directly to the package you worked on. |
| 113 | + |
| 114 | +This means that you have introduced a regression bug into the application. |
| 115 | + |
| 116 | +It is **your responsibility** — because you made the change — to fix all tests that are not passing as a result of your changes. |
| 117 | + |
| 118 | +There are some tests in Plone that fail randomly, we are always working on fixing those. |
| 119 | +If you think you hit such a test, try to fix it (better) or re-run the Jenkins job to see if it passes again. |
| 120 | + |
| 121 | +In any case the developer who made the commit is responsible to make it pass. |
| 122 | + |
| 123 | + |
| 124 | +Further Reading |
| 125 | +=============== |
| 126 | + |
| 127 | +Those rules were taken from the excellent book "Continuous Delivery" by Jez Humble and David Farley (Addison Wesley), |
| 128 | +and have been adopted and rewritten for the Plone community. |
| 129 | + |
| 130 | +If you want to learn more about Continuous Integration and Continuous Delivery, I'd recommend that you buy this book. |
0 commit comments