GitHub Actions: Capstone — A Full CI/CD Pipeline
A full CI/CD pipeline is one workflow that lints, tests, builds and deploys an app. This capstone joins every piece of the course into a single pipeline.
The test job is a reusable workflow
The capstone calls the shared test workflow from the reuse lesson.
jobs:
test:
uses: ./.github/workflows/reusable-test.ymlThe matrix
The build runs on Node 20, 22 and 24, on Ubuntu and Windows.
strategy:
matrix:
node: [20, 22, 24]
os: [ubuntu-latest, windows-latest]The status badge
The badge is a small image in the README that shows the latest run.
[](https://github.com/sanjay51/a1learner-github-actions-demo/actions/workflows/capstone.yml)The failure notice
This step runs only when a job fails. The demo has no Slack, so the notice is a log line.
- if: failure()
run: echo "Capstone pipeline failed - check the run log"Example
name: Capstone CI/CD
on:
pull_request:
push:
branches: [main]
schedule:
- cron: '0 3 * * *'
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
jobs:
test:
uses: ./.github/workflows/reusable-test.yml
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '24'
- run: npm run lint
build:
needs: [test, lint]
strategy:
matrix:
node: [20, 22, 24]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm run build
- uses: actions/upload-artifact@v7
with:
name: dist-${{ matrix.node }}-${{ matrix.os }}
path: dist
deploy:
needs: build
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
environment: production
concurrency:
group: deploy-production
cancel-in-progress: false
steps:
- uses: actions/checkout@v7
- uses: actions/download-artifact@v8
with:
name: dist-24-ubuntu-latest
path: dist
- uses: actions/configure-pages@v6
- uses: actions/deploy-pages@v5
notify:
needs: [test, lint, build, deploy]
if: failure()
runs-on: ubuntu-latest
steps:
- run: echo "Capstone pipeline failed - check the run log"Key points
- Capstone: one workflow that lints, tests, builds and deploys the demo app.
- Lint runs first, since it catches mistakes before tests.
- A matrix is a set of combinations, like Node versions times operating systems.
- The test job is a reusable workflow, called from the capstone.
- Caching saves the npm files between runs.
- Artifacts carry the built site from the build job to the deploy job.
- The deploy job waits for a human approval in the production environment.
- A status badge in the README shows the latest run at a glance.
- A nightly scheduled run catches breakage even when nobody pushes.
In this example, the workflow runs on pull requests, on pushes to main, on a nightly schedule at 3am, and by hand. The test job calls the reusable test workflow. The lint job checks the code. The build job needs both to pass. It runs a matrix of Node versions and operating systems. It caches npm files. It builds the site and uploads the dist folder as an artifact. The deploy job runs only on a push to main. It waits for approval in the production environment. It downloads the artifact and deploys it to Pages. The notify job runs only when a job fails. It prints a notice in the log, since the demo has no Slack.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What does the capstone deploy job wait for before it publishes the site?