Writing about continuous integration or continuous deployments seems a little funny to me given that I’ve done this before and given that I know a lot of developers already use this as part of their day-to-day.
But I also know that there are a lot of hobbyists, beginners, and those who are just starting out who are looking for ways to make sure they are setting up solid practices for their work.
For what it’s worth, it wasn’t until I started working with a few more people that we began to incorporate a wider set of tools in our deployment process.
And that’s the purpose of this post.
That is:
- introduce the whole idea behind WordPress-focused continuous integration,
- introducing CircleCI,
- getting ready to chat more about it.
With that said, here’s the run down on all of the above.
WordPress-Focused Continuous Integration
First, what’s the big idea behind continuous integration anyway? So the general definition of continuous integration is:
In software engineering, continuous integration (CI) is the practice of merging all developer working copies to a shared mainline several times a day.
Depending on the source control system of choice, what’s considered your “mainline” will vary. If you’re using GitHub, it’s likely going to be your master branch (which is why we should always do work in separate branches, have code reviews, and set up pull requests).
Then take whatever is in master and have it deployed to your staging server or your production server.
And though there are a lot of tools for that, my team and I have been using CircleCI for a few projects and I’m definitely a fan (plus, they just released the second version of their work).
1. What is CircleCI?
CircleCI pins itself simply as:
Create custom environments, apply Workflows for control over your build pipeline, enjoy flexible resource allocation, and more.
About which I have mixed feelings. I mean, it’s all true and it does allow for us to have customization over a number of different aspects of our deployments but in terms of being less intimidating to those just getting started, I don’t know.
Regardless, I have found that it can be as simple or as complex as your project needs. And since this is more about sharing the reasons for it, I won’t bother going into all it offers.
At least not in this post.
2. How Do We Use It?
Assuming you have a GitHub project already setup, it’s really easy to connect CircleCi to your project.
Whenever you sign up, you can connect with GitHub, Bitbucket, or Google (though I’m a fan of starting either with GitHub or Bitbucket considering they have the repositories for code that many of us in WordPress, at least, most commonly use).
From there, you’ll need to setup a webhook to CircleCI. This will essentially have CircleCI run through the variety of tools that you have setup and to build your project. I’ll talk more about this in a moment.
- If the build is successful, then you’ll receive one such notification and you can request a code review or merge the branch into master.
- If the build fails, it will (and should) block the ability to merge the branch until there is a successful build.
With that said, what might the tools include that are part of a build process for a WordPress project? Given that much of a WordPress project usually includes PHP and JavaScript, you may use a few of these:
- GrumPHP
- PHP CodeSniffer
- PHPMD
- ESLint
- And much more.
If you’ve configured GrumPHP correctly, it will watch every commit that goes into your repository (even when it’s a local commit – that is, before you push upstream to GitHub).
Thus, you should know if there’s a problem with your code before you even push it upstream. Once the local checks have completed, you’re then ready to push it to your repository. CircleCI will then execute the same operations based on your configuration in the environment you’ve configured.
If all goes well, then it’ll pass and, as mentioned, you can merge it. Otherwise, you’ll need to fix whatever errors it reports, recommit, and push. Usually, if it passes a local commit it will pass a push. But that’s not always the case so don’t assume as much.
More To Come
Obviously, this is just scratching the surface of what continuous integration can do. Honestly, I don’t even know if I’d say that – instead, it’s more about introducing the idea of continuous integration and the benefits it gives especially when working with a team.
Though I’ve tried a variety of different tools, I have to say that I’ve been most satisfied with what CircleCI offers. One of the things that’s best of all is that if you opt to build on a Linux box, then it’s free to use. And that works well for a small team who’s looking to stay lean.
Anyway, there’s more to cover regarding this so I’m looking to do that in future posts.