Skip to content

Commit

Permalink
feat: ASC-18278 - Implement Sonar Scan
Browse files Browse the repository at this point in the history
  • Loading branch information
zivaja committed Jan 10, 2024
1 parent f53a1e9 commit 6109770
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 110 deletions.
52 changes: 52 additions & 0 deletions .github/actions/sonar-scan/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
243 changes: 134 additions & 109 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
branches:
- main
pull_request:
branches:
- main
types: [opened, synchronize]
workflow_call:

jobs:
lint:
Expand Down Expand Up @@ -33,119 +33,144 @@ jobs:
uses: ./.github/actions/setup

- name: Run unit tests
run: yarn test --maxWorkers=2 --coverage

build-library:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup

- name: Build package
run: yarn prepack

build-android:
runs-on: ubuntu-latest
env:
TURBO_CACHE_DIR: .turbo/android
steps:
- name: Checkout
uses: actions/checkout@v3
run: yarn test

- name: Setup
uses: ./.github/actions/setup

- name: Cache turborepo for Android
- name: cache test results
uses: actions/cache@v3
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-android-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-turborepo-android-
- name: Check turborepo cache for Android
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
fi
- name: Install JDK
if: env.turbo_cache_hit != 1
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
path: ./*
key: ${{ github.sha }}

- name: Finalize Android SDK
if: env.turbo_cache_hit != 1
run: |
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
- name: Cache Gradle
if: env.turbo_cache_hit != 1
uses: actions/cache@v3
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build example for Android
run: |
yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
build-ios:
runs-on: macos-latest
env:
TURBO_CACHE_DIR: .turbo/ios
steps:
- name: Checkout
uses: actions/checkout@v3
sonar-scan:
runs-on: ubuntu-latest
name: Sonar scan

- name: Setup
uses: ./.github/actions/setup
needs: [test]

- name: Cache turborepo for iOS
steps:
- name: checkout repository
uses: actions/cache@v3
id: repo
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-turborepo-ios-
- name: Check turborepo cache for iOS
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
fi
- name: Cache cocoapods
if: env.turbo_cache_hit != 1
id: cocoapods-cache
uses: actions/cache@v3
path: ./*
key: ${{ github.sha }}

- name: Sonar scan
uses: ./.github/actions/sonar-scan
with:
path: |
**/ios/Pods
key: ${{ runner.os }}-cocoapods-${{ hashFiles('example/ios/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-cocoapods-
- name: Install cocoapods
if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
run: |
yarn example pods
env:
NO_FLIPPER: 1

- name: Build example for iOS
run: |
yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

# build-library:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v3

# - name: Setup
# uses: ./.github/actions/setup

# - name: Build package
# run: yarn prepack

# build-android:
# runs-on: ubuntu-latest
# env:
# TURBO_CACHE_DIR: .turbo/android
# steps:
# - name: Checkout
# uses: actions/checkout@v3

# - name: Setup
# uses: ./.github/actions/setup

# - name: Cache turborepo for Android
# uses: actions/cache@v3
# with:
# path: ${{ env.TURBO_CACHE_DIR }}
# key: ${{ runner.os }}-turborepo-android-${{ hashFiles('**/yarn.lock') }}
# restore-keys: |
# ${{ runner.os }}-turborepo-android-

# - name: Check turborepo cache for Android
# run: |
# TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")

# if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
# echo "turbo_cache_hit=1" >> $GITHUB_ENV
# fi

# - name: Install JDK
# if: env.turbo_cache_hit != 1
# uses: actions/setup-java@v3
# with:
# distribution: 'zulu'
# java-version: '11'

# - name: Finalize Android SDK
# if: env.turbo_cache_hit != 1
# run: |
# /bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"

# - name: Cache Gradle
# if: env.turbo_cache_hit != 1
# uses: actions/cache@v3
# with:
# path: |
# ~/.gradle/wrapper
# ~/.gradle/caches
# key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}
# restore-keys: |
# ${{ runner.os }}-gradle-

# - name: Build example for Android
# run: |
# yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"

# build-ios:
# runs-on: macos-latest
# env:
# TURBO_CACHE_DIR: .turbo/ios
# steps:
# - name: Checkout
# uses: actions/checkout@v3

# - name: Setup
# uses: ./.github/actions/setup

# - name: Cache turborepo for iOS
# uses: actions/cache@v3
# with:
# path: ${{ env.TURBO_CACHE_DIR }}
# key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('**/yarn.lock') }}
# restore-keys: |
# ${{ runner.os }}-turborepo-ios-

# - name: Check turborepo cache for iOS
# run: |
# TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")

# if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
# echo "turbo_cache_hit=1" >> $GITHUB_ENV
# fi

# - name: Cache cocoapods
# if: env.turbo_cache_hit != 1
# id: cocoapods-cache
# uses: actions/cache@v3
# with:
# path: |
# **/ios/Pods
# key: ${{ runner.os }}-cocoapods-${{ hashFiles('example/ios/Podfile.lock') }}
# restore-keys: |
# ${{ runner.os }}-cocoapods-

# - name: Install cocoapods
# if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
# run: |
# yarn example pods
# env:
# NO_FLIPPER: 1

# - name: Build example for iOS
# run: |
# yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,9 @@ android/keystores/debug.keystore

# generated by bob
lib/

# Test Coverage Results
coverage/

# Sonar-Scanner
.scannerwork/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"!**/.*"
],
"scripts": {
"test": "jest",
"test": "jest --forceExit --coverage --runInBand",
"typecheck": "tsc --noEmit",
"lint": "eslint \"**/*.{js,ts,tsx}\"",
"prepack": "bob build",
Expand Down
8 changes: 8 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sonar.projectKey=amity-social-UIKit-react-native-cli-opensource
sonar.organization=amityco
sonar.projectName=Amity Social Cloud: UIKit Ract Native CLI 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
3 changes: 3 additions & 0 deletions tests/000-always-pass.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test('Always Pass', () => {
expect(true).toBe(true);
});

0 comments on commit 6109770

Please sign in to comment.