Skip to content

Commit

Permalink
Add ability to set multiple paths to reports in SonarQube action
Browse files Browse the repository at this point in the history
  • Loading branch information
chudilka1 authored Oct 21, 2024
1 parent f1f2dac commit 5f4a9c9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 64 deletions.
6 changes: 6 additions & 0 deletions .changeset/tender-kids-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"ci-sonarqube-go": minor
"ci-sonarqube-ts": minor
---

Enable SonarQube actions to set multiple paths to reports
61 changes: 26 additions & 35 deletions actions/ci-sonarqube-go/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ inputs:
test-report-artifact:
description: "Name of artifact containing junit test and coverage results"
required: false
default: "go-test-results"
test-result-report-path:
description: "paths to Go test results in txt format"
requried: false
default: "output.txt"
test-coverage-report-path:
description: "paths to Go test coverage report in txt format"
default: go-test-results
test-report-name:
description: "Go coverage report name with extension"
requried: false
default: "coverage.txt"
lint-report-workflow:
Expand All @@ -39,9 +35,9 @@ inputs:
lint-report-artifact:
description: "Name of artifact containing golangci-lint report"
requried: false
default: "golangci-lint-report"
lint-report-path:
description: "paths to golangci-lint report in xml format"
default: golangci-lint-report
lint-report-name:
description: "Golangci-lint report name with extension"
requried: false
default: "golangci-lint-report.xml"
include-lint:
Expand All @@ -58,8 +54,13 @@ runs:
with:
fetch-depth: ${{ inputs.checkout-repo-fetch-depth }}

- name: Download all reports (no report-workflow name is specified)
if: inputs.test-report-workflow == '' || inputs.lint-report-workflow == ''
- name: Download all reports (no test-report-workflow)
id: all
if: inputs.test-report-workflow == ''
uses: actions/download-artifact@v4.1.8 # v4.1.8

- name: Download all reports (no lint-report-workflow)
if: steps.all.outcome != 'success' && inputs.lint-report-workflow == ''
uses: actions/download-artifact@v4.1.8 # v4.1.8

- name: Download test-report artifact using workflow file name
Expand All @@ -68,6 +69,7 @@ runs:
with:
workflow: ${{ inputs.test-report-workflow }}
name: ${{ inputs.test-report-artifact }}
search_artifacts: true
workflow_conclusion: "" # ignore workflow status to let the latest artifact be downloaded
if_no_artifact_found: warn

Expand All @@ -77,35 +79,24 @@ runs:
with:
workflow: ${{ inputs.lint-report-workflow }}
name: ${{ inputs.lint-report-artifact }}
search_artifacts: true
workflow_conclusion: ""
if_no_artifact_found: warn

- name: SonarQube scan without lint
if: inputs.include-lint == 'false'
uses: sonarsource/sonarqube-scan-action@aecaf43ae57e412bd97d70ef9ce6076e672fe0a9 # v2.3.0
with:
args: >
-Dsonar.go.tests.reportPaths=${{
inputs.test-result-report-path
}} -Dsonar.go.coverage.reportPaths=${{
inputs.test-coverage-report-path
}}
env:
SONAR_TOKEN: ${{ inputs.sonar-token }}
SONAR_HOST_URL: ${{ inputs.sonar-host-url }}
- name: Set SonarQube Report Paths
shell: bash
run: |
sonarqube_coverage_report_paths=$(find -type f -name '${{ inputs.test-report-name }}' -printf "%p,")
sonarqube_golangci_report_paths=$(find -type f -name '${{ inputs.lint-report-name }}' -printf "%p,")
ARGS=""
ARGS="$ARGS -Dsonar.go.coverage.reportPaths=$sonarqube_coverage_report_paths"
ARGS="$ARGS -Dsonar.go.golangci-lint.reportPaths=$sonarqube_golangci_report_paths"
echo "SONARQUBE_ARGS=$ARGS" >> $GITHUB_ENV
- name: SonarQube scan with lint
if: inputs.include-lint == 'true'
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@aecaf43ae57e412bd97d70ef9ce6076e672fe0a9 # v2.3.0
with:
args: >
-Dsonar.go.tests.reportPaths=${{
inputs.test-result-report-path
}} -Dsonar.go.coverage.reportPaths=${{
inputs.test-coverage-report-path
}} -Dsonar.go.golangci-lint.reportPaths=${{
inputs.lint-report-path
}}
args: ${{ env.SONARQUBE_ARGS }}
env:
SONAR_TOKEN: ${{ inputs.sonar-token }}
SONAR_HOST_URL: ${{ inputs.sonar-host-url }}
65 changes: 36 additions & 29 deletions actions/ci-sonarqube-ts/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ inputs:
description: "paths to junit test results in xml format"
requried: false
default: "junit.xml"
typescript-lcov-report-path:
description: "paths to lcov test coverage report in lcov format"
typescript-lcov-report-name:
description: "lcov test coverage report name with extension"
requried: false
default: "lcov.info"
lint-report-workflow:
Expand All @@ -40,8 +40,8 @@ inputs:
description: "Name of artifact containing eslint report"
requried: false
default: "ts-lint-results"
eslint-json-report-path:
description: "paths to eslint report in json format"
eslint-json-report:
description: "Eslint report name in json format"
requried: false
default: "eslint-report.json"
include-lint:
Expand All @@ -58,8 +58,13 @@ runs:
with:
fetch-depth: ${{ inputs.checkout-repo-fetch-depth }}

