ci: add backend SonarQube analysis #23
Conventional commits / commits (pull_request) Successful in 27s
Backend security / security (pull_request) Successful in 1m14s
Backend verify / verify (pull_request) Successful in 2m39s
Backend security / security (push) Successful in 8s
Backend verify / verify (push) Successful in 4m26s
Conventional commits / commits (pull_request) Successful in 27s
Backend security / security (pull_request) Successful in 1m14s
Backend verify / verify (pull_request) Successful in 2m39s
Backend security / security (push) Successful in 8s
Backend verify / verify (push) Successful in 4m26s
This commit was merged in pull request #24.
This commit is contained in:
@@ -10,6 +10,8 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: https://github.com/actions/checkout@v4
|
- uses: https://github.com/actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
- name: Record checked revision
|
- name: Record checked revision
|
||||||
run: git rev-parse HEAD
|
run: git rev-parse HEAD
|
||||||
- uses: https://github.com/actions/setup-node@v4
|
- uses: https://github.com/actions/setup-node@v4
|
||||||
@@ -22,3 +24,11 @@ jobs:
|
|||||||
run: npm run verify
|
run: npm run verify
|
||||||
- name: Run isolated SQLite and runtime OpenAPI suites
|
- name: Run isolated SQLite and runtime OpenAPI suites
|
||||||
run: npm run test:e2e
|
run: npm run test:e2e
|
||||||
|
- name: Analyze develop with SonarQube
|
||||||
|
if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/develop'
|
||||||
|
# v2.3.0: same Docker-based scanner used for SonarQube 9.9.
|
||||||
|
uses: https://github.com/SonarSource/sonarqube-scan-action@aecaf43ae57e412bd97d70ef9ce6076e672fe0a9
|
||||||
|
env:
|
||||||
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
|
with:
|
||||||
|
args: -Dsonar.qualitygate.wait=true
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ lerna-debug.log*
|
|||||||
|
|
||||||
# Tests
|
# Tests
|
||||||
/coverage
|
/coverage
|
||||||
|
/.scannerwork
|
||||||
/.nyc_output
|
/.nyc_output
|
||||||
|
|
||||||
# IDEs and editors
|
# IDEs and editors
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ npm run verify
|
|||||||
```
|
```
|
||||||
|
|
||||||
Он запускает zero-warning lint,
|
Он запускает zero-warning lint,
|
||||||
application/test typechecks, Jest и build. `npm run lint:fix` — отдельная
|
application/test typechecks, Jest с покрытием и build. `npm run lint:fix` — отдельная
|
||||||
записывающая команда, `npm run test:cov` — диагностика без общего числового
|
записывающая команда. `npm run test:cov` также доступен отдельно; общего числового
|
||||||
threshold. `npm run test:e2e` отдельно проверяет все HTTP suites на новых базах
|
threshold нет. `npm run test:e2e` отдельно проверяет все HTTP suites на новых базах
|
||||||
и соответствие генерируемого OpenAPI настроенному приложению. Для полной backend-проверки
|
и соответствие генерируемого OpenAPI настроенному приложению. Для полной backend-проверки
|
||||||
выполните обе команды.
|
выполните обе команды.
|
||||||
|
|
||||||
@@ -102,6 +102,38 @@ Required checks настраиваются отдельно в Gitea: налич
|
|||||||
runtime-валидацию. В обычном коде нужны инициализация или сужение типа
|
runtime-валидацию. В обычном коде нужны инициализация или сужение типа
|
||||||
после проверки значения.
|
после проверки значения.
|
||||||
|
|
||||||
|
## SonarQube
|
||||||
|
|
||||||
|
Проект `wealthledger-backend` на `https://sonarqube.ksv741.keenetic.pro`
|
||||||
|
использует `sonar-project.properties`. Анализируются исходники `src`; unit specs
|
||||||
|
и HTTP specs учитываются как тесты. Внешние T-Bank proto contracts исключены,
|
||||||
|
generated Prisma client находится за пределами `sonar.sources`.
|
||||||
|
|
||||||
|
`npm run verify` запускает unit tests с покрытием один раз. Jest штатно создаёт
|
||||||
|
`coverage/lcov.info`; scanner импортирует этот отчёт. Покрытие HTTP/e2e tests
|
||||||
|
в него не входит, сами HTTP suites остаются обязательным отдельным шагом CI.
|
||||||
|
|
||||||
|
Создайте в SonarQube проект с ключом `wealthledger-backend`, а в Gitea → backend →
|
||||||
|
Settings → Actions → Secrets добавьте `SONAR_TOKEN` с правом анализа этого проекта.
|
||||||
|
Токен не сохраняется в файлах. Community Edition 9.9.8 получает анализ только
|
||||||
|
при push в `develop`, после успешных `verify` и SQLite/e2e checks. CI ожидает
|
||||||
|
Quality Gate; отрицательный результат или ошибка scanner завершает job с ошибкой.
|
||||||
|
PR и другие ветки проходят штатные проверки без отправки анализа.
|
||||||
|
Переименование основной ветки SonarQube не требуется; `sonar.branch.name` не задаётся.
|
||||||
|
|
||||||
|
Runner должен поддерживать Docker actions и иметь доступ к GitHub, Docker Hub
|
||||||
|
и HTTPS-адресу SonarQube с действующим сертификатом для этого имени.
|
||||||
|
Официальный Docker action закреплён на commit версии 2.3.0, как в frontend.
|
||||||
|
`tsconfig.sonar.json` содержит совместимые со старым анализатором настройки
|
||||||
|
модулей и decorators с target ES2022, без новых compiler options приложения.
|
||||||
|
Штатная компиляция приложения остаётся на ES2023.
|
||||||
|
После обновления сервера пересмотрите scanner и необходимость отдельного tsconfig.
|
||||||
|
|
||||||
|
Локально после `nvm use --silent`, `npm ci` и генерации Prisma client выполните
|
||||||
|
`npm run verify`, затем `sonar-scanner` с совместимым SonarScanner CLI и
|
||||||
|
`SONAR_TOKEN` в окружении. Первый запуск CI после merge должен подтвердить
|
||||||
|
загрузку отчёта и покрытия: локальные проверки не доказывают доступность сервера.
|
||||||
|
|
||||||
## Документация
|
## Документация
|
||||||
|
|
||||||
- [AGENTS: правила и источники](AGENTS.md)
|
- [AGENTS: правила и источники](AGENTS.md)
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@
|
|||||||
"test:container": "node test/container-smoke.cjs",
|
"test:container": "node test/container-smoke.cjs",
|
||||||
"test:durability": "node test/bank-cards-durability.cjs",
|
"test:durability": "node test/bank-cards-durability.cjs",
|
||||||
"test:openapi-contract": "npm run build && node test/sqlite.cjs openapi-contract.e2e-spec.ts",
|
"test:openapi-contract": "npm run build && node test/sqlite.cjs openapi-contract.e2e-spec.ts",
|
||||||
"verify": "npm run lint && npm run typecheck:app && npm run typecheck:test && npm test -- --runInBand && npm run build",
|
"verify": "npm run lint && npm run typecheck:app && npm run typecheck:test && npm run test:cov -- --runInBand && npm run build",
|
||||||
"release:preview": "release-it --dry-run --ci",
|
"release:preview": "release-it --dry-run --ci",
|
||||||
"release:prepare": "release-it --ci",
|
"release:prepare": "release-it --ci",
|
||||||
"commitlint": "commitlint"
|
"commitlint": "commitlint"
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
sonar.projectKey=wealthledger-backend
|
||||||
|
sonar.projectName=WealthLedger backend
|
||||||
|
sonar.host.url=https://sonarqube.ksv741.keenetic.pro
|
||||||
|
sonar.sourceEncoding=UTF-8
|
||||||
|
|
||||||
|
sonar.sources=src
|
||||||
|
sonar.tests=src,test
|
||||||
|
sonar.test.inclusions=src/**/*.spec.ts,test/**/*.e2e-spec.ts
|
||||||
|
sonar.exclusions=src/**/*.spec.ts,src/integrations/tbank/proto/contracts/**
|
||||||
|
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
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "nodenext",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"target": "ES2022",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"noEmit": true
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.ts", "test/**/*.ts"],
|
||||||
|
"exclude": ["node_modules", "dist", "generated"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user