Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 19 additions & 43 deletions .github/workflows/gradlew-sonar-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,31 @@
name: Sonar Analysis via Gradlew

on:
workflow_call:
inputs:
SERVICE_LOCATION:
description: 'SERVICE LOCATION'
required: true
type: string
ANDROID_LOCATION:
description: 'ANDROID LOCATION'
required: true
type: string
SONAR_URL:
required: false
type: string
default: 'https://sonarcloud.io'
PROJECT_KEY:
required: false
type: string
default: "mosip_${{ github.event.repository.name }}"
PROJECT_NAME:
required: false
type: string
default: "${{ github.event.repository.name }}"
SONAR_ARGS:
required: false
type: string
default: ""

secrets:
SONAR_TOKEN:
required: true
SONAR_ORGANIZATION:
ORG_KEY:
Comment thread
Mahesh-Binayak marked this conversation as resolved.
required: true
SLACK_WEBHOOK_URL:
required: true

env:
ANDROID_HOME: '/opt/android-sdk/'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_ORGANIZATION: ${{ secrets.SONAR_ORGANIZATION }}
SONAR_URL: ${{ inputs.SONAR_URL }}

jobs:
Expand All @@ -51,10 +37,6 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- uses: actions/setup-node@v3.7.0
with:
node-version: '16'

- name: Cache Gradle packages
uses: actions/cache@v4
with:
Expand All @@ -64,32 +46,21 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle-

- name: Cache npm dependencies
uses: actions/cache@v4
with:
path: '~/.npm'
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-

- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-sonar-

- name: NPM Install Dependencies
run: cd ${{ inputs.SERVICE_LOCATION }} && npm install

- name: Check if Environmental variables set for sonar
run: |
run: |
if [[ -z $SONAR_TOKEN ]]; then
echo "\$SONAR_TOKEN environmental variable not set; EXITING;";
exit 1;
fi
if [[ -z $SONAR_ORGANIZATION ]]; then
echo "\$SONAR_ORGANIZATION environmental variable not set; EXITING;";
if [[ -z ${{ secrets.ORG_KEY }} ]]; then
echo "\$ORG_KEY secret not set; EXITING;";
Comment thread
coderabbitai[bot] marked this conversation as resolved.
exit 1;
fi
if [[ -z $SONAR_URL ]]; then
Expand All @@ -99,15 +70,20 @@ jobs:

- name: Analysis with Sonarcloud
run: |
cd ${{ inputs.SERVICE_LOCATION }}/${{ inputs.ANDROID_LOCATION }}
cd ${{ inputs.SERVICE_LOCATION }}
sed -i -e 's/\r$//' ./gradlew
chmod +x ./gradlew
./gradlew build sonarqube -Dsonar.organization=${{ env.SONAR_ORGANIZATION }} -Dsonar.projectKey=${{ inputs.PROJECT_KEY }} -Dsonar.projectName=${{ inputs.PROJECT_NAME }} -Dsonar.host.url=${{ inputs.SONAR_URL }} --info --warning-mode all ${{ inputs.SONAR_ARGS }}
./gradlew build sonarqube \
-Dsonar.organization=${{ secrets.ORG_KEY }} \
-Dsonar.projectKey=${{ secrets.ORG_KEY }}_${{ github.event.repository.name }} \
-Dsonar.projectName=${{ github.event.repository.name }} \
-Dsonar.host.url=${{ inputs.SONAR_URL }} \
--info --warning-mode all ${{ inputs.SONAR_ARGS }}
Comment thread
Mahesh-Binayak marked this conversation as resolved.

# - uses: 8398a7/action-slack@v3
# with:
# status: ${{ job.status }}
# fields: repo,message,author,commit,workflow,job # selectable (default: repo,message)
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
# if: "${{ github.event_name != 'pull_request' && failure() }}" # Pick up events even if the job fails or is canceled.
#- uses: 8398a7/action-slack@v3
# with:
# status: ${{ job.status }}
# fields: repo,message,author,commit,workflow,job # selectable (default: repo,message)
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
# if: "${{ github.event_name != 'pull_request' && failure() }}" # Pick up events even if the job fails or is canceled.