GitHub Actions for Dummies
Explain to your grandparents what GitHub Actions are in 5 minutes. This is a topic that is getting thrown around more and more with the rise of Pull Request Automation, we have found out that even software engineers don’t fully understand what they are, but here’s a quick fix.
A Cooking Analogy
Whenever we feel hungry, we go into the kitchen and use a recipe to cook.
In this action, a series of things happened. The first one was the event that triggered us to go into the kitchen and cook a recipe - feel hungry. The second one was the decision of where to execute/run our recipe - the kitchen. And finally what steps to follow - the recipe.
All these decisions have been orchestrated by us and can be summarized in the action of Eat when hungry with the following characteristics:
- Trigger event - feel hungry
- Execute on - the kitchen
- Execution steps - the recipe
GitHub actions work like this, but for GitHub repositories.
GitHub Actions
A GitHub Action is an automation (also called workflow), triggered by certain events, which will execute one or more jobs, on a specific machine (runner).
The core components are:
- Event: anything that happens inside the GitHub Repository. The list is pretty extensive. It goes from when labels are created, pull requests opened, or even when an issue is commented. The action can also be scheduled.
- Workflow: a workflow is triggered by an event and it’s comprised of one or more jobs run in parallel (that can also have dependencies between them).
- Jobs: A job is a series of steps to be executed in order. Each step is either a shell script that will be executed or an action that will be run.
- Runners: A runner is a server that runs one job at a time.
Github Actions— Everything You Need to Know to Get Started , by Ahmed Besbes
Let’s analyse a GitHub Action example: Run the linter on a pull request update in a deno project.
1name: Deno23on:4 pull_request:56jobs:7 test:8 runs-on: ubuntu-latest910 steps:11 - name: Setup repo12 uses: actions/checkout@v31314 - name: Setup Deno15 # uses: denoland/setup-deno@v116 uses: denoland/setup-deno@004814556e37c54a2f6e31384c9e18e98331736617 with:18 deno-version: v1.x1920 - name: Run linter21 run: deno lint
- Event: Update a pull request
- Jobs:
- Check out the repository
- Setup Deno
- Run the linter
- Runner: Linux machine
Do you want to know more? GitHub offers a pretty good documentation page on GitHub Action that’s actually pretty easy to understand. Check it out: Understanding Github Actions ↗︎.
But this is the subject of another For Dummies blog post.