CI/CD, GitHub Actions & Deployment
Lesson opener
In one line: Continuous Integration (CI) - test every push automatically.
Why it matters: This shows up at work when you need to continuous Integration (CI) - test every push automatically.
Before this lesson: Pull requests & collaboration
Before you start
| Resource | Link |
|---|---|
| Previous | Pull requests & collaboration |
| Next | Cheat sheet & capstone |
| Time | ~60 minutes |
What you will learn
- Continuous Integration (CI) — test every push automatically
- GitHub Actions workflow files
- Deploy static sites with GitHub Pages
- Secrets management — never hardcode keys in YAML
- 2026 extras: Dependabot, branch environments
Section 1 — CI in plain English
Before CI: "It worked on my machine" → production breaks.
With CI: Every push runs tests in a clean cloud VM. Red X = don't merge.
Section 2 — First GitHub Actions workflow
Create .github/workflows/ci.yml:
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
run: pytestPush → Actions tab shows run status on the PR.
Section 3 — GitHub Pages — free static hosting
For portfolios, docs sites, Vite/React builds:
# .github/workflows/pages.yml
name: Deploy Pages
on:
push:
branches: [main]
permissions:
contents: read
pages: write
id-token: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/configure-pages@v5
- uses: actions/upload-pages-artifact@v3
with:
path: website
- uses: actions/deploy-pages@v4Repo Settings → Pages → source: GitHub Actions.
Site live at: https://YOUR_USERNAME.github.io/REPO_NAME/
Same pattern deploys this learning site.
Section 4 — Secrets (critical)
Never commit:
# WRONG
env:
API_KEY: sk-live-abc123Use Settings → Secrets and variables → Actions:
env:
API_KEY: ${{ secrets.API_KEY }}Rotate keys if leaked — GitHub secret scanning alerts on public repos.
Section 5 — Environments & approvals
Production deploys use environments with required reviewers:
jobs:
deploy-prod:
environment: production
runs-on: ubuntu-latest
steps:
- run: echo "Deploying..."Section 6 — Dependabot (2026 maintenance)
Enable Settings → Security → Dependabot — auto-PRs when dependencies have CVEs.
Review and merge dependency PRs like feature PRs.
Section 7 — Mobile & Expo EAS
From android8:
- name: EAS Build
run: eas build --platform android --non-interactive
env:
EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}CI builds store-ready binaries from the same commit you tested.
Practice
- Add a CI workflow that runs
python -c "print('ok')"on push - Break it intentionally — see red X on PR
- Fix and merge
Checklist
- [ ] CI workflow runs on push/PR
- [ ] Secrets stored in GitHub, not in code
- [ ] Know GitHub Pages exists for static deploys
Teacher walkthrough: commit → check → deploy
All figures illustrative.
Step 1 — Define the pipeline. On push/PR: install, test, lint (as course shows).
Step 2 — Fail closed. Broken main should not deploy.
Step 3 — Deploy only known SHAs (tag or main after green checks).
Step 4 — Secrets in the host, never in YAML committed plaintext.
Failure example: deploy from a dirty laptop folder
Symptom: Production differs from GitHub; cannot roll back.
Diagnosis: Manual copy of unsorted files; no commit pin.
Correction: CI deploys from commit; artefact = git SHA; rollback = redeploy previous SHA.
Validation: Production version matches SHA.
Guided practice
Where should API_KEY live in a GitHub Actions deploy?
Complete solution: In encrypted/repo secrets (or OIDC to a vault) — referenced by the workflow, not committed.
Independent practice
Acceptance criteria:
- Describe your pipeline stages (test → deploy).
- One secret handled via host secrets.
- Rollback strategy named (redeploy previous commit).
- Link to course Actions example or your workflow file.
Common mistakes
- Skipping tests on main.
- Deploying without recording SHA.
- Committing cloud keys in workflow files.
What's next
Cheat sheet & capstone — command reference, tips, and portfolio project.