From d58b49d185f73195c2720ae745fe1b0f887caab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kh=C3=A1nh=20Ho=C3=A0ng?= Date: Mon, 2 Dec 2024 15:04:50 +0700 Subject: [PATCH] chore(testing): Configure SonarQube to include TypeScript test files (#36) * chore(testing): Configure SonarQube to include TypeScript test files Added a configuration to include TypeScript test files located in the `src` directory for SonarQube analysis. This change helps in capturing and analyzing test-specific metrics to enhance code quality assessments. * Integrate SonarCloud config into GitHub Workflow Remove the standalone sonar-project.properties file and incorporate its configuration directly into the GitHub Actions workflow. This change centralizes the SonarCloud configuration, streamlining the maintenance and execution process within the CI/CD pipeline. * Update ESLint workflow to adjust report file paths Modified the ESLint run command to process the report by removing the workspace path prefix in the 'eslint-report.json'. This change ensures that file paths in the report are relative, thus simplifying file path management and making reports easier to manage and interpret. * Update ESLint report path in GitHub Actions This change modifies the path replacement in the ESLint report generation step to use '/github/workspace/' instead of removing the GitHub workspace path prefix. This ensures that paths in the ESLint report correctly reflect the directory structure used during the GitHub Action's execution. It aims to improve the accuracy and usefulness of the ESLint reports in CI workflows. * Add SonarCloud configuration and streamline CI setup Introduce a new `sonar-project.properties` file to configure SonarCloud integration for the project. This change centralizes the SonarCloud settings and removes redundant command-line parameters from the GitHub Actions workflow. Additionally, it fixes the ESLint report path in CI by stripping the workspace prefix. * Refactor sonar configuration and update ESLint command path. Reordered the paths for JavaScript and ESLint reports in sonar-project.properties to enhance readability and maintain consistency. Updated the ESLint command in package.json to specify the src/ directory, ensuring linting is applied only to source files. --- .github/workflows/tests.yml | 6 ++++-- package.json | 2 +- sonar-project.properties | 6 ++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 85e0af0..4cb1816 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -88,8 +88,10 @@ jobs: run: pnpm test -- --coverage.enabled env: GOOGLE_SAFE_BROWSING_API_KEY: ${{ secrets.GOOGLE_SAFE_BROWSING_API_KEY }} - - name: Run ESLint - run: pnpm test:eslint + - name: Generate ESLint report + run: | + pnpm test:eslint + sed -i 's|${{ github.workspace }}/||g' lints/eslint-report.json - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@383f7e52eae3ab0510c3cb0e7d9d150bbaeab838 env: diff --git a/package.json b/package.json index 4a2b2d8..0446045 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "test": "vitest related src/*.ts", "test:prettier": "prettier --check .", "test:types": "deno check src/index.ts", - "test:eslint": "eslint . -f json -o lints/eslint-report.json" + "test:eslint": "eslint src/ -f json -o lints/eslint-report.json" }, "author": { "name": "Khánh Hoàng", diff --git a/sonar-project.properties b/sonar-project.properties index 1ed0f3b..1a73a1f 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,5 +1,11 @@ sonar.projectKey=hckhanh_google-safe-browsing sonar.organization=hckhanh +sonar.sources=src/ +sonar.exclusions=src/**/*.test.ts + +sonar.tests=src/ +sonar.test.inclusions=src/**/*.test.ts + sonar.javascript.lcov.reportPaths=coverage/lcov.info sonar.eslint.reportPaths=lints/eslint-report.json