GitHub Actions Basics — DevOps

A GitHub Actions workflow (an automated list of steps on GitHub's CI/CD service) is written in YAML in .github/workflows/. on sets the events (things that…

You write your first workflow file, push to main, and open the Actions tab. Empty. No error, no workflow running, nothing. Half an hour later you find it: the folder is .github/workflow/, one letter s short.

GitHub Actions is the CI/CD service built into GitHub, and it has strict rules about where files go and how they are written. You write a workflow (an automated list of steps) in a YAML file in the repo. Every time an event happens (something in the repo, a push for example), GitHub starts a fresh machine and runs the steps. Remember the catering kitchen from the What is CI/CD lesson? A workflow is like the procedure sheet pinned to that kitchen's wall. The sheet says when the work starts (every new order; on GitHub, an event), in which kitchen (a new cook with an empty kitchen; on GitHub, a new machine) and the steps, one by one.

Workflow files live in .github/workflows

GitHub only reads workflows from the .github/workflows/ folder at the repo root (the top folder of the repo). Every .yml or .yaml file in that folder is one workflow. This is notes-api's ci.yml, the same one the Lab uses:

# .github/workflows/ci.yml
name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

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

A little YAML first. Each line holds key: value. Indented lines (with spaces, never tabs) belong to the key above them. A line starting with - is one item of a list, and [main] is a list written on one line.

on: when the workflow runs

In the exercise, your function reads a simplified format made only for the exercise: on: push, pull_request, with the event names separated by commas. In a real workflow file, a list like that is written with square brackets: on: [push, pull_request].

steps: uses or run

Each step uses one of these two keys:

If you swap uses and run, each mistake fails in a different way. run: actions/checkout@v7 is run by bash as a command, then fails with actions/checkout@v7: No such file or directory (exit code 127). uses: npm test doesn't even get to run, because GitHub rejects the workflow file: Expected format {org}/{repo}[/path]@ref. Actual 'npm test'.

A runner starts as an empty machine

Every job gets a new, clean machine, and your repo's code isn't there yet. That's why actions/checkout is needed: it copies the repo into the runner's work folder, /home/runner/work/notes-api/notes-api. Without checkout, npm ci can't find package.json:

Run npm ci
npm error code ENOENT
npm error syscall open
npm error path /home/runner/work/notes-api/notes-api/package.json
npm error errno -2
npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/home/runner/work/notes-api/notes-api/package.json'
Error: Process completed with exit code 254.

Exit code 254 is not 0, so the step fails. A failed step stops the job: the steps after it are skipped.

Reading an Actions log

Open the Actions tab, pick the run (one time the workflow ran), then pick the test job. For the workflow above, after a push to main, its step list looks like this:

✓ Set up job
✓ Run actions/checkout@v7
✓ Run actions/setup-node@v7
✓ Run npm ci
✓ Run npm test
✓ Post Run actions/setup-node@v7
✓ Post Run actions/checkout@v7
✓ Complete job

Ordering jobs with needs, testing on several Node versions with a matrix, and branch protection (rules that protect main) are covered in the Testing in a CI/CD Pipeline lesson (Testing track). The next lesson, GitHub Actions Advanced, also covers matrices and needs, then continues with caching, environments and secrets.

⚠️ Why doesn't the workflow run, or go red right away?

TL;DR: A GitHub Actions workflow (an automated list of steps on GitHub's CI/CD service) is written in YAML in .github/workflows/. on sets the events (things that happen in the repo) that trigger it: push and pull_request, with branches: [main] to limit the branches. jobs holds jobs that each run on a new runner (a virtual machine from GitHub, runs-on: ubuntu-latest), and the steps inside run in order. uses: owner/repo@version runs an action (ready-made code written by someone else), for example actions/checkout@v7, which is needed first because the runner starts empty. run: runs a shell command. A failed step stops the job, and the reason is right above Error: Process completed with exit code ....

⚡ The place must be exact

Write:

.github/workflows/ci.yml
Guess first: you put the workflow file in .github/workflow/, with no s. What error shows up?

None at all. GitHub only reads .github/workflows/, so a folder one letter s short is ignored without any message.

Meaning: A GitHub Actions workflow file (an automated list of steps that GitHub runs) must be in .github/workflows/. Every .yml or .yaml file in that folder is one workflow.

⚡ on: when the workflow runs

Write:

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

Meaning: on lists the events (things that happen in the repo) that start the workflow. Here the workflow runs on every push to main, and every time a pull request (a request to merge a branch) into main is opened or gets a new commit. A push to another branch triggers nothing.

⚡ A runner starts as an empty machine

Write:

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

Meaning: The test job (a group of steps that run on one machine) runs on a runner, a new Ubuntu virtual machine from GitHub (runs-on: ubuntu-latest). Its steps run in order from the top. That machine doesn't have your repo's code yet, so actions/checkout (which copies the repo's code onto that machine) must come first. Without checkout, npm ci can't find package.json.

⚡ uses or run

Write:

- uses: actions/checkout@v7
- run: npm test

Meaning: uses runs an action (ready-made code written by someone else), written owner/repo@version. run runs a shell command on the runner. A failed step stops the job, and the reason is right above Error: Process completed with exit code ....

What you will learn