diff --git a/.gitea/workflows/verify.yml b/.gitea/workflows/verify.yml index 5e4898f..bd7f96f 100644 --- a/.gitea/workflows/verify.yml +++ b/.gitea/workflows/verify.yml @@ -11,6 +11,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: https://github.com/actions/checkout@v4 + with: + fetch-depth: 0 - name: Record checked revision run: git rev-parse HEAD - uses: https://github.com/actions/setup-node@v4 @@ -24,3 +26,11 @@ jobs: env: # OXC raw transfer allocates a ~6 GiB buffer; use the standard parser in CI. KNIP_DISABLE_RAW_TRANSFER: '1' + - name: Analyze develop with SonarQube + if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/develop' + # v2.3.0: Docker-based scanner for the SonarQube 9.9 server. + uses: https://github.com/SonarSource/sonarqube-scan-action@aecaf43ae57e412bd97d70ef9ce6076e672fe0a9 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: -Dsonar.qualitygate.wait=true diff --git a/.gitignore b/.gitignore index c2a0011..17ca640 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ dist storybook-static dist-ssr coverage +.scannerwork *.local # Local runtime configuration diff --git a/README.md b/README.md index d5f4d81..d3ab2b2 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,42 @@ TypeScript остаётся на 5.9.3: `openapi-typescript@7.13.0` требуе обновите `src/shared/api/spec/openapi.json` копированием backend OpenAPI document и затем выполните `npm run openapi:generate`. +## SonarQube + +Проект `wealthledger-frontend` использует настройки из +`sonar-project.properties`. Анализируются исходники `src`; тесты учитываются +отдельно, а Storybook fixtures, test helpers, generated API types и OpenAPI +snapshot исключены. `npm run test:coverage` (также входит в `npm run verify`) +создаёт `coverage/lcov.info` для импорта покрытия. + +Для первого анализа установите SonarScanner CLI, совместимый с версией сервера, +и выполните из корня frontend: + +```bash +nvm use --silent +npm ci +npm run test:coverage +# SONAR_TOKEN передайте через окружение; не сохраняйте токен в репозитории. +sonar-scanner +``` + +В Gitea откройте frontend → Settings → Actions → Secrets и добавьте +`SONAR_TOKEN` с токеном анализа проекта. Переименовывать основную ветку в +SonarQube не требуется; `sonar.branch.name` не задаётся. +Используется Community Edition 9.9.8: CI отправляет только +push в `develop`, после успешного `verify`, и ожидает результат Quality Gate. +PR и остальные ветки проходят обычные проверки без отправки в SonarQube. +Отрицательный Quality Gate или ошибка scanner завершает `verify` с ошибкой. + +Runner должен поддерживать Docker actions и иметь HTTPS-доступ к +`https://sonarqube.ksv741.keenetic.pro`, GitHub и Docker Hub. Docker action +SonarSource закреплён на commit версии 2.3.0; scanner запускается отдельно от +Node 24, используемого для сборки. `tsconfig.sonar.json` содержит совместимые +со старым анализатором TS настройки; приложение проверяется штатным TypeScript +5.9 через `npm run verify`. После обновления сервера пересмотрите scanner и +возможность использовать основной tsconfig. Успешный локальный `verify` не +доказывает доступность сервера и успешность анализа в CI. + ## UI-каталог Storybook После `nvm use --silent` выполните `npm run dev:catalog`; статическая сборка — diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..e9631e6 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,12 @@ +sonar.projectKey=wealthledger-frontend +sonar.projectName=WealthLedger frontend +sonar.host.url=https://sonarqube.ksv741.keenetic.pro +sonar.sourceEncoding=UTF-8 + +sonar.sources=src +sonar.tests=src +sonar.test.inclusions=src/**/*.test.ts,src/**/*.test.tsx +sonar.exclusions=src/**/*.test.ts,src/**/*.test.tsx,src/**/*.stories.tsx,src/test/**,src/shared/api/generated/**,src/shared/api/spec/** +sonar.javascript.lcov.reportPaths=coverage/lcov.info +# SonarQube 9.9 embeds an older TypeScript analyzer than the application compiler. +sonar.typescript.tsconfigPaths=tsconfig.sonar.json diff --git a/tsconfig.sonar.json b/tsconfig.sonar.json new file mode 100644 index 0000000..7d071c3 --- /dev/null +++ b/tsconfig.sonar.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ESNext", + "moduleResolution": "node", + "jsx": "react-jsx", + "strict": true, + "skipLibCheck": true, + "noEmit": true, + "baseUrl": ".", + "paths": { "@/*": ["src/*"] } + }, + "include": ["src"] +} diff --git a/vitest.config.ts b/vitest.config.ts index 886917c..611525c 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -21,7 +21,7 @@ export default defineConfig({ "src/**/*.test.{ts,tsx}", "src/**/*.stories.tsx", ], - reporter: ["text", "html"], + reporter: ["text", "html", "lcov"], thresholds: { statements: 82, branches: 75,