From 4e1b44d6968c38d819ba575ad7c92fb408a8393a Mon Sep 17 00:00:00 2001 From: Akash Jain <15995028+akash-jain-10@users.noreply.github.com> Date: Fri, 1 Apr 2022 10:31:45 +0530 Subject: [PATCH] feat: Add Workflow CI for SonarCloud OpenMetadata UI (#3708) * Adding Workflow CI for SonarCloud OpenMetadata UI * Adding sonar project properties and reporter for UI * Added mock and test exclusions * Minor changes * fix node version to 12.x in CI * Test CI workflow * fixed syntax * remove yarn caching * test docker on steps * remove jobs container * test out args * update path * check with yarn * fix typo * fix typo * fix typo * fix typo * use npm -g command * removed project base dir Co-authored-by: darth-coder00 --- .github/workflows/yarn-coverage.yml | 74 +++++++++++++++++++ .../src/main/resources/ui/jest.config.js | 3 + .../src/main/resources/ui/package.json | 4 +- .../resources/ui/sonar-project.properties | 13 ++++ .../src/main/resources/ui/yarn.lock | 12 +++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/yarn-coverage.yml create mode 100644 openmetadata-ui/src/main/resources/ui/sonar-project.properties diff --git a/.github/workflows/yarn-coverage.yml b/.github/workflows/yarn-coverage.yml new file mode 100644 index 00000000000..eccfc4e0ca3 --- /dev/null +++ b/.github/workflows/yarn-coverage.yml @@ -0,0 +1,74 @@ +name: Node Yarn Coverage + Sonar + +on: + # Trigger analysis when pushing in master or pull requests, and when creating + # a pull request. + push: + branches: + - main + paths: + - openmetadata-ui/src/main/resources/ui/** + pull_request: + types: [opened, synchronize, reopened] + paths: + - openmetadata-ui/src/main/resources/ui/** +env: + UI_WORKING_DIRECTORY: openmetadata-ui/src/main/resources/ui +jobs: + coverage-tests: + strategy: + matrix: + node-version: [12.x] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + # Disabling shallow clone is recommended for improving relevancy of reporting + fetch-depth: 0 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - name: Install Yarn Packages + working-directory: ${{ env.UI_WORKING_DIRECTORY }} + run: yarn install + - name: Run Coverage + working-directory: ${{ env.UI_WORKING_DIRECTORY }} + run: yarn test:coverage + id: yarn_coverage + - name: yarn add sonarqube-scanner + working-directory: ${{ env.UI_WORKING_DIRECTORY }} + run: npm install -g sonarqube-scanner + id: npm_install_sonar_scanner + - name: SonarCloud Scan On PR + if: steps.npm_install_sonar_scanner.outcome == 'success' && github.event_name == 'pull_request' + working-directory: ${{ env.UI_WORKING_DIRECTORY }} + run: | + sonar-scanner -Dsonar.host.url=${SONARCLOUD_URL} \ + -Dproject.settings=sonar-project.properties \ + -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \ + -Dsonar.pullrequest.branch=${{ github.head_ref }} \ + -Dsonar.pullrequest.base=main \ + -Donar.pullrequest.github.repository=OpenMetadata \ + -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \ + -Dsonar.pullrequest.provider=github + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.UI_SONAR_TOKEN }} + SONARCLOUD_URL: https://sonarcloud.io + - name: SonarCloud Scan + if: github.event_name == 'push' && steps.npm_install_sonar_scanner.outcome == 'success' + working-directory: ${{ env.UI_WORKING_DIRECTORY }} + run: | + sonar-scanner -Dsonar.host.url=${SONARCLOUD_URL} \ + -Dproject.settings=sonar-project.properties \ + -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \ + -Dsonar.pullrequest.branch=${{ github.head_ref }} \ + -Dsonar.pullrequest.base=main \ + -Donar.pullrequest.github.repository=OpenMetadata \ + -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \ + -Dsonar.pullrequest.provider=github + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.UI_SONAR_TOKEN }} + SONARCLOUD_URL: https://sonarcloud.io \ No newline at end of file diff --git a/openmetadata-ui/src/main/resources/ui/jest.config.js b/openmetadata-ui/src/main/resources/ui/jest.config.js index 273b32a536a..5683c7a61fc 100644 --- a/openmetadata-ui/src/main/resources/ui/jest.config.js +++ b/openmetadata-ui/src/main/resources/ui/jest.config.js @@ -52,4 +52,7 @@ module.exports = { '@fortawesome/react-fontawesome': '/src/test/unit/mocks/fontawesome.mock.js', }, + + // Sonar Cloud Configuration + testResultsProcessor: 'jest-sonar-reporter', }; diff --git a/openmetadata-ui/src/main/resources/ui/package.json b/openmetadata-ui/src/main/resources/ui/package.json index 2476cd206bf..21ab22da1d2 100644 --- a/openmetadata-ui/src/main/resources/ui/package.json +++ b/openmetadata-ui/src/main/resources/ui/package.json @@ -90,7 +90,8 @@ "mock-api": "node ./mock-api/app.js", "test": "jest --passWithNoTests", "test:watch": "jest --passWithNoTests --watch", - "test:coverage": "jest --passWithNoTests --coverage --coverageReporters=\"text-summary\"", + "test:coverage": "jest --passWithNoTests --coverage", + "test:cov-summary": "jest --passWithNoTests --coverage --coverageReporters=\"text-summary\"", "lint": "eslint \"./src/**/*.{js,jsx,ts,tsx}\"", "lint:fix": "eslint './src/**/*.{js,jsx,ts,tsx}' --fix", "pretty": "prettier . --config './.prettierrc' --write", @@ -163,6 +164,7 @@ "html-webpack-plugin": "^4.5.1", "jest": "^26.6.3", "jest-environment-jsdom-fourteen": "^1.0.1", + "jest-sonar-reporter": "^2.0.0", "lint-staged": "^10.3.0", "mini-css-extract-plugin": "0.9.0", "organize-imports-cli": "^0.7.0", diff --git a/openmetadata-ui/src/main/resources/ui/sonar-project.properties b/openmetadata-ui/src/main/resources/ui/sonar-project.properties new file mode 100644 index 00000000000..49019675a56 --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/sonar-project.properties @@ -0,0 +1,13 @@ +sonar.projectKey=open-metadata-ui +sonar.projectName=open-metadata-ui +sonar.organization=open-metadata +sonar.language=ts + +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +# This property is optional if sonar.modules is set. +sonar.sources=src +sonar.tests=src/test/unit +sonar.exclusions=src/enums/**, src/generated/**, src/interface/**, src/jsons/**, src/mocks/**, src/styles/**, src/**/*.mock.*, src/*.js, src/**/*.test.ts, src/**/*.test.tsx, src/**/*.test.js, src/**/*.test.jsx +sonar.inclusions=src/**/*.ts, src/**/*.tsx, src/**/*.js, src/**/*.jsx +sonar.typescript.lcov.reportPaths=src/test/unit/coverage/lcov.info +sonar.testExecutionReportPaths=test-report.xml diff --git a/openmetadata-ui/src/main/resources/ui/yarn.lock b/openmetadata-ui/src/main/resources/ui/yarn.lock index aa6579675f9..4ac9a7f510a 100644 --- a/openmetadata-ui/src/main/resources/ui/yarn.lock +++ b/openmetadata-ui/src/main/resources/ui/yarn.lock @@ -7674,6 +7674,13 @@ jest-snapshot@^26.6.2: pretty-format "^26.6.2" semver "^7.3.2" +jest-sonar-reporter@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/jest-sonar-reporter/-/jest-sonar-reporter-2.0.0.tgz#faa54a7d2af7198767ee246a82b78c576789cf08" + integrity sha512-ZervDCgEX5gdUbdtWsjdipLN3bKJwpxbvhkYNXTAYvAckCihobSLr9OT/IuyNIRT1EZMDDwR6DroWtrq+IL64w== + dependencies: + xml "^1.0.1" + jest-util@^24.0.0, jest-util@^24.9.0: version "24.9.0" resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-24.9.0.tgz#7396814e48536d2e85a37de3e4c431d7cb140162" @@ -13193,6 +13200,11 @@ xml-name-validator@^3.0.0: resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a" integrity sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw== +xml@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5" + integrity sha1-eLpyAgApxbyHuKgaPPzXS0ovweU= + xmlchars@^2.1.1, xmlchars@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"