GitHub Actions CI/CD
Summary
GitHub Actions is GitHub's native CI/CD platform for automating software workflows. Define workflows in YAML files to build, test, and deploy code directly from your repository with event-driven automation.
When to Use
- Automate testing on every pull request
- Build and deploy applications on merge to main
- Schedule regular tasks (nightly builds, backups)
- Publish packages to registries (npm, PyPI, Docker Hub)
- Run security scans and code quality checks
- Automate release processes and changelog generation
Quick Start
Basic Test Workflow
Create .github/workflows/test.yml:
Complete GitHub Actions Guide
Core Concepts
Workflows
YAML files in .github/workflows/ that define automation pipelines.
Structure:
- Name: Workflow identifier
- Triggers: Events that start the workflow
- Jobs: One or more jobs to execute
- Steps: Commands/actions within each job
Jobs
Independent execution units that run in parallel by default.
Steps
Sequential commands or actions within a job.
Actions
Reusable units of code (from marketplace or custom).
Workflow Syntax
Triggers (on)
Push Events
Pull Request Events
Schedule (Cron)
Manual Trigger
Multiple Triggers
Environment Variables
Workflow-level
Job-level
Step-level
Secrets
Store sensitive data in repository settings.
Best Practices:
- Never commit secrets to code
- Use GitHub encrypted secrets
- Limit secret access to specific environments
- Rotate secrets regularly
Contexts
github Context
Repository and workflow information.
env Context
Access environment variables.
secrets Context
Access repository secrets.
matrix Context
Access matrix values.
needs Context
Access outputs from dependent jobs.
Runners
GitHub-hosted Runners
Available Runners:
ubuntu-latest,ubuntu-22.04,ubuntu-20.04macos-latest,macos-14,macos-13windows-latest,windows-2022,windows-2019
Self-hosted Runners
Setup:
- Go to Settings → Actions → Runners
- Click "New self-hosted runner"
- Follow platform-specific instructions
- Add custom labels for targeting
Matrix Strategies
Basic Matrix
Test across multiple versions.
Include/Exclude
Fail-fast
Max Parallel
Common Actions
Checkout Code
Setup Node.js
Setup Python
Setup Java
Setup Go
Cache Dependencies
Upload Artifacts
Download Artifacts
Conditional Execution
if Conditions
Job Conditions
Framework-Specific Workflows
Node.js/TypeScript
Python
Docker
Next.js with Vercel
Deployment Patterns
Vercel Deployment
Netlify Deployment
AWS S3 + CloudFront
Docker Registry Push
Testing Workflows
Unit Tests with Coverage
Integration Tests
E2E Tests with Playwright
Release Automation
Semantic Release
Create Release with Changelog
Publish npm Package
Security Scanning
CodeQL Analysis
Dependency Scanning
Trivy Container Scan
Composite Actions
Create reusable actions in .github/actions/.
Simple Composite Action
.github/actions/setup-project/action.yml:
Usage:
Reusable Workflows
.github/workflows/reusable-deploy.yml:
Usage:
Performance Optimization
Dependency Caching
Docker Layer Caching
Parallelization
Conditional Job Execution
Debugging Workflows
Enable Debug Logging
Set repository secrets:
ACTIONS_RUNNER_DEBUG:trueACTIONS_STEP_DEBUG:true
Debug Step
Interactive Debugging with tmate
Best Practices
Security
- Use secrets for sensitive data
- Pin action versions to SHA:
uses: actions/checkout@8e5e7e5a... - Minimize token permissions
- Use environment protection rules
- Enable branch protection with required checks
Performance
- Cache dependencies aggressively
- Use matrix strategies for parallel testing
- Minimize checkout depth when possible
- Use artifacts for job-to-job data transfer
- Optimize Docker builds with multi-stage builds
Maintainability
- Use reusable workflows for common patterns
- Create composite actions for repeated steps
- Document workflow purpose and triggers
- Use meaningful job and step names
- Keep workflows focused (single responsibility)
Reliability
- Set appropriate timeouts
- Use
continue-on-errorstrategically - Implement retry logic for flaky tests
- Monitor workflow run times
- Clean up old artifacts and caches
Common Patterns
PR Comment on Failure
Auto-merge Dependabot PRs
Notify on Deploy
Troubleshooting
Common Issues
Workflow not triggering:
- Check branch filters match actual branch names
- Verify workflow file is in
.github/workflows/ - Ensure YAML syntax is valid
Job skipped:
- Check
ifconditions - Verify
needsdependencies succeeded - Check branch protection rules
Timeout:
- Default timeout is 360 minutes
- Set explicit timeout:
timeout-minutes: 30 - Optimize long-running steps
Permission denied:
- Update workflow permissions:
Secrets not available:
- Verify secret names match exactly (case-sensitive)
- Check secret scope (repo, organization, environment)
- Ensure workflow has access to environment secrets
Local Workflow Patterns (Your Repos)
Python + uv CI (mcp-vector-search)
- Install uv:
astral-sh/setup-uv@v3anduv python install 3.11. - Use
uv sync --devand runuv run ruff,uv run mypy,uv run pytest. - Use OS + Python version matrix and upload coverage to Codecov on linux.
Node + pnpm CI (ai-code-review)
- Use
pnpm/action-setup@v4andactions/setup-node@v4with pnpm cache. - Install with
pnpm install --frozen-lockfile, thenpnpm run lint,pnpm run build:types,pnpm test.
Release on Tags
- Trigger on
pushtagsv*. - Build, create GitHub Release notes, and publish to npm or PyPI.
- Use
pypa/gh-action-pypi-publish@release/v1orNODE_AUTH_TOKENfor npm publish.
Homebrew Update Pipeline
- Trigger on
workflow_runafter CI success. - Run
scripts/update_homebrew_formula.pywithHOMEBREW_TAP_TOKEN. - On failure, open an issue with manual update steps.


