What is a Workflow?
A workflow is a YAML file that defines when automation runs and what it does.
Location:
.github/workflows/
It includes:
- Triggers (
on) - Jobs
- Steps (commands or actions)
Basic Structure
name: My Workflow
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install
run: npm i
- name: Test
run: npm run testKey Parts
name
Display name in the Actions UI.
on (trigger)
When the workflow runs:
on: pushon:
pull_request:on:
push:
branches: [main]jobs
One or more jobs. Each job:
- Runs on a runner
- Executes a list of steps
runs-on
Where the job executes:
| Value | Meaning |
|---|---|
ubuntu-latest | GitHub-hosted Ubuntu VM |
self-hosted | Your EC2 (or other) runner |
steps
The actual commands:
steps:
- run: npm i
- run: npm run testProduction-style CI/CD Pipeline
name: CI/CD Pipeline
on:
push:
branches: [master]
jobs:
deploy:
runs-on: self-hosted
steps:
- name: Install
run: npm i
- name: Test
run: npm run test
- name: Start App
run: pm2 restart appAdjust branch names (main vs master) and paths to match your repo.
Syncing Code with rsync
If the runner workspace and the live app directory differ, sync files before install / restart:
rsync -av --delete ./ /home/ubuntu/app/github-action-ci-cd/| Flag / path | Meaning |
|---|---|
rsync | Fast file sync (often preferred over plain cp) |
-a | Archive mode (permissions, structure) |
-v | Verbose |
./ | Current runner workspace |
--delete | Remove files in destination that are gone from source |
| destination path | Your live app folder |
Then run commands in the live directory:
cd /home/ubuntu/app/github-action-ci-cd
npm i
pm2 restart appSimple Flow
Push Code → Workflow Triggered → Job Runs → Steps Execute
Workflow = the file that defines your automated pipeline (CI/CD) in GitHub Actions.