Skip to content

Commit

Permalink
Merge pull request #831 from eclipse/sonar
Browse files Browse the repository at this point in the history
configure java tests and libraries
  • Loading branch information
amvanbaren authored Nov 16, 2023
2 parents efe09aa + ba8f051 commit f06a2b7
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 17 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ jobs:
run: docker build -t $WEBUI_TAG:$IMAGE_VERSION webui
- name: Run Server Tests
run: server/gradlew --no-daemon -p server check
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Build Server Image
run: docker build -t $SERVER_TAG:$IMAGE_VERSION server
- name: Push Docker Images
Expand Down
85 changes: 85 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Sonar
on:
workflow_run:
workflows: [CI]
types: [completed]
jobs:
sonar:
name: Sonar
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
steps:
- name: Download PR number artifact
if: github.event.workflow_run.event == 'pull_request'
uses: dawidd6/action-download-artifact@v2
with:
workflow: Build
run_id: ${{ github.event.workflow_run.id }}
name: PR_NUMBER
- name: Read PR_NUMBER.txt
if: github.event.workflow_run.event == 'pull_request'
id: pr_number
uses: juliangruber/read-file-action@v1
with:
path: ./PR_NUMBER.txt
- name: Request GitHub API for PR data
if: github.event.workflow_run.event == 'pull_request'
uses: octokit/[email protected]
id: get_pr_data
with:
route: GET /repos/{full_name}/pulls/{number}
number: ${{ steps.pr_number.outputs.content }}
full_name: ${{ github.event.repository.full_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v3
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0
- name: Checkout base branch
if: github.event.workflow_run.event == 'pull_request'
run: |
git remote add upstream ${{ github.event.repository.clone_url }}
git fetch upstream
git checkout -B ${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} upstream/${{ fromJson(steps.get_pr_data.outputs.data).base.ref }}
git checkout ${{ github.event.workflow_run.head_branch }}
git clean -ffdx && git reset --hard HEAD
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: List Files #TODO remove after debugging
run: ls -al
- name: Build Server
run: server/gradlew --no-daemon -p server build
- name: SonarCloud Scan on PR
if: github.event.workflow_run.event == 'pull_request'
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
-Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }}
-Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }}
-Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }}
- name: SonarCloud Scan on push
if: github.event.workflow_run.event == 'push' && github.event.workflow_run.head_repository.full_name == github.event.repository.full_name
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
-Dsonar.branch.name=${{ github.event.workflow_run.head_branch }}
9 changes: 0 additions & 9 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ buildscript {
}
}
plugins {
id "org.sonarqube" version "4.4.1.3373"
id 'nu.studer.jooq' version '8.2.1'
id 'de.undercouch.download' version '5.4.0'
id 'org.springframework.boot' version '3.1.0'
Expand Down Expand Up @@ -124,14 +123,6 @@ dependencies {
gatling "io.gatling:gatling-app:${versions.gatling}"
}

sonar {
properties {
property "sonar.projectKey", "open-vsx_openvsx"
property "sonar.organization", "open-vsx"
property "sonar.host.url", "https://sonarcloud.io"
}
}

jooq {
// use jOOQ version defined in Spring Boot
version = dependencyManagement.importedProperties['jooq.version']
Expand Down
7 changes: 4 additions & 3 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
sonar.projectKey=open-vsx_openvsx
sonar.organization=open-vsx
sonar.sources=cli,webui,server/scripts,server/Dockerfile,server/src/dev,server/src/gatling,server/src/main/java,server/src/main/resources,.gitpod.dockerfile,.gitpod.yml
sonar.tests=server/src/test
sonar.java.binaries=server/build/classes/java/main
sonar.java.libraries=.gradle/caches
sonar.java.test.binaries=server/build/classes/java/test
sonar.java.test.libraries=.gradle/caches

# This is the name and version displayed in the SonarCloud UI.
#sonar.projectName=openvsx
#sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
#sonar.sources=.

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

0 comments on commit f06a2b7

Please sign in to comment.