DevOps and automation · Beginner to advanced

Learn GitHub CI/CD step by step

Learn how GitHub Actions checks every code change, runs tests and publishes an approved website, with simple examples and a safe release flow. Every module explains the idea in plain language, walks through a code example and gives you a small task to try yourself.

Version snapshot: GitHub Actions · checked 21 October 2026. GitHub Actions changes over time. The workflow example follows current official syntax and uses GitHub Pages as a concrete static-site deployment; check the official references before updating action versions.

Before you begin

A GitHub account and a repository are enough to follow along. The working sample uses a small Node.js static site; other languages use the same flow with their own setup and test commands.

What you’ll be able to do

Build a pull-request check, deploy passing static files to GitHub Pages, and explain how to protect production credentials and releases.

Work through the modules in order if you’re new to GitHub CI/CD. If you already know the basics, use the contents list to jump to a topic. Try each example by changing one value, running it again and explaining the result in your own words.

GitHub CI/CD terms in simple language

CI
Automatically running checks when code changes, so mistakes are found before changes are merged.
CD
Automatically preparing a release or publishing an approved change for people to use.
Workflow
A YAML recipe in .github/workflows that tells GitHub what work to run and when.
Event
Something that starts a workflow, such as opening a pull request or pushing to main.
Runner
The temporary computer that GitHub gives a job to run its steps.
Action
A reusable step someone has packaged so a workflow can do a common task.
Artifact
A file made during a workflow, such as the finished site files ready to publish.
Secret
A private value such as a deploy password, stored in GitHub settings rather than in code.
In this guide · 10 modules
  1. Key terms in simple language
  2. CI/CD in one simple flow
  3. Understand workflows, events, jobs and runners
  4. Prepare a small site and repeatable commands
  5. Create your first CI workflow
  6. Use pull requests as the safety gate
  7. Add CD and publish the site with GitHub Pages
  8. Keep passwords and deployment secrets safe
  9. Read a failed run and repair the pipeline
  10. Harden production releases
  11. Adapt the pipeline to PHP, Python or another app
  12. Final project
  13. Official references
MODULE 01 / 10 · CONCEPT EXPLAINED

CI/CD in one simple flow

Imagine you prepare an assignment before submitting it. You check spelling and make sure it opens: that is Continuous Integration (CI), automatic checks that run when code changes. Continuous Delivery means every passing change is ready to publish, but a person can approve the final release. Continuous Deployment goes one step further and publishes each passing change automatically. The everyday flow is: create a branch → change code → open a pull request → GitHub runs checks → review and merge → deploy the approved version. A failed check stops the flow before broken code is published.

Follow this example
feature branch → pull request → CI checks
                         ↓ checks pass + review
main branch → build → deploy to website

CI = automatically check code changes
CD = automatically prepare or publish approved changes
Try it yourself: Draw this flow for a change to a personal website. Mark where tests run, where a person reviews the change and when website visitors see it.
MODULE 02 / 10 · CONCEPT EXPLAINED

Understand workflows, events, jobs and runners

A workflow is an automation recipe stored in YAML under .github/workflows. An event starts the recipe; common events are a pull request, a push to main or a manual run. A job is a group of work that runs on a runner, which is a temporary computer provided by GitHub. A job has steps: a step can run a command or use a reusable action. A build artifact is a file produced by the workflow, such as the finished website folder.

Follow this example
repository/
├── .github/
│   └── workflows/
│       └── site.yml
├── package.json
├── package-lock.json
└── public/
Try it yourself: Create the .github/workflows folder in a practice repository and add an empty site.yml file.
MODULE 03 / 10 · CONCEPT EXPLAINED

Prepare a small site and repeatable commands

A workflow can only repeat tasks your project already knows how to do. This example expects package.json to have test and build scripts, and a package-lock.json that matches it. npm ci installs the saved package versions, npm test runs checks, and npm run build creates deployable files in dist. Run these commands on your own computer first. A PHP or Python app keeps the same workflow shape but replaces Node setup and npm commands with its own install and test commands.

Follow this example
{
  "scripts": {
    "test": "node --test",
    "build": "mkdir -p dist && cp -r public/. dist/"
  }
}
Try it yourself: Run npm ci, npm test and npm run build locally. Confirm that dist contains your website before adding automation.
MODULE 04 / 10 · CONCEPT EXPLAINED

Create your first CI workflow

Create .github/workflows/site.yml. This workflow runs for pull requests into main and for pushes to main. The build job checks out the files, installs Node.js 24 and locked dependencies, runs tests, builds the site and packages dist as a Pages artifact. GitHub displays every step and its output in the Actions tab. The workflow has read-only access to repository content; keep permissions this small unless a later job needs more.

Follow this example
name: Site CI and deployment

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

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Get repository files
        uses: actions/checkout@v7
      - name: Install Node.js
        uses: actions/setup-node@v7
        with:
          node-version: 24
      - name: Install exact dependencies
        run: npm ci
      - name: Run tests
        run: npm test
      - name: Build the website
        run: npm run build
      - name: Package website for Pages
        uses: actions/upload-pages-artifact@v4
        with:
          path: dist
Try it yourself: Commit the workflow on a branch and open a pull request. Open the Actions tab, find its run and fix any failed step before merging.
MODULE 05 / 10 · CONCEPT EXPLAINED

Use pull requests as the safety gate

