Skip to content

Commit 55621d2

Browse files
[deps]: Update sonarsource/sonarqube-scan-action action to v6 (#449)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Matt Andreko <mandreko@bitwarden.com>
1 parent f9668b7 commit 55621d2

File tree

1 file changed

+69
-27
lines changed

1 file changed

+69
-27
lines changed

.github/workflows/_sonar.yml

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
with:
4141
fetch-depth: 0
4242
ref: ${{ github.event.pull_request.head.sha }}
43+
persist-credentials: false
4344

4445
- name: Log in to Azure
4546
uses: bitwarden/gh-actions/azure-login@main
@@ -60,18 +61,18 @@ jobs:
6061

6162
- name: Scan with Sonar
6263
if: inputs.sonar-config == 'default'
63-
uses: sonarsource/sonarqube-scan-action@1a6d90ebcb0e6a6b1d87e37ba693fe453195ae25 # v5.3.1
64+
uses: sonarsource/sonarqube-scan-action@fd88b7d7ccbaefd23d8f36f73b59db7a3d246602 # v6.0.0
6465
env:
6566
SONAR_TOKEN: ${{ steps.get-kv-secrets.outputs.SONAR-TOKEN }}
6667
with:
6768
args: >
68-
-Dsonar.organization=${{ github.repository_owner }}
69-
-Dsonar.projectKey=${{ github.repository_owner }}_${{ github.event.repository.name }}
70-
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
71-
${{ inputs.sonar-test-inclusions != '' && format('-Dsonar.test.inclusions={0}', inputs.sonar-test-inclusions) || '' }}
72-
${{ inputs.sonar-exclusions != '' && format('-Dsonar.exclusions={0}', inputs.sonar-exclusions) || '' }}
73-
${{ inputs.sonar-sources != '' && format('-Dsonar.sources={0}', inputs.sonar-sources) || '' }}
74-
${{ inputs.sonar-tests != '' && format('-Dsonar.tests={0}', inputs.sonar-tests) || '' }}
69+
"-Dsonar.organization=${{ github.repository_owner }}"
70+
"-Dsonar.projectKey=${{ github.repository_owner }}_${{ github.event.repository.name }}"
71+
"-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}"
72+
${{ inputs.sonar-test-inclusions != '' && format('"-Dsonar.test.inclusions={0}"', inputs.sonar-test-inclusions) || '' }}
73+
${{ inputs.sonar-exclusions != '' && format('"-Dsonar.exclusions={0}"', inputs.sonar-exclusions) || '' }}
74+
${{ inputs.sonar-sources != '' && format('"-Dsonar.sources={0}"', inputs.sonar-sources) || '' }}
75+
${{ inputs.sonar-tests != '' && format('"-Dsonar.tests={0}"', inputs.sonar-tests) || '' }}
7576
7677
- name: Set up Java
7778
if: inputs.sonar-config == 'maven' || inputs.sonar-config == 'dotnet'
@@ -91,28 +92,69 @@ jobs:
9192
- name: Scan with Sonar
9293
if: inputs.sonar-config == 'dotnet'
9394
env:
94-
SONAR_TOKEN: ${{ steps.get-kv-secrets.outputs.SONAR-TOKEN }}
95+
_SONAR_TOKEN: ${{ steps.get-kv-secrets.outputs.SONAR-TOKEN }}
96+
_REPOSITORY_NAME: ${{ github.event.repository.name }}
97+
_REPOSITORY_OWNER: ${{ github.repository_owner }}
98+
_SONAR_TEST_INCLUSIONS: ${{ inputs.sonar-test-inclusions }}
99+
_SONAR_EXCLUSIONS: ${{ inputs.sonar-exclusions }}
100+
_SONAR_SOURCES: ${{ inputs.sonar-sources }}
101+
_SONAR_TESTS: ${{ inputs.sonar-tests }}
102+
_PULL_REQUEST_KEY: ${{ github.event_name == 'pull_request' && github.event.pull_request.number || '' }}
95103
run: |
96-
dotnet-sonarscanner begin /k:"${{ github.repository_owner }}_${{ github.event.repository.name }}" \
97-
/o:"${{ github.repository_owner }}" \
98-
/d:sonar.token="${{ steps.get-kv-secrets.outputs.SONAR-TOKEN }}" \
99-
/d:sonar.host.url="https://sonarcloud.io" \
100-
${{ contains(github.event_name, 'pull_request') && format('/d:sonar.pullrequest.key={0}', github.event.pull_request.number) || '' }} \
101-
${{ inputs.sonar-test-inclusions != '' && format('/d:sonar.test.inclusions={0}', inputs.sonar-test-inclusions) || '' }} \
102-
${{ inputs.sonar-exclusions != '' && format('/d:sonar.exclusions={0}', inputs.sonar-exclusions) || '' }} \
103-
${{ inputs.sonar-sources != '' && format('-Dsonar.sources={0}', inputs.sonar-sources) || '' }} \
104-
${{ inputs.sonar-tests != '' && format('-Dsonar.tests={0}', inputs.sonar-tests) || '' }}
104+
set -euo pipefail
105+
ARGS=()
106+
if [ -n "$_PULL_REQUEST_KEY" ]; then
107+
ARGS+=("/d:sonar.pullrequest.key=$_PULL_REQUEST_KEY")
108+
fi
109+
if [ -n "$_SONAR_TEST_INCLUSIONS" ]; then
110+
ARGS+=("/d:sonar.test.inclusions=$_SONAR_TEST_INCLUSIONS")
111+
fi
112+
if [ -n "$_SONAR_EXCLUSIONS" ]; then
113+
ARGS+=("/d:sonar.exclusions=$_SONAR_EXCLUSIONS")
114+
fi
115+
if [ -n "$_SONAR_SOURCES" ]; then
116+
ARGS+=("-Dsonar.sources=$_SONAR_SOURCES")
117+
fi
118+
if [ -n "$_SONAR_TESTS" ]; then
119+
ARGS+=("-Dsonar.tests=$_SONAR_TESTS")
120+
fi
121+
122+
dotnet-sonarscanner begin \
123+
/k:"${REPOSITORY_OWNER}_${REPOSITORY_NAME}" \
124+
/o:"$REPOSITORY_OWNER" \
125+
/d:sonar.token="$SONAR_TOKEN" \
126+
/d:sonar.host.url="https://sonarcloud.io" \
127+
"${ARGS[@]}"
105128
dotnet build
106-
dotnet-sonarscanner end /d:sonar.token="${{ steps.get-kv-secrets.outputs.SONAR-TOKEN }}"
129+
dotnet-sonarscanner end /d:sonar.token="$_SONAR_TOKEN"
107130
108131
- name: Scan with Sonar
109132
if: inputs.sonar-config == 'maven'
110133
env:
111-
SONAR_TOKEN: ${{ steps.get-kv-secrets.outputs.SONAR-TOKEN }}
112-
run: >
113-
mvn clean install -Dgpg.skip=true sonar:sonar
114-
${{ inputs.sonar-test-inclusions != '' && format('-Dsonar.test.inclusions={0}', inputs.sonar-test-inclusions) || '' }}
115-
${{ inputs.sonar-exclusions != '' && format('-Dsonar.exclusions={0}', inputs.sonar-exclusions) || '' }}
116-
${{ inputs.sonar-sources != '' && format('-Dsonar.sources={0}', inputs.sonar-sources) || '' }}
117-
${{ inputs.sonar-tests != '' && format('-Dsonar.tests={0}', inputs.sonar-tests) || '' }}
118-
${{ contains(github.event_name, 'pull_request') && format('-Dsonar.pullrequest.key={0}', github.event.pull_request.number) || '' }}
134+
_SONAR_TOKEN: ${{ steps.get-kv-secrets.outputs.SONAR-TOKEN }}
135+
_SONAR_TEST_INCLUSIONS: ${{ inputs.sonar-test-inclusions }}
136+
_SONAR_EXCLUSIONS: ${{ inputs.sonar-exclusions }}
137+
_SONAR_SOURCES: ${{ inputs.sonar-sources }}
138+
_SONAR_TESTS: ${{ inputs.sonar-tests }}
139+
_PULL_REQUEST_KEY: ${{ github.event_name == 'pull_request' && github.event.pull_request.number || '' }}
140+
run: |
141+
set -euo pipefail
142+
ARGS=()
143+
144+
if [ -n "$_SONAR_TEST_INCLUSIONS" ]; then
145+
ARGS+=("-Dsonar.test.inclusions=$_SONAR_TEST_INCLUSIONS")
146+
fi
147+
if [ -n "$_SONAR_EXCLUSIONS" ]; then
148+
ARGS+=("-Dsonar.exclusions=$_SONAR_EXCLUSIONS")
149+
fi
150+
if [ -n "$_SONAR_SOURCES" ]; then
151+
ARGS+=("-Dsonar.sources=$_SONAR_SOURCES")
152+
fi
153+
if [ -n "$_SONAR_TESTS" ]; then
154+
ARGS+=("-Dsonar.tests=$_SONAR_TESTS")
155+
fi
156+
if [ -n "$_PULL_REQUEST_KEY" ]; then
157+
ARGS+=("-Dsonar.pullrequest.key=$_PULL_REQUEST_KEY")
158+
fi
159+
160+
mvn clean install -Dgpg.skip=true sonar:sonar "${ARGS[@]}"

0 commit comments

Comments
 (0)