diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44bbaea..0569e11 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -28,7 +39,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: '20' - cache: 'npm' + cache: npm - name: Install dependencies run: npm ci @@ -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 @@ -55,7 +67,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: '20' - cache: 'npm' + cache: npm - name: Install dependencies run: npm ci @@ -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 @@ -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 @@ -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 @@ -134,4 +153,5 @@ jobs: with: name: dist path: dist/ + if-no-files-found: error retention-days: 3