A pull request is a review area for a proposed change before it becomes part of main. The workflow checks the proposed code, so reviewers can see whether tests and the build pass. In repository Settings → Branches, protect main by requiring a pull request and successful status checks before merging. This catches problems before they reach the production branch. Begin with one required check; add more rules when your team has a clear reason.

Follow this example
1. Create a feature branch
2. Edit files and push that branch
3. Open a pull request into main
4. Wait for the Actions check
5. Review the changes and fix failed checks
6. Merge only after required checks pass
Try it yourself: Open a pull request that changes one line in your practice site. Confirm that the CI run is attached to the pull request and passes.
MODULE 06 / 10 · CONCEPT EXPLAINED

Add CD and publish the site with GitHub Pages

The CI job made a tested website artifact; a separate deploy job now publishes it. It waits for build to finish and only runs after a push to main, so an unmerged pull request cannot publish the site. In the repository, open Settings → Pages and choose GitHub Actions as the publishing source. After a passing change is merged, open Actions to see deployment status and the published page URL. GitHub Pages serves static HTML, CSS and JavaScript files; it does not run a PHP server or database.

Follow this example
  deploy:
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Publish the built site
        id: deployment
        uses: actions/deploy-pages@v4
Try it yourself: Enable GitHub Actions as the Pages source, merge a passing change to main and follow the deploy job to its page URL.
MODULE 07 / 10 · CONCEPT EXPLAINED

Keep passwords and deployment secrets safe

A secret is private data such as a hosting token or SSH key. Never paste it into source code or a workflow file because those files and logs can expose it. Add secrets in Settings → Secrets and variables → Actions, then read them with the secrets context only in the deployment step that needs them. Put production credentials in a production environment and add branch rules or required approval if the release needs a person to authorize it. Workflows from forked pull requests do not receive normal repository secrets. The GitHub Pages example needs no custom password, so it does not use a secret.

Follow this example
- name: Deploy to your hosting provider
  env:
    HOSTING_TOKEN: ${{ secrets.HOSTING_TOKEN }}
  run: ./scripts/deploy.sh
Try it yourself: List what credentials your chosen host needs. For each credential, note the one trusted deploy step that uses it and who should be allowed to approve production releases.
MODULE 08 / 10 · CONCEPT EXPLAINED

Read a failed run and repair the pipeline

A red workflow does not always mean GitHub is broken. Open the run, choose the failed job and read its step log from the first error upward. npm ci often fails if the lockfile is missing or does not match package.json. A failed test means the test command ran but found behavior it did not expect. A missing dist folder means the build output and artifact path do not match. A skipped deploy on a pull request is expected: publishing is limited to main. Make one fix, push again and let the same workflow check it.

Follow this example
npm ci fails       → update and commit package-lock.json
npm test fails     → inspect the failing assertion
Artifact upload fails → check that build creates dist/
Deploy is skipped  → expected for a pull request
Try it yourself: Temporarily use a command that fails, find its message in the Actions run, then restore the correct command and push the repair.
MODULE 09 / 10 · CONCEPT EXPLAINED

Harden production releases

Give each job only the permissions it needs. Run tests for pull requests, but expose production credentials only to a protected deployment environment on a trusted branch. A concurrency group can prevent two production deploys from racing. Save reports or build files as artifacts when you need to inspect or reuse them. For stronger supply-chain security, pin third-party actions to reviewed full commit SHAs and update them deliberately; major-version tags are easier to read, but the tag can move. Keep dependencies and action versions maintained.

Follow this example
concurrency:
  group: pages-production
  cancel-in-progress: true

# Production release pattern:
# - test pull requests without production secrets
# - deploy only a protected main branch
# - require approval for a production environment
Try it yourself: Review your workflow permissions and remove any permission that no step uses. Identify which job is allowed to publish production.
MODULE 10 / 10 · CONCEPT EXPLAINED

Adapt the pipeline to PHP, Python or another app

The repeatable pattern is install → lint → test → build → deploy. A PHP application can run syntax checks and its test suite before a separate SSH or hosting-provider deploy job. A Python application can install pinned requirements and run pytest. GitHub Pages is only for static files; a PHP app needs a host that runs PHP and any database it uses. Keep the pull-request checks and replace only the language setup and destination-specific deploy steps. Use the current deployment guide from your chosen host, and never copy a Pages step to a backend server expecting it to run PHP.

Follow this example
Every project: install → lint → test → build → deploy
Static site: publish HTML, CSS and JavaScript files
PHP or database app: choose a PHP-capable host

Keep pull-request checks when the deploy destination changes.
Try it yourself: Write a release plan for your own project: install command, tests, build output folder, hosting target and the first step you would take to roll back a bad release.
PUT THE MODULES TOGETHER

Your final project

Create a small static website, require GitHub Actions checks on every pull request and automatically publish passing changes from main to GitHub Pages. Write down what the project should do, build it in small steps, and include a README that explains how to run it.

Find a guided course →

Official documentation and further reading

Use primary documentation for current language rules and version changes. The examples in this guide are learning starting points; verify details for the exact runtime and browser support your project needs.

Frequently asked questions

Does a green CI run guarantee a bug-free site?

No. It means the checks you configured passed. Include meaningful tests, reviews and production safeguards for the risks in your project.

Can GitHub Pages run PHP or a database?

No. Pages publishes static files. A PHP application needs hosting that runs PHP and its database; the CI checks can stay and the deploy job must change.

Should I put a deploy password in my YAML file?

No. Store credentials as GitHub Actions secrets or protected environment secrets, and expose them only to the trusted deployment job that needs them.