Building GitHub Actions
I’m Michael and I love GitHub Actions. I work on a team that’s built a complex platform to solve exactly the problems we need it to. Of course, this comes at a cost.
Data is stored across multiple repos, with various submodules and test suites that all need to stay in sync. People were struggling to make changes because our workflows were… well, they made doing your taxes look fun. They were repetitive, yet somehow still error prone at the same time.
Then GitHub Actions came along and solved all our problems. What was a complex process involving commits to multiple repos suddenly became as simple as merging a pull request. The time taken to validate changes and get them merged dropped from 20 minutes to 60 seconds overnight.
That was back in October 2018. Since then, I’ve built over a dozen GitHub Actions to automate our workflows with even more in the works. I’ve learned which libraries to use when building Actions, how to test them locally and how to build tools to make building Actions even easier. Now, I want to show you how to do the same.
Table of Contents
Learn what GitHub actions are and how they can be used. You might be surprised, but you can do more than just running CI scripts!
CREATING AN ACTION
Learn where Actions live on GitHub, what files are required and how to build your first action by following a step-by-step guide
USING YOUR ACTION
Build a workflow that runs the action that you built in response to events on GitHub. Learn how to handle events such as pull_request and push and understand the information available
RUNNING YOUR ACTION LOCALLY
The commit, push, wait cycle gets repetitive very quickly. Run your actions locally to reduce the time it takes to get feedback and iterate on your workflows
BUILD A REAL-WORLD ACTION USING BASH
Understand how things work under the hood by building an action that interacts with the GitHub API and data in event.json to automatically add comments when pull requests are merged
BUILDING WITH NODE.JS
Reimplement the Action from the previous chapter using Node.js, taking advantage of @actions/core and @actions.github to reduce the amount of code you have to write
Make the most of the GitHub Actions ecosystem, using third party libraries to reduce the amount of code you need to write even further!
WRITING UNIT TESTS
Your action’s working, congratulations! But how do you know it’ll continue to work? How does it handle the edge cases? Learn how to write unit tests for your action by mocking both the event.json and GitHub API
PUBLISHING YOUR ACTION
Writing an action isn’t where the story ends. Once your action is built, it’s time to publish it! Learn what you need to make your action official and publish it in the GitHub Marketplace
Extra bonus action! Learn how to build an action that runs on a schedule to create an issue every week summarising the activity in a repository
ACTIONS TIPS AND TRICKS
I learned the hard way so that you don’t have to. Learn about debugging, semantic versioning, secret management and more!
Congratulations, you made it to the end! By now you’ll know that Actions are for more than just Continuous Integration. You’ve built multiple actions, configured workflows and released them to the marketplace. I’ll leave you with some ideas for even more actions to build to enhance your skills