Skip to content

SonarCloud scan

SonarCloud scan #790

#
# Copyright (c) 2019 Broadcom.
# The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Broadcom, Inc. - initial API and implementation
#
name: SonarCloud scan
on:
workflow_run:
workflows: ["SonarCloud build"]
types:
- completed
defaults:
run:
shell: sh
jobs:
sonar:
name: SonarCloud scan
runs-on: ubuntu-24.04
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: 'Download build output'
uses: actions/github-script@v7
with:
script: |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "bw-output"
})[0];
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{ runner.temp }}/bw-artifact.zip', Buffer.from(download.data));
- name: Get PR info
run: |
unzip ${{ runner.temp }}/bw-artifact.zip 'pr-info/*'
echo "REF=$(cat pr-info/ref.txt)" >> $GITHUB_ENV
echo "HEAD_BRANCH_ARG=$(cat pr-info/head-branch-arg.txt)" >> $GITHUB_ENV
echo "PR_NUMBER_ARG=$(cat pr-info/pr-number-arg.txt)" >> $GITHUB_ENV
- uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
ref: ${{ env.REF }}
- name: Get version
run: echo "VERSION=$(node -e "console.log(require('./clients/vscode-hlasmplugin/package.json').version)")" >> $GITHUB_ENV
- run: unzip ${{ runner.temp }}/bw-artifact.zip
- name: Download Sonar
env:
SONAR_SCANNER_VERSION: 5.0.1.3006
run: |
curl -sSLo sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
unzip sonar-scanner.zip
mv sonar-scanner-$SONAR_SCANNER_VERSION-linux sonar-scanner-linux
working-directory: ${{ runner.temp }}
- name: Sonar scan
env:
SONAR_SCANNER_OPTS: -server
run: >
$RUNNER_TEMP/sonar-scanner-linux/bin/sonar-scanner
-Dsonar.projectKey=$(echo "$GITHUB_REPOSITORY" | tr "/" "_")
-Dsonar.organization=$(echo "$GITHUB_REPOSITORY_OWNER" | tr "[:upper:]" "[:lower:]")
-Dsonar.sources=benchmark,clients/vscode-hlasmplugin/src/,language_server/src,parser_library/src,parser_library/include,utils/src,utils/include
-Dsonar.tests=parser_library/test,language_server/test,clients/vscode-hlasmplugin/src/test,utils/test
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.token=${{ secrets.SONAR_TOKEN }}
-Dsonar.cfamily.build-wrapper-output=build/bw-output
-Dsonar.cfamily.llvm-cov.reportPath=build/coverage.txt
-Dsonar.javascript.lcov.reportPaths=clients/vscode-hlasmplugin/coverage/lcov.info
-Dsonar.projectVersion=$VERSION
-Dsonar.cpd.exclusions=parser_library/src/context/instruction.cpp
-Dsonar.exclusions=clients/vscode-hlasmplugin/src/test/**
-Dsonar.test.inclusions=clients/vscode-hlasmplugin/src/test/**
-Dsonar.coverage.exclusions=benchmark/benchmark.cpp,**/*.web.ts
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
$HEAD_BRANCH_ARG
$PR_NUMBER_ARG