From db390e33ff59aab05966d139e78720a3de3033f9 Mon Sep 17 00:00:00 2001 From: Sivaja Patamornchai Date: Wed, 10 Jan 2024 09:09:37 +0700 Subject: [PATCH 1/2] feat: ASC-18271 - Implement Sonar Scan --- .github/sonar-scan/action.yml | 52 ++++++++++++++++++++++++++++++++++ .github/workflows/testing.yaml | 25 ++++++++++++++++ .gitignore | 6 ++++ sonar-project.properties | 8 ++++++ tests/000-always-pass.test.js | 3 ++ 5 files changed, 94 insertions(+) create mode 100644 .github/sonar-scan/action.yml create mode 100644 sonar-project.properties create mode 100644 tests/000-always-pass.test.js diff --git a/.github/sonar-scan/action.yml b/.github/sonar-scan/action.yml new file mode 100644 index 000000000..7222c382d --- /dev/null +++ b/.github/sonar-scan/action.yml @@ -0,0 +1,52 @@ +name: SonarCloud Scan +description: SonarCloud Scan action. + +inputs: + SONAR_SCANNER_VERSION: + description: SonarCloud Scanner version + default: 5.0.1.3006 + SONAR_HOST: + description: SonarCloud Scanner version + default: https://sonarcloud.io + SONAR_TOKEN: + description: SonarCloud user token + required: true + SONAR_ScanningDirectory: + description: Base Directory for Scanner + SONAR_QualityGate_Wait: + description: SonarCloud Scanner wait for QualityGate + default: 'false' + SONAR_QualityGate_Timeout: + description: SonarCloud Scanner QualityGate polling timeout + default: '3000' + NODE_VERSION: + description: Node version + default: '18' + +runs: + using: composite + steps: + # Install SonarCloud Scanner + - name: Install SonarCloud Scanner + shell: bash + run: | + export SONAR_SCANNER_VERSION=${{ inputs.SONAR_SCANNER_VERSION }} + export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux + curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip + unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ + export PATH=$SONAR_SCANNER_HOME/bin:$PATH + export SONAR_SCANNER_OPTS="-server" + + # Run the SonarCloud scan + - name: SonarCloud Scan + working-directory: ${{ inputs.SONAR_ScanningDirectory }} + shell: bash + run: | + export SONAR_SCANNER_VERSION=${{ inputs.SONAR_SCANNER_VERSION }} + export SONAR_SCANNER_BIN=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux/bin + $SONAR_SCANNER_BIN/sonar-scanner \ + -Dsonar.host.url=${{ inputs.SONAR_HOST }} \ + -Dsonar.token=${{ inputs.SONAR_TOKEN }} \ + -Dsonar.projectBaseDir=${{ inputs.SONAR_ScanningDirectory }} \ + -Dsonar.qualitygate.wait=${{ inputs.SONAR_QualityGate_Wait }} \ + -Dsonar.qualitygate.timeout=${{ inputs.SONAR_QualityGate_Timeout }} diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 89b4ecbc5..1c3a5d7b0 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -30,3 +30,28 @@ jobs: - name: eslint checks run: npm run lint + + - name: cache test results + uses: actions/cache@v3 + with: + path: ./* + key: ${{ github.sha }} + + sonar-scan: + runs-on: ubuntu-latest + name: Sonar scan + + needs: [unit_tests] + + steps: + - name: checkout repository + uses: actions/cache@v3 + id: repo + with: + path: ./* + key: ${{ github.sha }} + + - name: Sonar scan + uses: ./.github/actions/sonar-scan + with: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.gitignore b/.gitignore index 4373e0450..01d04e8c6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,9 @@ storybook-build/ .env.local .DS_Store .eslintcache + +# Test Coverage Results +coverage/ + +# Sonar-Scanner +.scannerwork/ diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 000000000..2445a290d --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,8 @@ +sonar.projectKey=amity-social-cloud-UIKit-web-opensource +sonar.organization=amityco +sonar.projectName=Amity Social Cloud: UIKit Web Opensource +sonar.sources=./src +sonar.test=./tests +sonar.exclusions = **/*.java,**/node_modules/**,**/*.spec.ts,**/*.spec.tsx,**/*.spec.js,**/*.spec.jsx,**/*.stories.tsx,**/*.stories.ts,**/*.stories.js,**/*.stories.js,scripst/**,coverage/** +sonar.test.inclusions=**/*.spec.ts +sonar.javascript.lcov.reportPaths=**/lcov.info diff --git a/tests/000-always-pass.test.js b/tests/000-always-pass.test.js new file mode 100644 index 000000000..871a1b259 --- /dev/null +++ b/tests/000-always-pass.test.js @@ -0,0 +1,3 @@ +test('Always Pass', () => { + expect(true).toBe(true); +}); From 85a679eb5bfd76b6bfc592dd1900772cc030cfc2 Mon Sep 17 00:00:00 2001 From: Sivaja Patamornchai Date: Wed, 10 Jan 2024 09:17:08 +0700 Subject: [PATCH 2/2] fix: ASC-18271 - .github/actions directory --- .github/{ => actions}/sonar-scan/action.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{ => actions}/sonar-scan/action.yml (100%) diff --git a/.github/sonar-scan/action.yml b/.github/actions/sonar-scan/action.yml similarity index 100% rename from .github/sonar-scan/action.yml rename to .github/actions/sonar-scan/action.yml