Skip to main content
GitHub Actions beginner Lesson 1 of 5

GitHub Actions CI Basics

Get a working GitHub Actions pipeline: triggers, jobs/steps, caching, environment variables, and status checks.

GitHub Actions automates work in response to events.

Key concepts:

  • workflow: YAML file under .github/workflows/*.yml
  • job: a unit of execution (runs steps on one runner)
  • step: one command/action inside a job
  • runner: the machine environment that executes steps

Theory first: CI as automated quality gates

Think of GitHub Actions as an event-driven policy engine for your repository. A workflow is a codified quality gate: when a code event happens, predefined checks produce fast, repeatable feedback.

This theory helps you design cleaner pipelines: isolate responsibilities by job, keep steps deterministic, and fail early where risk is highest.

Learning outcomes

By the end you can:

  • create a CI workflow that runs on PR and main
  • understand jobs/steps and uses vs run
  • cache dependencies for faster builds
  • use secrets safely

1) Minimal workflow

Create .github/workflows/ci.yml:

name: CI

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

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Install deps
        run: npm ci

      - name: Run tests
        run: npm test

2) uses vs run

  • uses: owner/action@version runs an existing GitHub Action
  • run: executes shell commands

3) Caching dependencies (speed)

Example for Node (npm cache):

- name: Cache npm
  uses: actions/cache@v4
  with:
    path: ~/.npm
    key: npm-${{ hashFiles('package-lock.json') }}
    restore-keys: |
      npm-

4) Environment variables

You can set env at workflow/job/step scope:

env:
  NODE_ENV: test

5) Secrets

Use secrets for credentials:

env:
  API_TOKEN: ${{ secrets.API_TOKEN }}

Then in your script:

echo "Calling external API"

Do not echo secrets in logs.

6) What status checks mean

  • your workflow sets a result: success / failure
  • branch protection rules can require success before merge

Next steps

Next tutorials:

  • GitHub Actions secrets + artifacts
  • deploying with environments
  • adding Terraform/Ansible steps

Frequently Asked Questions

What is the difference between a workflow and a job?
A workflow is the overall YAML definition. A workflow contains one or more jobs; each job runs on a runner and contains steps.
Where do environment variables come from?
From job/workflow `env`, repository variables/secrets, and runner environment. Secrets are exposed to steps but not printed in logs.