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 <aashit@getcollate.io>
This commit is contained in:
Akash Jain 2022-04-01 10:31:45 +05:30 committed by GitHub
parent bd2f52863b
commit 4e1b44d696
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 105 additions and 1 deletions

74
.github/workflows/yarn-coverage.yml vendored Normal file
View File

@ -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

View File

@ -52,4 +52,7 @@ module.exports = {
'@fortawesome/react-fontawesome':
'<rootDir>/src/test/unit/mocks/fontawesome.mock.js',
},
// Sonar Cloud Configuration
testResultsProcessor: 'jest-sonar-reporter',
};

View File

@ -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",

View File

@ -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

View File

@ -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"