If your team uses Git and Continuous Integration, chances are good that your workflow could benefit from . But first, strap on your VR headset and experience the perils of through the eyes of our seasoned developer, Karen. git greenbase git pull Karen vs the broken build You arrive to work still flush with exertion from your morning run, a smile on your face and a bounce in your step — the light bulb went off mid run: you knew why the identity service was flaking out every morning at 11:48AM. Firing up the console, you to the right repo and flows nimbly from your fingertips, your heel tapping out the beat to the last song on your playlist; it was a good one. cd git pull Git decides it needs to repack and take out the garbage on your oversized repo. You roll your eyes slightly, but no bother — nothing can get you down today. You’re in and out of Vim in a flash. Hard to believe such a simple three-line change would alleviate so much misery for the Ops peeps. You glance at the clock. It just might be possible to get it diffed to code review before the daily standup. Just one thing left to do… Run the tests. “That’s funny…” “That’s funny… 17 tests failed???” You furrow your brow in consternation. “How did my change possibly break the Time widget”, you think, shaking your head. Down below, your once merry foot had stopped tapping, its good beats forgotten. The next ten minutes sneak past you like a puma as you pour over all the source files even remotely related to your fix. Still nothing. A blip on the screen shocks you from your concentration like a cold pie to the face. “You coming to the standup?” Yikes, I’m late! Skidding to a halt Coyote-style near the great semicircle of agility, you sidle up next to your buddy Anne. Everyone looks faintly amused, but they’re not looking at you. Tom is apologizing for breaking the build. “Sorry I’m late everybody”, you interject meekly. “I was looking at some tests I broke.” Tom looks at you sheepishly. “By any chance, were they 17 tests in the Time widget?” Slumping forward, you let out an overly dramatic exasperated sigh of frustration. The team glances around for a second, then bursts into laughter. It was a knowing laugh, one of commiseration and mutual understanding. Where vanilla falls short git pull What happened to you in our story? You pulled a broken build! That sent you down a rabbit hole searching in vain for a problem you didn’t cause. You ran to pull in the latest changes, but think about it, did you really want the changes? Or did you want the latest changes? When people build a house, they take time to prepare the land and the foundation. They don’t just start building on a pile of junk. Likewise, when we start development of a new feature or bug fix, we should start from a known good place. That gives you the confidence that any build or test failures really are fault, and not from Anne, Tom, or that one intern that rides around the office on a unicycle. git pull latest good your If your team practices and has a solid suite of automated tests, your source of truth for what constitutes a “known good build” is your CI server. Continuous Integration (CI) to the rescue! git greenbase This is where comes in. Instead of blindly running like a slot machine and hoping for the best, you run . It queries your CI server for the latest , or “green” build, then resets your local master to match. Voila! is now at a known good state. Start your coding engines with confidence! git greenbase git pull git greenbase passing master What about local feature branches? If you are on a local feature branch that tracks , and your team uses a rebase-based workflow, then still resets to match the green build, but it rebases your local feature branch on top of master. Pretty cool, huh? master git greenbase master also Installing git greenbase sits serenely on Github: . If you’re on Linux, install it like this: git greenbase https://github.com/tygerbytes/git-greenbase git clone cd git-greenbase ./install https://github.com/tygerbytes/git-greenbase.git The script will create a symlink to git-greenbase and add it to your PATH. Git will find it in your path and allow you to run , just like any Git command. ./install git greenbase (See the for the latest installation instructions.) repo But what about Mac and Windows? As of March 2018 git greenbase has only been tested with Linux. It works with Mac OS X as well. It most likely won’t work on Windows. I am totally open to pull requests. If demand is great enough, I’ll write a version in PowerShell. probably as is Configure to work with your CI provider git greenbase Now that it’s installed, how do you configure it to work with your CI provider? Typically you need to provide Git with your CI server’s URL, API token, and the ID of your project. The information is stored in your Git config. For example, if you use Travis CI, you would run commands similar to the following: git config . traviscigit config greenbase. git config greenbase.travisci. git config greenbase.travisci. greenbase provider travisci.token <TOKEN> serverUri <SERVER_URI> repoId <GITHUB_REPO_ID> ( for the latest configuration instructions.) See the repo Which CI providers are supported? As of March 2018 the only CI providers supported out of the OSS box are: Gitlab Travis CI TFS (Not well-tested) That’s a short list! If you would like to add support for another CI provider, feel free to send me a pull request. See below under “Contributing to development.” Contributing to development git greenbase is written in Bash, and tested using the . git greenbase Bats testing framework I tried my best to design it in a modular fashion for testability and maintainability. For example, the logic for communicating with each CI provider lives in its own Bash script, with its Bats tests alongside it in the same directory. Personally, , nor am I a super skilled Bash developer. That said, I feel tools like will bring more peace, love, and butterflies to the DevOps landscape. So I persevere. :) Bash isn’t my favorite language git greenbase See the for the latest development details. development page Can I buy you a coffee? If you’re super stoked about and all the pain it has saved you and your team, . I find coffee a great motivator. git greenbase buy me a coffee Originally published at tygertec.com on March 5, 2018.
Share Your Thoughts