Sonar #703
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sonar | |
on: | |
workflow_run: | |
workflows: ["Java CI with Gradle - mainidewindow.idestatusbar, screenshot"] | |
types: | |
- completed | |
jobs: | |
build: | |
name: Sonar | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
ref: ${{github.event.workflow_run.head_sha}} | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 11 | |
- name: Download artifacts | |
uses: actions/[email protected] | |
with: | |
script: | | |
var artifacts = await github.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{github.event.workflow_run.id}}, | |
}); | |
for (var artifact of artifacts.data.artifacts) { | |
if (artifact.name == 'linux-integration-test-reports' || artifact.name == 'ubuntu-latest-test-reports' || artifact.name == 'prInfo') { | |
var zipfile = await github.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: artifact.id, | |
archive_format: 'zip', | |
}); | |
var fs = require('fs'); | |
var path = require('path'); | |
var pathFile = path.format({ | |
root: '${{github.workspace}}/', | |
name: artifact.name, | |
ext: '.zip' | |
}); | |
fs.writeFileSync(pathFile, Buffer.from(zipfile.data)); | |
} | |
} | |
- name: Unzip artifacts | |
run: | | |
find . -name '*.zip' -exec sh -c 'unzip -d "${{github.workspace}}/build" "$1"' _ {} \; | |
- name: Run Sonar analysis | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: | | |
if [ '${{github.event.workflow_run.event}}' == 'pull_request' ]; then | |
PR_NUMBER=$(<build/PR) | |
BASE_REF=$(<build/base_ref) | |
HEAD_REF=$(<build/head_ref) | |
./gradlew sonarqube -Dsonar.pullrequest.base=$BASE_REF -Dsonar.pullrequest.branch=$HEAD_REF -Dsonar.pullrequest.key=$PR_NUMBER -Dsonar.pullrequest.provider=GitHub -Dsonar.pullrequest.github.repository=${{github.repository}} | |
else | |
./gradlew sonarqube | |
fi | |
shell: bash | |