diff --git a/.github/workflows/gradlew-sonar-analysis.yml b/.github/workflows/gradlew-sonar-analysis.yml index 5a6f2fbb..10274722 100644 --- a/.github/workflows/gradlew-sonar-analysis.yml +++ b/.github/workflows/gradlew-sonar-analysis.yml @@ -1,4 +1,5 @@ name: Sonar Analysis via Gradlew + on: workflow_call: inputs: @@ -6,40 +7,25 @@ on: 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: 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: @@ -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: @@ -64,14 +46,6 @@ 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: @@ -79,17 +53,14 @@ jobs: 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;"; exit 1; fi if [[ -z $SONAR_URL ]]; then @@ -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 }} - # - 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.