A hands-on tutorial project for learning Continuous Integration and Continuous Deployment by implementing a GitHub Actions workflow from scratch.
This repository is a teaching project where students learn CI/CD by:
- Writing their own GitHub Actions workflow file
- Setting up automated testing and code quality checks
- Creating and managing build artifacts
- Implementing automatic deployment to GitHub Pages
- Node.js 20 or higher
- npm (comes with Node.js)
- Git
- GitHub account with access to create repositories and enable GitHub Actions
# Fork the repository on GitHub first, then:
git clone https://github.com/YOUR-USERNAME/ci-cd-tutorial.git
cd ci-cd-tutorialnpm install# Run tests
npm test
# Run linter
npm run lint
# Check code formatting
npm run format:check
# Build the project
npm run buildCreate a .github/workflows/ci-cd.yml file that:
- Triggers on push to
mainand pull requests - Runs on
ubuntu-latest - Installs dependencies with
npm ci - Runs the linter:
npm run lint - Checks formatting:
npm run format:check - Runs tests:
npm test - Builds the project:
npm run build - Generates a simple log file (e.g., with timestamp)
- Uploads two artifacts:
- Build logs
- The demo site (from
public/directory)
- Only runs after CI succeeds
- Only deploys on push to
main(not on PRs) - Deploys the demo site to GitHub Pages
- Go to your repository Settings
- Navigate to Pages (in the left sidebar)
- Under Source, select GitHub Actions
- Push your workflow file to trigger the first deployment
- Create a new branch:
git checkout -b test-ci - Make a small change (e.g., update README)
- Push and create a Pull Request
- Verify CI runs successfully
- Merge the PR and verify deployment happens
- Go to Settings β Branches
- Add a rule for the
mainbranch - Enable Require status checks to pass before merging
- Select the ci check
- Try creating a PR that fails tests to see protection in action
ci-cd-tutorial/
βββ .github/
β βββ workflows/
β βββ ci-cd.yml # Your workflow file to create
βββ src/
β βββ sum.js # Simple sum function to test
βββ test/
β βββ sum.test.js # Tests for sum function
βββ demo/
β βββ index.html # Interactive demo page for deployment
βββ eslint.config.js # ESLint configuration
βββ package.json # Project dependencies and scripts
By completing this tutorial, you'll learn:
- GitHub Actions Syntax: YAML workflow configuration, jobs, steps, and actions
- Automated Testing: Run tests on every code change
- Code Quality Gates: Implement linting and formatting checks
- Build Artifacts: Create and store build outputs and logs
- Deployment Automation: Auto-deploy successful builds to production
- Branch Protection: Enforce CI checks before merging
- Environment Separation: Different behaviors for branches (CI everywhere, CD only on main)
- Job Dependencies: Chain CI and CD jobs together
- Workflow Triggers: Events that start your pipeline (push, pull_request)
- Jobs: Units of work that run in parallel or sequence
- Steps: Individual commands within a job
- Artifacts: Files preserved after workflow completion
- Conditional Execution: Run steps only when certain conditions are met
Once implemented:
- Push to
main: Runs CI + CD (deploys to GitHub Pages) - Pull Requests to
main: Runs CI only (no deployment) - Artifacts: Available for download after each run
After your workflow runs:
- Go to Actions tab β Select a workflow run
- Scroll to Artifacts section at the bottom
- Download
build-logsordemo-siteto inspect outputs
# Run all tests
npm test
# Tests include:
# - Basic addition
# - Type validation
# - Error handling| Command | Description |
|---|---|
npm test |
Run tests using Node.js test runner |
npm run lint |
Check code quality with ESLint |
npm run lint:fix |
Auto-fix linting issues |
npm run format |
Format code with Prettier |
npm run format:check |
Check if code is formatted |
npm run build |
Build the project to dist/ |
Once deployed, the demo site shows:
- Interactive calculator using the sum function
- Beautiful UI demonstrating the deployed application
- Real-world example of CD in action
Click for GitHub Actions Workflow Hints
name: Your Workflow Name
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
job-name:
runs-on: ubuntu-latest
steps:
- name: Step description
run: command to executeactions/checkout@v6- Check out your codeactions/setup-node@v6- Set up Node.js environmentactions/upload-artifact@v6- Upload build artifactsactions/download-artifact@v7- Download artifacts from previous jobactions/upload-pages-artifact@v3- Upload to Pagesactions/deploy-pages@v4- Deploy to Pages
mkdir -p logs
echo "Build completed at $(date)" > logs/build.logif: github.event_name == 'push' && github.ref == 'refs/heads/main'This repository includes a reference implementation at .github/workflows/ci-cd.yml for testing purposes. Students should create their own workflow from scratch. Consider:
- Having students work in pairs to discuss workflow design
- Asking them to intentionally break tests to see CI failures
- Discussing artifact retention policies and costs
- Exploring more advanced topics like matrix builds, caching, or secrets management
This project is open source and available for educational purposes.