name: CI

on:
  pull_request:
  push:
    branches:
      - main
      - master
  workflow_dispatch:

permissions:
  contents: read

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

jobs:
  quality:
    name: Quality Gate
    runs-on: ubuntu-latest
    timeout-minutes: 20

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm

      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          go-version-file: apps/backend/go.mod
          cache-dependency-path: |
            apps/backend/go.sum

      - name: Install dependencies
        run: npm ci

      - name: Run CI quality gate
        run: npm run ci

      - name: Verify generated API client is committed
        run: |
          git diff --exit-code -- packages/api-client/src/client packages/api-client/src/index.ts || {
            echo "Generated API client is out of date. Run 'npm run gen:api' and commit changes.";
            exit 1;
          }
