Beginner friendly + Real-life analogy + Production mindset
- What is GitHub Actions
- Easy Explanation
- Why Use It
- CI/CD Concept
- How GitHub Actions Works
- Workflow Fundamentals
- Workflow Deep Dive
- Reusable Workflow
- Composite Action
- Docker / JS Actions
- Matrix Strategy
- Cache
- Artifacts
- Secrets & Security
- Self Hosted Runner
- Environment & Approval
- Real Project Examples
- Best Practices
- Debugging Tips
GitHub Actions is an automation platform inside GitHub.
It automates:
- testing
- building
- deployment
- notifications
- cron jobs
- security scan
- release automation
Simple:
You push code → GitHub automatically works
Imagine restaurant automation:
Manual:
Order আসে → Chef রান্না → Packaging → Delivery
Automated:
Order আসে → Robot রান্না → Auto QC → Auto Delivery
Software world:
Code push → Test → Build → Deploy
This robot = GitHub Actions
Benefits:
- automatic
- fast
- repeatable
- less human error
- team consistency
- production ready
- built into GitHub
Meaning:
Every push / PR:
- install deps
- lint
- test
- build
Example:
git push↓
Auto:
npm install
npm run lint
npm test
npm run buildReady for deployment automatically.
Human approves deploy.
Fully automatic production deployment.
Push → Live
Visual:
Developer
↓
Push
↓
CI
↓
Build
↓
Deploy
↓
Production
Flow:
Developer action
↓
Event trigger
↓
Workflow starts
↓
Runner machine created
↓
Jobs run
↓
Steps run
↓
Logs generated
↓
Success / Fail
project/
├── src/
├── package.json
└── .github/
└── workflows/
├── ci.yml
├── deploy.yml
└── release.ymlImportant:
.github/workflows/GitHub scans this folder.
| Term | Meaning |
|---|---|
| Workflow | automation file |
| Event | trigger |
| Job | group of tasks |
| Step | single task |
| Runner | machine |
| Action | reusable block |
| Secret | encrypted variable |
| Artifact | generated file |
Basic:
name:
on:
jobs:Example:
name: Node CI
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: echo "Hello"Workflow name.
name: Backend CI PipelineReadable name use.
Good:
name: API Test PipelineBad:
name: workflow1Trigger.
Example:
on: pushon: pushon: pull_requestManual run.
on:
workflow_dispatch:Cron.
on:
schedule:
- cron: "0 0 * * *"Daily midnight.
on:
push:
branches:
- main
- developon:
push:
tags:
- v*on:
push:
paths:
- src/**Workflow contains jobs.
Example:
jobs:
test:
build:
deploy:Visual:
Workflow
├── test
├── build
└── deploy
Machine that executes workflow.
runs-on: ubuntu-latestOptions:
ubuntu-latest
windows-latest
macos-latestSmall tasks.
steps:Example:
steps:
- run: npm install
- run: npm test
- run: npm run buildExecute shell command.
- run: pwd- run: ls -la- run: npm testMulti-line:
- run: |
npm install
npm run lint
npm testReusable action.
Example:
Checkout code:
- uses: actions/checkout@v4Setup Node:
- uses: actions/setup-node@v4Pass inputs.
- uses: actions/setup-node@v4
with:
node-version: 20Environment variable.
Workflow:
env:
NODE_ENV: productionJob:
jobs:
build:
env:
PORT: 5000Step:
- env:
NAME: Sabbir
run: echo $NAMEDependency.
jobs:
test:
build:
needs: test
deploy:
needs: buildFlow:
test → build → deploy
Conditional run.
if: github.ref == 'refs/heads/main'Encrypted variables.
Examples:
- DB_PASSWORD
- API_KEY
- SSH_KEY
- JWT_SECRET
Use:
${{ secrets.API_KEY }}Example:
- run: echo "${{ secrets.API_KEY }}"Never hardcode.
Bad:
PASSWORD=123456One job passes value to another.
Example:
outputs:
version: v1Use:
needs.build.outputs.versionRun multiple versions.
Example:
strategy:
matrix:
node: [18, 20, 22]Runs 3 jobs.
Useful:
- multi version test
- multi OS test
Speed up builds.
Example:
- uses: actions/cache@v4Cache:
- npm
- yarn
- pnpm
- pip
- gradle
Benefit:
Fast CI.
Save generated files.
Example:
- build zip
- test report
- coverage report
Upload:
- uses: actions/upload-artifact@v4Download later.
Purpose:
One workflow reused everywhere.
Example:
.github/workflows/node-ci.ymlReusable:
on:
workflow_call:Input:
inputs:
node_version:
required: true
type: stringCall:
jobs:
call:
uses: ./.github/workflows/node-ci.yml
with:
node_version: 20Useful:
Organization standard pipeline.
Reusable step group.
Folder:
.github/actions/setup-app/Contains:
action.ymlExample:
name: Setup App
description: Install app deps
runs:
using: composite
steps:
- run: npm install
shell: bashUse:
- uses: ./.github/actions/setup-appComposite:
→ step reusable
Reusable Workflow:
→ whole workflow reusable
Container based action.
Good for:
- isolated runtime
- custom toolchain
Contains:
Dockerfile
Node based action.
Fast.
Reusable.
Marketplace actions mostly JS.
Own machine.
Examples:
- VPS
- EC2
- office server
Benefits:
- more CPU
- custom software
- private network
Use DB inside CI.
Example:
Postgres
Redis
MySQL
Example:
services:
postgres:Useful for integration tests.
Deployment stage:
- dev
- staging
- production
Protection:
- manual approval
- secret isolation
Token permission limit.
Example:
permissions:
contents: readSecurity best practice.
Least privilege.
Prevent duplicate workflow.
concurrency: productionOld deploy cancels.
Only latest runs.
Send to:
- Slack
- Discord
Example:
Deploy failed → notify team
name: Node CI
on:
pull_request:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run lint
- run: npm test
- run: npm run build- run: docker build -t app .
- run: docker push imageProduction:
Build → Tag → Push → Deploy
Flow:
Push
↓
Test
↓
Docker build
↓
Push image
↓
SSH server
↓
Pull image
↓
Restart container
Apps:
apps/
frontend/
backend/Only backend changed:
Run backend workflow.
Path filter.
Efficient.
Split:
- ci.yml
- deploy.yml
- release.yml
Use:
- composite
- reusable workflow
Never echo secret.
Fast builds.
Good:
@v4Not:
npm installUse:
npm ciCI friendly.
timeout-minutes: 10Prevent duplicate deploy.
Check:
Actions tab logs
Use:
- run: pwd- run: env- run: ls -laPrint debug info.
Developer Push
↓
Lint
↓
Test
↓
Build
↓
Docker Build
↓
Security Scan
↓
Push Registry
↓
Deploy Staging
↓
Approval
↓
Deploy Production
↓
Notify Team
GitHub Actions = automation brain of repo.
Main pillars:
- Workflow
- Event
- Job
- Step
- Action
- Runner
- Secret
- Reusable workflow
- Composite action
✔ Secrets use করো (never hardcode) 🔐 ✔ Cache use করো ⚡ ✔ Reusable workflow use করো ✔ Small & modular pipeline রাখো ✔ Environment protection ব্যবহার করো
- GitHub Actions logs check করো
- echo ব্যবহার করো
- step by step isolate করো
- failed step identify করো
❌ checkout missing ❌ wrong node version ❌ secrets missing ❌ wrong path