What is CI/CD?
Continuous Integration and Continuous Deployment (CI/CD) is a practice that automates the building, testing, and deployment of applications. GitHub Actions makes this accessible to every developer.
Your First Workflow
Create a file at .github/workflows/ci.yml:
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
- run: npm install
- run: npm testMulti-stage Deployments
A production pipeline typically includes: build, test, Docker image creation, and deployment. You can chain jobs using the needs keyword to create dependency chains.
Secrets Management
Store sensitive values like API keys and deployment credentials in GitHub Secrets under Settings → Secrets and variables → Actions. Reference them in workflows as ${{ secrets.MY_SECRET }}.
Caching Dependencies
Speed up your pipeline by caching dependencies:
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles("**/package-lock.json") }}Conclusion
GitHub Actions is a powerful, flexible CI/CD solution. Start with simple workflows and gradually add complexity as your project grows.