GitHub Actions is GitHub's built-in automation platform for CI/CD: it builds, tests and deploys your code, and can react to other repository events, directly from the repository. You describe the automation in a YAML file under .github/workflows, and GitHub runs it on a virtual machine whenever the trigger you chose happens.
If you are new to GitHub itself, what GitHub is used for covers the basics first. This article assumes you have a repository and want to know what Actions adds to it.
What GitHub Actions does
GitHub's documentation describes Actions as a CI/CD platform. CI/CD stands for continuous integration and continuous delivery (or deployment): every change is built and tested automatically, and passing changes can be released automatically too. Typical jobs are running a test suite on every pull request, building a release when you push a tag, and publishing a site after a merge.
It is not limited to that. Any event in a repository can start a workflow. The documentation's own example is automatically labelling a newly opened issue. Because the automation lives in the same repository as the code, the workflow file is versioned, reviewed and branched like everything else.
The six parts of GitHub Actions
Everything in Actions is built from six concepts. The definitions below follow GitHub's documentation.
| Term | What it is |
|---|---|
| Workflow | A configurable automated process that runs one or more jobs. It is one YAML file. |
| Event | A specific activity in a repository that triggers a workflow run, such as a push or an opened pull request. |
| Job | A set of steps executed on the same runner. Jobs run in parallel by default. |
| Step | One unit inside a job. It either runs a shell command you wrote or uses an action. Steps run in order. |
| Action | A pre-defined, reusable set of jobs or code that performs a specific task. You can write your own or find them in the GitHub Marketplace. |
| Runner | The server that runs your workflow when it triggers. Each runner runs one job at a time. |
The relationships matter more than the names. An event starts a workflow. The workflow contains jobs. Each job is sent to its own runner, and gets a fresh virtual machine for every run. The steps inside a job share that machine, so one step can create a file that the next step reads. Two different jobs do not share a machine, so they do not share files unless you pass them along explicitly.
A working workflow example
This is the example from GitHub's quickstart. Save it as .github/workflows/github-actions-demo.yml and commit it:
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "This job is now running on a ${{ runner.os }} server hosted by GitHub."
- name: Check out repository code
uses: actions/checkout@v6
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "This job's status is ${{ job.status }}."
I trimmed a few of the quickstart's echo lines and its emoji for brevity. Here is what each part does:
nameis the workflow's display name in the Actions tab. If you leave it out, GitHub shows the file path.run-namenames each individual run. It can use expressions such as${{ github.actor }}, the user who triggered the run.on: [push]is the event. Every push to the repository starts this workflow. You can pass a single event, a list, or filters such asbranches,pathsandtags.jobsholds one or more jobs. Here there is one, with the IDExplore-GitHub-Actions. A job ID must start with a letter or an underscore and can contain only letters, numbers, hyphens and underscores.runs-on: ubuntu-latestpicks the runner: a GitHub-hosted Linux machine.runexecutes a shell command.usesruns an action, hereactions/checkout, which copies your repository onto the runner. Without a checkout step, the runner has none of your files.
The ${{ ... }} syntax is an expression. GitHub replaces it with a value at run time, for example the event name or the runner's operating system.
How to see a workflow run
After you push the file, open the repository on GitHub and follow the quickstart's steps:
- Click the Actions tab.
- In the left sidebar, click the workflow name, GitHub Actions Demo.
- In the list of runs, click the run you want. Runs are named after the user who triggered them.
- Under All jobs, click the job.
- Expand any step to read its log output.
A failed step turns the job red, and the log shows the command output that explains why. That log is the first place to look when a run fails.
How to run jobs in order
Jobs run in parallel unless you say otherwise. To make one job wait for another, use needs:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- run: echo "run your tests here"
deploy:
needs: test
runs-on: ubuntu-latest
steps:
- run: echo "runs only after test succeeds"
The deploy job starts only after test finishes. By default, a failed test job means deploy does not run, which is the behaviour you want when deployment should depend on passing tests.
Triggers other than push
The on key accepts many events. Three common patterns:
- Pull requests. Run tests before a change is merged.
- Schedules. A scheduled workflow runs at set times. According to the workflow syntax reference, the shortest interval is every 5 minutes, and schedules run in UTC unless you set a time zone.
- Manual runs. The
workflow_dispatchevent adds a button in the Actions tab, and it can take inputs (up to 25 top-level properties).
Several triggering events on one workflow can start several runs.
GitHub-hosted and self-hosted runners
GitHub provides runners for Linux, Windows and macOS, so you do not have to maintain build machines. You pick one with runs-on. If you need specific hardware, network access to private systems or software GitHub's images lack, you can host your own runner and point runs-on at it instead.
On cost, GitHub's billing documentation says standard GitHub-hosted runners are free in public repositories, and self-hosted runners do not use your included allowance. Private repositories get a monthly allowance that depends on your plan, which the page expresses as a dollar amount of compute rather than a fixed number of minutes. Larger runners are billed even in public repositories. These numbers change, so read the billing page before you rely on them.
Secrets and safety
Workflows often need a token or password. Do not write it into the YAML. Store it as a secret under Settings > Secrets and variables > Actions > Secrets in the repository, or with the GitHub CLI:
gh secret set SECRET_NAME
Then read it in a step through the secrets context:
env:
super_secret: ${{ secrets.SuperSecret }}
A few rules from GitHub's documentation are worth knowing early:
- Except for
GITHUB_TOKEN, secrets are not passed to workflows triggered from a forked repository. - Secrets cannot be used directly in
if:conditions. Put them in a job-level environment variable and test that instead. - If a secret is not set, the expression returns an empty string rather than an error.
- Pass secrets to commands through environment variables, not inline on the command line, where other users on the machine may see them.
If you need to generate a strong random value for a secret first, a password generator that runs in your browser does the job.
If your workflow does not run
Check these in order:
- File location. The file must be in
.github/workflowsand end in.ymlor.yaml. A file anywhere else is ignored. - Branch. Workflows run from the version of the file on the branch that triggered the event. If you added the file on a branch you have not pushed, nothing fires.
- Trigger mismatch. If
onhas filters such asbranchesorpaths, your push may not match them. - YAML errors. Indentation mistakes stop a workflow from loading. Open the Actions tab; GitHub reports a problem with the file there.
Frequently asked questions
- Is GitHub Actions free?
- Standard GitHub-hosted runners are free in public repositories. Private repositories get a monthly allowance of included compute that depends on your plan, and usage beyond it is billed. Self-hosted runners do not use the included allowance. Check GitHub's billing page for the current amounts, because they change.
- Is GitHub Actions the same as CI/CD?
- No. CI/CD is the practice of building, testing and deploying code automatically. GitHub Actions is one platform that can do it. It can also automate other repository events, such as labelling a newly opened issue.
- Where do I put a GitHub Actions workflow file?
- Store it in the .github/workflows directory at the root of your repository, with a .yml or .yaml extension. A repository can hold several workflow files, and each one runs independently when its trigger fires.
- Can I run GitHub Actions on my own machine?
- Yes, by installing a self-hosted runner on a server you control and pointing a job's runs-on at it. GitHub also offers hosted runners for Linux, Windows and macOS, so a self-hosted runner is optional.