Workflows, triggers, jobs and steps

Beginner · 8 min

Write your first GitHub Actions workflow: a YAML file that runs the tests when you push or open a pull request, built from triggers, jobs and steps.

Before thisPull requestsCreating and publishing a repositoryBranch protection and rulesets

GitHub · 8 min

Workflows, triggers, jobs and steps

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by GitHubReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A workflow is a YAML file in .github/workflows that GitHub runs automatically when an event in the on: section happens.
  • A workflow contains jobs, each job runs on a fresh runner, and each job is a list of steps that either use an action or run a shell command.
  • Jobs run in parallel unless one declares needs, and steps inside a job run in order and share the same working directory.
  • For a pull_request event the workflow runs against the merge of your branch into the base, not just your branch's tip.
  • A workflow that fails shows a red check on the pull request, and with a required status check in your rules it stops the merge.

Why automate the checks

So far the tests in the notes project run when someone remembers to type npm test. That is the weak point of any team process. A contributor forgets, a reviewer assumes they ran, and a broken change gets merged on trust.

GitHub Actions removes the trust. It runs commands on GitHub’s machines whenever something happens in your repository, such as a push or a pull request. The result appears on the pull request as a green tick or a red cross, and branch protection can refuse to merge without it. Automated checks like this are called continuous integration, CI for short.

The vocabulary

Four words cover nearly everything.

  • A workflow is one YAML file in .github/workflows/. A repository can have many.
  • An event is what starts it: a push, a pull request, a button press, a schedule. You list events under on:.
  • A job is a group of steps that runs on one fresh machine, called a runner. A workflow has one or more jobs.
  • A step is a single task in a job. It is either uses: (run a packaged action) or run: (run a shell command).

Think of a workflow as a recipe card. The event is “when guests arrive”. A job is a station in the kitchen, with its own counter. Steps are the instructions at that station, done in order.

The smallest useful workflow

This is .github/workflows/ci.yml for the notes CLI. It runs the tests on every pull request and on every push to main:

name: CI

on:
  push:
    branches: [main]
  pull_request:

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - run: npm test

I checked three things. The file parses as valid YAML. The command it runs, npm test, passes locally, with three tests passing on Node 26.13.1. And the action tags are real: actions/checkout v7.0.1 and actions/setup-node v7.1.0 were the latest releases when I looked on 2026-11-23, and both v7 tags exist. I could not run the workflow itself. It needs a repository on GitHub, and I have no account where I wrote this lesson. So I cannot show you the run page, and the behaviour described below comes from GitHub’s docs.

Walk through it.

  • name is the label shown in the Actions tab and on the pull request.
  • on lists the events. pull_request runs for pull requests. push with branches: [main] runs only for pushes to main. Without that filter, pushing to a branch with an open pull request starts two runs, one per event.
  • permissions: contents: read limits the token the workflow gets. Set this deliberately. The hardening lesson explains why.
  • jobs.test defines one job named test. The name matters, because it is what a required status check refers to.
  • runs-on: ubuntu-latest picks the runner. The next lesson covers choices.
  • timeout-minutes kills a hung job, so it cannot burn minutes for hours.
  • actions/checkout is the first step of almost every job. The runner starts empty, and this fetches your repository into it.
  • actions/setup-node installs the Node version you ask for, so the result does not depend on whatever is preinstalled.
  • run: npm test is a shell command. If it exits non-zero, the step fails, the job fails, and the check turns red.

Events, in more detail

The events you will use most, from GitHub’s “Events that trigger workflows” page (read on 2026-11-23):

  • push runs when commits or tags are pushed, including on branches that are not the default.
  • pull_request runs by default for the activity types opened, synchronize (new commits pushed) and reopened. A surprising detail: GITHUB_SHA is the merge commit and the ref is refs/pull/<number>/merge. Your tests run against your branch merged into the base, which is what you want, since that is what main will become. It also means workflows do not run on this event while the PR has a merge conflict. To test only your head commit, the docs point to github.event.pull_request.head.sha.
  • workflow_dispatch adds a manual Run workflow button. The docs say it only works if the workflow file exists on the default branch.
  • schedule runs on a cron schedule, only on the default branch, and in UTC unless you set a timezone. The docs warn that runs can be delayed under load, and that in public repositories scheduled workflows are disabled after 60 days without repository activity.
on:
  workflow_dispatch:
  schedule:
    - cron: "17 4 * * 1"   # Mondays at 04:17 UTC, off the top of the hour

Pull requests from forks are restricted. The docs say workflows do not run in forks by default, and that the token is read-only for pull requests from forks, with no secrets other than the token. That is deliberate. Without it, anyone could open a pull request that steals your secrets by editing the workflow.

Parallel jobs and ordering

Jobs run in parallel by default, each on its own fresh runner. Files created in one job do not exist in another. If one job must wait for another, say so with needs:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - run: npm test

  package:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - run: npm run build

package starts only when test succeeds. Both jobs need their own checkout, since they run on separate machines. The caching and artifacts lesson shows how to pass files between them.

Reading a failure

When a check fails, open the run from the pull request’s Details link, open the failed job, and expand the red step. The log of your command is there, and it is the same output you would see locally. If it fails in CI but passes on your machine, suspect differences: the Node version, a file that is gitignored locally and so absent from the clone, or an environment variable you have set on your laptop.

What the video covers

GitHub’s “How to use GitHub Actions | GitHub for Beginners” is about eight minutes and was published around March 2026 (YouTube shows “8 months ago”). The description says the hosts teach you what you need to get started with GitHub Actions. I could not read a transcript or chapters, so I cannot list the example it builds. It is from the official channel and recent, so the interface it shows is likely current. English is judged from the title and channel. A longer, 2026 walkthrough that builds a first workflow entirely in the browser is linked under deeper.

Where this fits

You can run a command on every pull request. The next lesson looks at what runs it and where reusable steps come from: runners and the marketplace.

Check yourself

  1. 01What is the difference between a job and a step?

    A job is a unit that runs on its own runner and can run in parallel with other jobs. A step is one action or shell command inside a job, and steps run in sequence on that job's runner.

  2. 02Why does a workflow need actions/checkout?

    The runner starts with an empty workspace. Checkout fetches your repository's files into it, so later steps have your code to test.

  3. 03Your workflow triggers on both push and pull_request. What happens when you push to a branch with an open pull request?

    It runs twice, once for each event. Limit push to main with a branches filter so branch pushes are covered only by the pull_request run.

  4. 04How do you make job B wait for job A?

    Add needs: A to job B. Without it, both jobs start at the same time.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark