Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 41 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@

# =============================================
# TraffiTech — GitHub Actions CI/CD Pipeline
# =============================================
# Triggers: Every push to main & all pull requests
# Jobs: lint → test-frontend → test-backend → build
# Triggers: Push to main and pull requests targeting main
# Jobs: lint -> test-frontend + test-backend -> build

name: TraffiTech CI

on:
push:
branches: [main]
branches:
- main
pull_request:
branches: [main]
branches:
- main

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
# ─────────────────────────────────

# =============================================
# Job 1: Code Linting & Formatting
# ─────────────────────────────────
# =============================================
lint:
name: Lint & Format Check
runs-on: ubuntu-latest
Expand All @@ -28,7 +39,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache: npm

- name: Install dependencies
run: npm ci
Expand All @@ -39,9 +50,10 @@ jobs:
- name: Check Prettier formatting
run: npm run format:check

# ─────────────────────────────────

# =============================================
# Job 2: Frontend Tests (Vitest)
# ─────────────────────────────────
# =============================================
test-frontend:
name: Frontend Tests (Vitest)
runs-on: ubuntu-latest
Expand All @@ -55,7 +67,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache: npm

- name: Install dependencies
run: npm ci
Expand All @@ -69,16 +81,22 @@ jobs:
with:
name: frontend-coverage
path: coverage/
if-no-files-found: ignore
retention-days: 7

# ─────────────────────────────────

# =============================================
# Job 3: Backend Tests (Jest)
# ─────────────────────────────────
# =============================================
test-backend:
name: Backend Tests (Jest)
runs-on: ubuntu-latest
needs: lint

defaults:
run:
working-directory: server

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -87,26 +105,27 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache: npm
cache-dependency-path: server/package-lock.json

- name: Install backend dependencies
run: npm ci
working-directory: server

- name: Run Jest tests
run: npm test
working-directory: server
env:
NODE_ENV: test

# ─────────────────────────────────
# Job 4: Production Build Verify
# ─────────────────────────────────

# =============================================
# Job 4: Production Build Verification
# =============================================
build:
name: Verify Production Build
runs-on: ubuntu-latest
needs: [test-frontend, test-backend]
needs:
- test-frontend
- test-backend

steps:
- name: Checkout code
Expand All @@ -116,12 +135,12 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache: npm

- name: Install dependencies
run: npm ci

- name: Create dummy .env for build
- name: Create dummy environment variables for CI
run: |
echo "VITE_STRIPE_PUBLISHABLE_KEY=pk_test_dummy_key_for_ci" > .env
echo "VITE_API_URL=http://localhost:5000" >> .env
Expand All @@ -134,4 +153,5 @@ jobs:
with:
name: dist
path: dist/
if-no-files-found: error
retention-days: 3