# .github/workflows/ci.yml
# Version: 1.1.0
# Description: Clean CI pipeline with lint, test, fixtures, coverage, and release
# Author: Ali Kahwaji

name: CI & Release

on:
  push:
    branches: [main]
    tags: ['v*']
  pull_request:
    branches: [main]

jobs:
  build-test-release:
    name: Lint, Test, and Release
    runs-on: ubuntu-latest

    steps:
      - name: ⬇️ Checkout code
        uses: actions/checkout@v4

      - name: 🟢 Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'npm'
          registry-url: 'https://registry.npmjs.org/'

      - name: 📦 Install dependencies
        run: npm ci

      - name: 🧹 Lint codebase
        run: npm run lint

      - name: ✅ Run tests with coverage
        run: npm test

      - name: 🧪 Validate Fixtures
        run: npm run validate-fixtures

      - name: 📊 Upload coverage to Codecov
        uses: codecov/codecov-action@v5
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          slug: DevilsDev/rag-pipeline-utils

      - name: 🚀 Semantic Release
        env:
          GH_TOKEN: ${{ secrets.GH_TOKEN }}            # ✅ Required by @semantic-release/github
          GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}        # ✅ Used by GitHub Actions
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: npx semantic-release
