# CI/CD & Dev Experience Optimization Plan ## Current Situation - **Husky `pre-commit`**: Runs `npm test` (Vitest) on every commit. This likely runs the entire test suite, which is slow and frustrating for developers. - **Gitea Actions**: Currently only has `contract-testing.yml`. - **Missing**: No automated linting or type-checking in CI, no tiered testing strategy. ## Proposed Strategy: The "Fast Feedback Loop" We will implement a tiered approach to balance speed and safety. ### 1. Local Development (Husky + lint-staged) **Goal**: Prevent obvious errors from entering the repo without slowing down the dev. - **Trigger**: `pre-commit` - **Action**: Only run on **staged files**. - **Tasks**: - `eslint --fix` - `prettier --write` - `vitest related` (only run tests related to changed files) ### 2. Pull Request (Gitea Actions) **Goal**: Ensure the branch is stable and doesn't break the build or other modules. - **Trigger**: PR creation and updates. - **Tasks**: - Full `lint` - Full `typecheck` (crucial for monorepo integrity) - Full `unit tests` - `integration tests` - `contract tests` ### 3. Merge to Main / Release (Gitea Actions) **Goal**: Final verification before deployment. - **Trigger**: Push to `main` or `develop`. - **Tasks**: - Everything from PR stage. - `e2e tests` (Playwright) - these are the slowest and most expensive. --- ## Implementation Steps ### Step 1: Install and Configure `lint-staged` We need to add `lint-staged` to [`package.json`](package.json) and update the Husky hook. ### Step 2: Optimize Husky Hook Update [`.husky/pre-commit`](.husky/pre-commit) to run `npx lint-staged` instead of `npm test`. ### Step 3: Create Comprehensive CI Workflow Create `.github/workflows/ci.yml` (Gitea Actions compatible) to handle the heavy lifting. --- ## Workflow Diagram ```mermaid graph TD A[Developer Commits] --> B{Husky pre-commit} B -->|lint-staged| C[Lint/Format Changed Files] C --> D[Run Related Tests] D --> E[Commit Success] E --> F[Push to PR] F --> G{Gitea CI PR Job} G --> H[Full Lint & Typecheck] G --> I[Full Unit & Integration Tests] G --> J[Contract Tests] J --> K{Merge to Main} K --> L{Gitea CI Main Job} L --> M[All PR Checks] L --> N[Full E2E Tests] N --> O[Deploy/Release] ``` ## Proposed `lint-staged` Configuration ```json { "*.{js,ts,tsx}": ["eslint --fix", "vitest related --run"], "*.{json,md,yml}": ["prettier --write"] } ``` --- ## Questions for the User 1. Do you want to include `typecheck` in the `pre-commit` hook? (Note: `tsc` doesn't support linting only changed files easily, so it usually checks the whole project, which might be slow). 2. Should we run `integration tests` on every PR, or only on merge to `main`? 3. Are there specific directories that should be excluded from this automated flow?