Skip to content

Commit

Permalink
implement sonar report comment
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Aug 18, 2022
1 parent 8c6f6e4 commit 9f7b759
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
41 changes: 40 additions & 1 deletion .github/workflows/angular.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
github.event.action != 'closed' &&
!contains(github.event.pull_request.labels.*.name, 'pr: skip-ci') &&
needs.build-matrix.outputs.workflow-angular == 'true'
timeout-minutes: 40
timeout-minutes: 50
strategy:
fail-fast: false
# Matrix available at https://github.com/jhipster/generator-jhipster/tree/main/test-integration/workflow-samples/
Expand Down Expand Up @@ -215,6 +215,45 @@ jobs:
with:
name: screenshots-${{ matrix.name }}
path: ${{ steps.setup.outputs.application-path }}/**/cypress/screenshots
- name: 'ANALYSIS: Sonar PR'
id: sonar-result
if: steps.base-app.outcome == 'success' && matrix.name == 'ngx-default'
run: |
echo "::group::docker startup"
npm run docker:sonar:up
npm run docker:sonar:await
echo "::endgroup::"
echo "::group::base analisys"
cd ../base/app
./mvnw -ntp --batch-mode clean compile -Dskip.installnodenpm -Dskip.npm
./mvnw -ntp --batch-mode initialize sonar:sonar \
-Dsonar.projectVersion=0.0.0-base \
-Dsonar.testExecutionReportPaths=""
echo "::endgroup::"
echo "::group::merge analisys"
cd ../../app
./mvnw -ntp --batch-mode clean compile -Dskip.installnodenpm -Dskip.npm
npm run sonnar -Dsonar.projectVersion=0.0.0-base -Dsonar.testExecutionReportPaths=""
echo "::endgroup::"
echo "::group::report install"
npm install -g mshima/sonar-report
echo "::endgroup::"
sonar-report \
--exit-code \
--ejs-file summary.txt.ejs \
--save-report-json target/sonar_report.json \
--allbugs \
--since-leak-period \
--vulnerability-plural-phrase Issues \
--vulnerability-phrase Issue
echo "::group::json result"
cat target/sonar_report.json
echo "::endgroup::"
- name: Dump docker logs
if: always()
uses: jwalton/gh-docker-logs@v2
Expand Down
1 change: 0 additions & 1 deletion generators/common/templates/sonar-project.properties.ejs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
sonar.projectKey=<%= baseName %>
sonar.projectName=<%= baseName %> generated by jhipster
sonar.projectVersion=1.0

sonar.sources=<%= MAIN_DIR %>
sonar.host.url=http://localhost:9001
Expand Down
16 changes: 16 additions & 0 deletions generators/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,22 @@ module.exports = class JHipsterServerGenerator extends BaseBlueprintGenerator {
'ci:e2e:server:start': `java -jar ${e2ePackage}.$npm_package_config_packaging --spring.profiles.active=e2e,$npm_package_config_default_environment ${javaCommonLog} ${javaTestLog} --logging.level.org.springframework.web=ERROR`,
});
},
packageJsonSonar() {
if (this.buildToolMaven) {
this.packageJson.merge({
scripts: {
sonar: './mvnw -ntp --batch-mode initialize sonar:sonar',
},
});
}
this.packageJson.merge({
scripts: {
'docker:sonar:up': 'docker compose -f src/main/docker/sonar.yml up -d',
'docker:sonar:down': 'docker compose -f src/main/docker/sonar.yml down',
'docker:sonar:await': `echo "Waiting for sonar to start" && wait-on -t ${WAIT_TIMEOUT} http-get://localhost:9001/api/system/status && echo "sonar started"`,
},
});
},
packageJsonE2eScripts() {
const scriptsStorage = this.packageJson.createStorage('scripts');
const buildCmd = this.jhipsterConfig.buildTool === GRADLE ? 'gradlew' : 'mvnw';
Expand Down
2 changes: 2 additions & 0 deletions generators/server/templates/src/main/docker/sonar.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
version: '<%= DOCKER_COMPOSE_FORMAT_VERSION %>'
services:
<%= baseName.toLowerCase() %>-sonar:
# There is no arm64/apple silicon support
# It's possible to use an third party provider that provides arm64 support like mwizner/sonarqube:9.4.0-community
image: <%= DOCKER_SONAR %>
# Authentication is turned off for out of the box experience while trying out SonarQube
# For real use cases delete sonar.forceAuthentication variable or set sonar.forceAuthentication=true
Expand Down

0 comments on commit 9f7b759

Please sign in to comment.