Skip to content

Commit

Permalink
Enable SonarQube actions to download reports from the default workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
chudilka1 authored Oct 16, 2024
1 parent 5f5ebd5 commit 3d0601b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 50 deletions.
8 changes: 8 additions & 0 deletions .changeset/forty-ears-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"ci-sonarqube-go": minor
"ci-sonarqube-ts": minor
---

Let SonarQube actions to fetch reports from a default workflow (the workflow the
action is specified) if names of the workflows that produce reports are not
mentioned
6 changes: 4 additions & 2 deletions actions/ci-sonarqube-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ sonarqube:
with:
# sonarqube inputs
include-lint: "true"
test-report-workflow: "ci-core.yaml"
lint-report-workflow: "golingci-lint.yaml"
# if workflow names are not used, artifacts will be downloaded
# from a workflow this action is added to
test-report-workflow: "ci-core.yaml" # optional
lint-report-workflow: "golingci-lint.yaml" # optional
sonar-token: ${{ secrets.SONAR_TOKEN }}
sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
```
34 changes: 8 additions & 26 deletions actions/ci-sonarqube-go/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ inputs:
description: "sonarqube host url"
required: false
test-report-workflow:
description:
"workflow file name which uploaded test report artifacts [i.e.
ci-core.yaml]"
required: true
default: ${{ github.run_id }}
description: "workflow file name which uploaded test report artifacts"
required: false
test-report-artifact:
description: "Name of artifact containing junit test and coverage results"
required: false
Expand All @@ -37,11 +34,8 @@ inputs:
requried: false
default: "coverage.txt"
lint-report-workflow:
description:
"workflow file name which uploaded lint report artifacts [i.e.
golangci-lint.yaml]"
required: true
default: ${{ github.run_id }}
description: "workflow file name which uploaded lint report artifacts"
required: false
lint-report-artifact:
description: "Name of artifact containing golangci-lint report"
requried: false
Expand All @@ -64,6 +58,10 @@ 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 == ''
uses: actions/download-artifact@v4.1.8 # v4.1.8

- name: Download test-report artifact using workflow file name
if: inputs.test-report-workflow != ''
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6
Expand All @@ -73,14 +71,6 @@ runs:
workflow_conclusion: "" # ignore workflow status to let the latest artifact be downloaded
if_no_artifact_found: warn

- name: Download test-report artifact from current workflow
if: inputs.test-report-workflow == ''
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6
with:
name: ${{ inputs.test-report-artifact }}
workflow_conclusion: ""
if_no_artifact_found: warn

- name: Download lint-report artifact using workflow file name
if: inputs.lint-report-workflow != ''
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6
Expand All @@ -90,14 +80,6 @@ runs:
workflow_conclusion: ""
if_no_artifact_found: warn

- name: Download lint-report artifact from current workflow
if: inputs.lint-report-workflow == ''
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6
with:
name: ${{ inputs.lint-report-artifact }}
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
Expand Down
6 changes: 4 additions & 2 deletions actions/ci-sonarqube-ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ sonarqube:
with:
# sonarqube inputs
include-lint: "true"
test-report-workflow: "ci-core.yaml"
lint-report-workflow: "ts-lint.yaml"
# if workflow names are not used, artifacts will be downloaded
# from a workflow this action is added to
test-report-workflow: "ci-core.yaml" # optional
lint-report-workflow: "ts-lint.yaml" # optional
sonar-token: ${{ secrets.SONAR_TOKEN }}
sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
```
26 changes: 6 additions & 20 deletions actions/ci-sonarqube-ts/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ inputs:
required: false
test-report-workflow:
description: "workflow file name which uploaded test report artifacts"
required: true
default: ${{ github.run_id }}
required: false
test-report-artifact:
description: "Name of artifact containing junit test and coverage results"
required: false
Expand All @@ -36,8 +35,7 @@ inputs:
default: "lcov.info"
lint-report-workflow:
description: "workflow file name which uploaded lint report artifacts"
required: true
default: ${{ github.run_id }}
required: false
lint-report-artifact:
description: "Name of artifact containing eslint report"
requried: false
Expand All @@ -60,6 +58,10 @@ 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 == ''
uses: actions/download-artifact@v4.1.8 # v4.1.8

- name: Download test-report artifact using workflow file name
if: inputs.test-report-workflow != ''
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6
Expand All @@ -69,14 +71,6 @@ runs:
workflow_conclusion: "" # ignore workflow status to let the latest artifact be downloaded
if_no_artifact_found: warn

- name: Download test-report artifact from current workflow
if: inputs.test-report-workflow == ''
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6
with:
name: ${{ inputs.test-report-artifact }}
workflow_conclusion: ""
if_no_artifact_found: warn

- name: Download lint-report artifact using workflow file name
if: inputs.lint-report-workflow != ''
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6
Expand All @@ -86,14 +80,6 @@ runs:
workflow_conclusion: ""
if_no_artifact_found: warn

- name: Download lint-report artifact from current workflow
if: inputs.lint-report-workflow == ''
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6
with:
name: ${{ inputs.lint-report-artifact }}
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
Expand Down

0 comments on commit 3d0601b

Please sign in to comment.