Skip to content

Commit 96e35af

Browse files
committed
SQSCANGHA-51 Make Scanner CLI binaries URL customizable
1 parent 94d4f8a commit 96e35af

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

.github/workflows/qa.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,55 @@ jobs:
6868
- name: Assert
6969
run: |
7070
./test/assertFileContains ./output.properties "sonar.projectBaseDir=.*/baseDir"
71+
scannerVersionTest:
72+
name: >
73+
'scannerVersion' input
74+
runs-on: ubuntu-latest # assumes default RUNNER_ARCH for linux is X64
75+
steps:
76+
- uses: actions/checkout@v4
77+
with:
78+
token: ${{ secrets.GITHUB_TOKEN }}
79+
- name: Run action with scannerVersion
80+
uses: ./
81+
with:
82+
scannerVersion: 6.1.0.4477
83+
args: -Dsonar.scanner.internal.dumpToFile=./output.properties
84+
env:
85+
NO_CACHE: true # force install-sonar-scanner-cli.sh execution
86+
SONAR_HOST_URL: http://not_actually_used
87+
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
88+
- name: Assert
89+
run: |
90+
./test/assertFileExists "$RUNNER_TEMP/sonarscanner/sonar-scanner-cli-6.1.0.4477-linux-x64.zip"
91+
scannerBinariesUrlTest:
92+
name: >
93+
'scannerBinariesUrl' input with invalid URL
94+
runs-on: ubuntu-latest # assumes default RUNNER_ARCH for linux is X64
95+
steps:
96+
- uses: actions/checkout@v4
97+
with:
98+
token: ${{ secrets.GITHUB_TOKEN }}
99+
- name: Run action with scannerBinariesUrl
100+
id: runTest
101+
uses: ./
102+
continue-on-error: true
103+
with:
104+
scannerVersion: 6.2.1.4610
105+
scannerBinariesUrl: https://invalid_uri/Distribution/sonar-scanner-cli
106+
env:
107+
NO_CACHE: true # force install-sonar-scanner-cli.sh execution
108+
SONAR_HOST_URL: http://not_actually_used
109+
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
110+
- name: Fail if action succeeded
111+
if: steps.runTest.outcome == 'success'
112+
run: exit 1
113+
- name: Assert Sonar Scanner CLI was not downloaded
114+
run: |
115+
ls .
116+
./test/assertFileDoesntExist "$RUNNER_TEMP/sonarscanner/sonar-scanner-cli-6.2.1.4610-linux-x64.zip"
117+
- name: Assert Sonar Scanner CLI was not executed
118+
run: |
119+
./test/assertFileDoesntExist ./output.properties
71120
dontFailGradleTest:
72121
name: >
73122
Don't fail on Gradle project

action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ inputs:
1515
description: Version of the Sonar Scanner CLI to use
1616
required: false
1717
default: 6.2.1.4610
18+
scannerBinariesUrl:
19+
description: URL to download the Sonar Scanner CLI binaries from
20+
required: false
21+
default: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli
1822
runs:
1923
using: "composite"
2024
steps:
@@ -30,11 +34,12 @@ runs:
3034
path: ${{ runner.temp }}/sonar-scanner-cli-${{ inputs.scannerVersion }}-${{ runner.os }}-${{ runner.arch }}
3135
key: sonar-scanner-cli-${{ inputs.scannerVersion }}-${{ runner.os }}-${{ runner.arch }}
3236
- name: Install Sonar Scanner CLI
33-
if: steps.sonar-scanner-cli.outputs.cache-hit != 'true'
37+
if: ${{ env.NO_CACHE == 'true' || steps.sonar-scanner-cli.outputs.cache-hit != 'true' }}
3438
run: ${GITHUB_ACTION_PATH}/install-sonar-scanner-cli.sh
3539
shell: bash
3640
env:
3741
INPUT_SCANNERVERSION: ${{ inputs.scannerVersion }}
42+
INPUT_SCANNERBINARIESURL: ${{ inputs.scannerBinariesUrl }}
3843
- name: Add SonarScanner CLI to the PATH
3944
run: echo "${RUNNER_TEMP}/sonar-scanner-cli-${{ inputs.scannerVersion }}-${{ runner.os }}-${{ runner.arch }}/bin" >> $GITHUB_PATH
4045
shell: bash

install-sonar-scanner-cli.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ set -x
2626
mkdir -p $RUNNER_TEMP/sonarscanner
2727
cd $RUNNER_TEMP/sonarscanner
2828

29-
$WGET --no-verbose --user-agent="sonarqube-scan-action" https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$INPUT_SCANNERVERSION-$FLAVOR.zip
29+
$WGET --no-verbose --user-agent="sonarqube-scan-action" "${INPUT_SCANNERBINARIESURL%/}/sonar-scanner-cli-$INPUT_SCANNERVERSION-$FLAVOR.zip"
3030

3131
unzip -q sonar-scanner-cli-$INPUT_SCANNERVERSION-$FLAVOR.zip
3232

test/assertFileDoesntExist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
error() { echo -e "\\e[31m✗ $*\\e[0m"; }
4+
5+
if [ -f $1 ]; then
6+
error "File '$1' found"
7+
exit 1
8+
fi

0 commit comments

Comments
 (0)