Skip to Content
Mengty Learns
CI/CD

Pipeline Anatomy: Triggers, Jobs, Cache, Artifacts

How a CI/CD pipeline turns a git push into parallel jobs, cached dependencies, build artifacts, and a deployment gate.

explanationbeginnerTested with pnpm 11.6.0, node 22.22.3Updated Nov 26, 2026

TL;DR

A CI/CD pipeline is an event-driven DAG: a trigger (push, pull_request) spawns jobs on clean runners, caches restore unchanged dependencies, artifacts carry build outputs across stages, and a deploy gate promotes only verified builds.

Intent

TL;DR

Understand the five building blocks of every modern CI/CD pipeline—triggers, parallel jobs, caching, artifacts, and deploy gates—using this repository's own .github/workflows/ci.yml as a concrete reference.

Problem

Treating CI as one opaque bash script makes builds slow and brittle. Installing packages from scratch on every commit wastes minutes, running lint/test/build sequentially delays feedback, and deploying without a gate lets broken commits reach users.

Caches speed up future runs; artifacts pass outputs (such as out/ or test reports) between jobs in one run.

Solution

Every healthy pipeline separates five responsibilities:

  1. Trigger (on:): Declarative rules (push to main, pull_request) decide when the workflow starts.
  2. Parallel Jobs (jobs:): Independent checks (lint, typecheck, unit tests, build) run concurrently on separate runners unless linked by needs:.
  3. Cache Restore / Save: Package stores (like pnpm store keyed by pnpm-lock.yaml) are restored before pnpm install --frozen-lockfile and saved afterward.
  4. Artifacts: Build outputs (out/), Playwright traces, or coverage reports are uploaded so downstream jobs or reviewers can inspect or deploy them.
  5. Deploy Gate: Branch protection and environment rules require all check jobs to succeed before the deploy step runs.

Real-world analogy

▶ Flow: watch it work

CI/CD Pipeline: Trigger → Cache → Jobs → Artifacts → Gate

Overview of CI/CD Pipeline: Trigger → Cache → Jobs → Artifacts → Gate. 5 steps.
Overview5 steps in this flow

Press Start or tap any step dot to trace the path.

▸All steps (5)

Code

Here is the real .github/workflows/ci.yml from this repository:

name: CI

on:
  push:
    branches: [main, mengtylearns-mvp]
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: pnpm/action-setup@v4
        with:
          version: 11.6.0
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: pnpm
      - run: pnpm install --frozen-lockfile
      - run: pnpm lint
      - run: pnpm typecheck
      - run: pnpm build

When to use / when to avoid

When to use
  • You want fast feedback by running independent checks (lint, unit tests, build) in parallel.
  • You need reproducible builds using --frozen-lockfile and cached dependency stores.
When to avoid
  • Splitting a 20-second workflow into 6 tiny jobs where runner boot + checkout overhead exceeds the work saved.
  • Storing secrets inside caches or artifacts—both are accessible to workflow runs and should never hold credentials.

How to implement

Define narrow triggers

Trigger on pull_request and pushes to main so every merge candidate is checked.

Cache dependencies by lockfile hash

Use actions/setup-node with cache: pnpm and pnpm install --frozen-lockfile.

Gate deployment on check jobs

Require lint, typecheck, test, and build to pass before deploying artifacts.

Pros / Cons

Pros
  • Parallel jobs cut wall-clock feedback time for developers.
  • Immutable artifacts guarantee you deploy the exact bits that passed tests.
Cons
  • Cache misses or oversized artifacts can still slow runners down if not scoped carefully.
  • Runner startup overhead means very small scripts can be faster in one combined job.

Relations

Check yourself

Check Yourself

1. Why does .github/workflows/ci.yml pass --frozen-lockfile to pnpm install?

2. When should you use a GitHub Actions artifact instead of a cache?

Sources