How to Make GitHub Pull Request Check with a Few Clicks on AWS

Alexey Balchunas
3 min readOct 1, 2018

--

Nowadays, automatic testing and linting of your code are just a must-have.

Fortunately, you’ve everything you need to set up such a checker on GitHub using AWS. Especially now, when Amazon made it a built-in feature of AWS CodeBuild.

By the way, up until now, we haven’t been using this feature of CodeBuild, because we had a nicely working CloudFormation template doing the same exact thing, for details check the corresponding repo. However, this is not a recommended way of testing you PRs anymore, so I’ve migrated our PRs to use CodeBuild instead for this particular article. Enjoy!

Setting Up CodeBuild

First, go straight to the project creation page of CodeBuild, you will see this:

Choose GitHub as your Source provider, then select the required repository. Also, you will definitely need to check Report build status, Webhook and Build Badge to be able to see the check status directly on GitHub Pull Request page. Note, that I’ve specified Branch filter as ^((?!master).)*$, this is just a regular expression saying that I don't want to perform the checks on the master branch of the repo, you may want to specify something else here or leave it empty.

Here you need to specify Environment image. I’d recommend specifying a docker image with all required dependencies installed. You can easily create such an image completely for free on Docker Hub. If you’d like to know how exactly to create a docker image using Docker Hub, consider to sign up to the mailing list at the bottom of the page. I share many tips and tricks for subscribers only.

Then, you will need to describe how to run the testing process. You’ve 2 options: put a spec file buildspec.yml in the source root or put the specification commands directly on CodeBuild. I used the latter option, here is what I’ve put there:

version: 0.2phases:
build:
commands:
- ./full-test.sh

Meaning, the check will just run a shell script with all my tests.

Also, consider to change the Timeout setting (in the advanced settings section) to some reasonable value for your tests, the default value is 60 minutes which is too much in most cases.

All the other settings may be left as is.

Fixing GitHub Settings

Well, after you’ve created the project, you are done. However, there is a small issue you might want to fix.

The problem is that CodeBuild will run the tests for all your branches, not only for Pull Requests. Fortunately, it’s quite easy to fix.

Go to the settings of your repository on GitHub, go to Webhooks, find the CodeBuild webhook there, and then just uncheck the push event, so that the tests are executed for Pull Requests only.

What’s Next?

If you liked the article, don’t miss the next one by following me on medium.

Also, besides these articles, I share many tips and thoughts to subscribers of the mailing list only, so consider subscribing.

Comments, likes, and shares are highly appreciated. Cheers!❤️

--

--