Introduction
GitHub Actions (GHA) is a service for continuous integration & deployment.

But you don’t have to consider yourself a software engineer to use it! Any repetitive task can potentially be automated with GitHub Actions. Just a few examples:
- Test your code every time changes are pushed
- Reformat code when a pull request is opened
- Build a website when documentation files are changed
- Render a report on a schedule
- Build and push a docker container for every new release
How to write GitHub Actions workflows
Workflows are defined as YAML files in a specific directory in your repo: .github/workflows/.
Create this directory if you haven’t already:
mkdir -p .github/workflows/Create a YAML file:
touch .github/workflows/hello-world.ymlAnd open it in your favorite text editor.
Anatomy of a GHA workflow
.github/workflows/hello-world.yml
- 1
- Name of the workflow
- 2
- Triggers: events that cause the workflow to run
- 3
- Name of a job. Jobs can run sequentially or in parallel.
- 4
- Which virtual machine to run the job on
- 5
- List of steps in the job
- 6
- A single step or action that runs bash code
- 7
- A multiline step
How to run your first workflow
Copy the above YAML code to .github/workflows/hello-world.yml and save the file.
Add, commit, and push your workflow file to GitHub:
git add .github/workflows/hello-world.yml
git commit -m 'ci: create hello-world workflow'
git pushIn a web browser, navigate to your repo’s Actions tab. On the left sidebar you’ll see the name of your action: click on it and you’ll see a list of the workflow runs (i.e. times it was executed). Click on the most recent run to see the details of the execution and the logs for each step.

Actions steps
Writing custom steps for your workflows is powerful, but you’re not limited to only what you can implement. You can reuse Actions created by others’, including many that are maintained by GitHub.
.github/workflows/hello-checkout.yml
- 1
-
Use the action from actions/checkout to checkout the repo. The version is specified with
@v4. - 2
- Name of the run step (optional).
- 3
-
List the files in the repo, which was checked out to the
github.workspacevariable.
github.workspace is a variable defined by GHA1. You can access variables in workflows with a dollar sign and double curly braces: ${{ variable }}.
The current working directory is github.workspace by default, and this is where your repo is checked out.
Triggers
So far we’ve used the push trigger, which triggers the workflow to run every time a commit is pushed to the repo on GitHub. There are a myriad of triggers2 you can use, and you can mix-and-mitch in the same workflow. Here are a few of the most common triggers:
.github/workflows/demo-triggers.yml
- 1
- Triggers the workflow on push or pull request events, but only for the “main” branch.
- 2
- Allows you to run this workflow manually from the Actions tab.
- 3
- Triggers the workflow on a cron schedule3. This one runs at 12:00 UTC on every Monday.
- 4
- Print the event that triggered the run.
Let’s try running this workflow manually! After you add this workflow to your repo, navigate to the Actions tab and click on the workflow name. A button will appear: run workflow. Click it and select the branch you want to run on. Refresh the page and you will see your manually triggered run in the log. What is the value in github.event_name when you run the workflow manually?

push
workflow_dispatchWhat now?
So far, we’ve learned the basics of how to write Github Actions workflows. Next you’ll see some useful examples of GHA in practice and learn about more advanced features along the way.
Footnotes
Contexts & variables https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#about-contexts↩︎
Events that trigger workflows https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows↩︎
Website to help understand cron schedule syntax https://crontab.guru/↩︎