Sixth installment of the Shape-Up Your Infrastructure Webinar Series – “Automated Cookbook Testing with GitHub Actions”.
Since GitHub is the preferred place for developers to be in the modern software development ecosystem, folks at Chef decided to make it convenient for Chef users to use Test Driven Development (TDD) and integrate Chef Infra runs within their existing Continuous Integration (CI) processes in GitHub. Since GitHub actions already help automate CI workflows, these actions can be used to run code changes through the Chef Test Kitchen and be validated through Chef Cookbooks before being pushed to release state.
GitHub Actions offer certain important benefits and when used alongside Chef can yield some amazing outcomes. Let’s discuss some of the most important ones in this blog.
- Unit Testing
- Integration Testing
- Issue Management
Linting and Unit Testing with Chef using GitHub Actions
Testing with Cookstyle
This allows Cookstyle, the linting tool by Chef to check for code style, syntax, and other mistakes or irregular patterns in code. Upon every check in, Cookstyle runs static code analysis to ensure that your code is always free of errors and is in the most optimal format.
Testing with rspec
rspec is a testing tool for Ruby that is based on the Behaviour-Driven Development (BDD) approach. The idea is to write tests in the form of specifications of system behaviour. Although not common in everyday Chef usage but in case you do have unit tests for specific methods written in rspec, those can be tested too to check for possible errors.
Validate YAML and Markdown files
GitHub actions will also allow you to validate YAML or Markdown files for consistency across multiple users and repositories. Developers can focus on actual change related work rather than dwelling on occasional YAML or Markdown errors.
Integration Testing with Chef using GitHub Actions
Test Kitchen Runs
Upon every check-in, GitHub Actions allows you to run Test Kitchen integration tests in the CI system across multiple operating systems like Linux (with Dokken), MacOS and Windows. More importantly, by allowing to run these integrations tests parallelly instead of one after the other, it helps save loads of time and makes feedback loops faster. These Integration tests are flexible allowing the ability to include or exclude specific use cases.
After a commit is made, the jobs released under the CI file are listed with errors and warnings that can be further viewed in detail to pinpoint errors. Also, a list of warnings are generated based on linting or unit test results prompting you to stay in the right lane with the best practices of creating code.
GitHub Actions streamlines CI pipeline processes by working in sync with Chef Infra runs and Test Kitchen and makes secure deployments faster. Since manual releases can often be time consuming, Chef uses automated processes to speed up the release process. Also, manual processes can lead to security vulnerabilities and problems in the form of poorly written or erroneous code. With Test Kitchen, only changes that pass the codified tests are allowed to be merged ensuring better security and faster deployments. Commit code, automate testing, and merge with confidence with GitHub Actions and Chef Cookbooks!
Learn more about Automating Cookbook Testing with GitHub Actions by watching this on-demand webinar by Jason Field, Delivery Consultant at ECS, and a long time user of Chef tools.
Automating Cookbook Testing with GitHub Actions by Jason Field.
Also check out our list of past and future events on the “Shape-up Your Infrastructure Automation” webinar series that will continue to run for the rest of 2021. You can find all the videos in the Chef Infra Best Practices Quickfire Webinars page.
You can also take a look at this eBook on Chef Infra Automation Best Practices for more information.