- name: Download all reports (no report-workflow name is specified)
if: inputs.test-report-workflow == '' || inputs.lint-report-workflow == ''
- name: Download all reports (no test-report-workflow)
id: all
if: inputs.test-report-workflow == ''
uses: actions/download-artifact@v4.1.8 # v4.1.8

- name: Download all reports (no lint-report-workflow)
if: steps.all.outcome != 'success' && inputs.lint-report-workflow == ''
uses: actions/download-artifact@v4.1.8 # v4.1.8

- name: Download test-report artifact using workflow file name
Expand All @@ -68,6 +73,7 @@ runs:
with:
workflow: ${{ inputs.test-report-workflow }}
name: ${{ inputs.test-report-artifact }}
search_artifacts: true
workflow_conclusion: "" # ignore workflow status to let the latest artifact be downloaded
if_no_artifact_found: warn

Expand All @@ -77,35 +83,36 @@ runs:
with:
workflow: ${{ inputs.lint-report-workflow }}
name: ${{ inputs.lint-report-artifact }}
search_artifacts: true
workflow_conclusion: ""
if_no_artifact_found: warn

- name: SonarQube scan without lint
if: inputs.include-lint == 'false'
uses: sonarsource/sonarqube-scan-action@aecaf43ae57e412bd97d70ef9ce6076e672fe0a9 # v2.3.0
with:
args: >
-Dsonar.junit.reportPaths=${{
inputs.junit-xml-report-path
}} -Dsonar.typescript.lcov.reportPaths=${{
inputs.typescript-lcov-report-path
}}
env:
SONAR_TOKEN: ${{ inputs.sonar-token }}
SONAR_HOST_URL: ${{ inputs.sonar-host-url }}
- name: Set SonarQube Report Paths
id: sonarqube_report_paths
shell: bash
run: |
sonarqube_coverage_report_paths=$(find -type f -name '*${{ inputs.typescript-lcov-report-name }}' -printf "%p,")
echo "sonarqube_coverage_report_paths=$sonarqube_coverage_report_paths"
sonarqube_lint_report_paths=$(find -type f -name '*${{ inputs.eslint-json-report }}' -printf "%p,") >> GITHUB_OUTPUT
echo "sonarqube_lint_report_paths=$sonarqube_lint_report_paths"
ARGS=""
ARGS="$ARGS -Dsonar.typescript.lcov.reportPaths=$sonarqube_coverage_report_paths"
ARGS="$ARGS -Dsonar.eslint.reportPaths=$sonarqube_lint_report_paths"
echo "Final SONARQUBE_ARGS: $ARGS"
echo "SONARQUBE_ARGS=$ARGS" >> $GITHUB_ENV
- name: Update ESLint report symlinks
continue-on-error: true
shell: bash
run:
sed -i 's+/home/runner/work/${{ github.event.repository.name }}/${{
github.event.repository.name }}/+/github/workspace/+g' ${{
steps.sonarqube_report_paths.outputs.sonarqube_lint_report_paths }}

- name: SonarQube scan with lint
if: inputs.include-lint == 'true'
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@aecaf43ae57e412bd97d70ef9ce6076e672fe0a9 # v2.3.0
with:
args: >
-Dsonar.junit.reportPaths=${{
inputs.junit-xml-report-path
}} -Dsonar.typescript.lcov.reportPaths=${{
inputs.typescript-lcov-report-path
}} -Dsonar.eslint.reportPaths=${{
inputs.eslint-json-report-path
}}
args: ${{ env.SONARQUBE_ARGS }}
env:
SONAR_TOKEN: ${{ inputs.sonar-token }}
SONAR_HOST_URL: ${{ inputs.sonar-host-url }}

0 comments on commit 5f4a9c9

Please sign in to comment.