Introduction
GitHub Actions is one of the most popular CI/CD tools today. This guide covers everything from basics to advanced techniques.
Basic Workflow Structure
name : CI/CD Pipeline
on : push : branches : [ main , develop ] pull_request : branches : [ main ]
jobs : test : runs-on : ubuntu-latest steps : - uses : actions/checkout@v4 - uses : actions/setup-node@v4 with : node-version : ' 18' - run : npm ci - run : npm test
Enter fullscreen mode
Exit fullscreen mode
Matrix Builds
Test across multiple environments:
strategy : matrix : node-version : [ 16 , 18 , 20 ] os : [ ubuntu-latest , windows-latest ]
Enter fullscreen mode
Exit fullscreen mode
Caching
Speed up builds with caching:
- uses : actions/setup-node@v4 with : node-version : ' 18' cache : ' npm'
- uses : actions/cache@v3 with : path : ~/.cache/pip key : ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
Enter fullscreen mode
Exit fullscreen mode
Reusable Workflows
Create reusable workflow:
#…