# CI Workflow and Package Scripts Mapping

This document maps the Gitea CI workflow jobs to the corresponding npm scripts in package.json.

## CI Workflow Jobs → Package Scripts

### 1. `lint-and-type-check` Job

**CI Workflow:**
- Runs `npm run lint` in admin-frontend
- Runs `npm run type-check` in viewer-frontend

**Package Scripts:**
- `npm run lint:admin` - Lint admin-frontend
- `npm run lint:viewer` - Lint viewer-frontend
- `npm run type-check:viewer` - Type check viewer-frontend
- `npm run lint:all` - Lint both frontends

### 2. `python-lint` Job

**CI Workflow:**
- Installs flake8, black, mypy, pylint
- Runs Python syntax check: `find backend -name "*.py" -exec python -m py_compile {} \;`
- Runs flake8: `flake8 backend --max-line-length=100 --ignore=E501,W503`

**Package Scripts:**
- `npm run lint:python` - Run flake8 on backend
- `npm run lint:python:syntax` - Check Python syntax

### 3. `test-backend` Job

**CI Workflow:**
- Installs dependencies from requirements.txt
- Runs: `python -m pytest tests/ -v`

**Package Scripts:**
- `npm run test:backend` - Run backend tests with pytest
- `npm run test:all` - Run all tests (currently just backend)

### 4. `build` Job

**CI Workflow:**
- Builds admin-frontend: `npm run build`
- Generates Prisma client: `npx prisma generate`
- Builds viewer-frontend: `npm run build`

**Package Scripts:**
- `npm run build:admin` - Build admin-frontend
- `npm run build:viewer` - Build viewer-frontend
- `npm run build:all` - Build both frontends

### 5. Security Scans

**CI Workflow:**
- `secret-scanning` - Gitleaks
- `dependency-scan` - Trivy vulnerability and secret scanning
- `sast-scan` - Semgrep

**Package Scripts:**
- No local scripts (these are CI-only security scans)

## Combined Scripts

### `ci:local` - Run All CI Checks Locally

**Package Script:**
```bash
npm run ci:local
```

This runs:
1. `lint:all` - Lint both frontends
2. `type-check:viewer` - Type check viewer-frontend
3. `lint:python` - Lint Python backend
4. `test:backend` - Run backend tests
5. `build:all` - Build both frontends

**Note:** This is a convenience script to run all CI checks locally before pushing.

## Missing from CI (Not in Package Scripts)

These CI jobs don't have corresponding package scripts (by design):
- `secret-scanning` - Gitleaks (security tool, CI-only)
- `dependency-scan` - Trivy (security tool, CI-only)
- `sast-scan` - Semgrep (security tool, CI-only)
- `workflow-summary` - CI workflow summary generation

## Usage Examples

### Run All CI Checks Locally
```bash
npm run ci:local
```

### Run Individual Checks
```bash
# Frontend linting
npm run lint:all

# Type checking
npm run type-check:viewer

# Python linting
npm run lint:python

# Backend tests
npm run test:backend

# Build everything
npm run build:all
```

### Development
```bash
# Start all services
npm run dev:admin      # Terminal 1
npm run dev:viewer     # Terminal 2
npm run dev:backend    # Terminal 3
```

## Notes

- All CI scripts use `continue-on-error: true` or `|| true` to not fail the build
- Local scripts also use `|| true` for non-critical checks
- The `ci:local` script will stop on first failure (unlike CI which continues)
- Python linting requires flake8: `pip install flake8`
- Backend tests require pytest: `pip install pytest`

