Understanding the Basics of GitHub Actions
Explore the fundamental components of GitHub Actions such as workflows, events, context, jobs, steps, and reusable actions. Understand how to trigger and compose automation tasks within your repository to build efficient CI/CD pipelines.
We'll cover the following...
GitHub Actions are event-driven automation tasks that live within a GitHub repository. An event like a pull request can trigger a set of tasks to be executed. An example is a pull request triggering a set of tasks to clone the Git repository and execute go test to run Go tests.
GitHub Actions is extremely flexible, enabling developers to author a wide variety of automation, even some that we might not normally associate with a traditional continuous integration/release pipeline. Actions are also composable, enabling groups of tasks to be packaged together as a published action and used in workflows together with other actions.
In this lesson, we will learn about the components of a GitHub Action: workflows, events, context and expressions, jobs, steps, and actions. After we have been introduced to these components, we'll build and trigger our first GitHub Action.
Exploring the components of a GitHub Action
Understanding the components of a GitHub Action, their relationships, and how they interact is the key to understanding how to compose our own automation. Let's get started with exploring the components of an action.
Workflows
A workflow is an automation file written in YAML that lives in a GitHub repository in the ./github/workflows/ folder. A workflow consists of one or more jobs and can be scheduled or triggered by an event. A workflow is the highest-level component of a GitHub Action.
Workflow syntax
Workflows require a developer to specify the events that will trigger automation via the on key and the jobs that automation will execute when it is triggered by the jobs key. Often, a name is also specified by the name keyword. Otherwise, the workflow will take the short name of the file that contains the workflow YAML. For example, the workflow defined in ./github/workflows/foo.yaml will have the default name of foo.
The following is an example of a named workflow with the minimum set of keys defined. However, this is not a valid workflow, as we have not yet defined any events to trigger the workflow nor any jobs to be executed once triggered:
Next, let's discuss how to trigger workflows.
Events
An event is a trigger that causes a workflow to start ...