Skip to content

Commit 804cd23

Browse files
committed
SQSCANGHA-55 Support GitHub self-hosted runners without wget
1 parent ab7fbab commit 804cd23

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

.github/workflows/qa.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,58 @@ jobs:
269269
- name: Assert
270270
run: |
271271
./test/assertFileExists ./test/example-project/.scannerwork/report-task.txt
272+
dontFailOnMissingWget:
273+
name: Don't fail on missing wget
274+
runs-on: ubuntu-latest
275+
steps:
276+
- uses: actions/checkout@v4
277+
with:
278+
token: ${{ secrets.GITHUB_TOKEN }}
279+
- name: Remove wget
280+
run: sudo apt-get remove -y wget
281+
- name: Assert wget is not available
282+
run: |
283+
command -v wget
284+
if [ $? -eq 0 ]; then
285+
exit 1
286+
fi
287+
- name: Run action
288+
uses: ./
289+
env:
290+
SONAR_HOST_URL: http://not_actually_used
291+
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
292+
with:
293+
args: -Dsonar.scanner.internal.dumpToFile=./output.properties
294+
- name: Assert
295+
run: |
296+
./test/assertFileDoesntExist ./output.properties
297+
failOnMissingCurl:
298+
name: Fail on missing curl
299+
runs-on: ubuntu-latest
300+
steps:
301+
- uses: actions/checkout@v4
302+
with:
303+
token: ${{ secrets.GITHUB_TOKEN }}
304+
- name: Remove curl
305+
run: sudo apt-get remove -y curl
306+
- name: Assert curl is not available
307+
run: |
308+
command -v curl
309+
if [ $? -eq 0 ]; then
310+
exit 1
311+
fi
312+
- name: Run action
313+
id: runTest
314+
uses: ./
315+
continue-on-error: true
316+
env:
317+
SONAR_HOST_URL: http://not_actually_used
318+
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
319+
with:
320+
args: -Dsonar.scanner.internal.dumpToFile=./output.properties
321+
- name: Assert failure of previous step
322+
if: steps.runTest.outcome == 'success'
323+
run: exit 1
272324
useSslCertificate:
273325
name: >
274326
'SONAR_ROOT_CERT' is converted to truststore

install-sonar-scanner-cli.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
set -eou pipefail
44

5-
#See https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables
5+
# See https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables
6+
#
7+
# Script-specific variables required:
8+
# - INPUT_SCANNERVERSION: e.g. 6.2.1.4610
9+
# - INPUT_SCANNERBINARIESURL: e.g. https://github.com/me/my-repo/raw/refs/heads/main/binaries
610

7-
WGET=wget
11+
CURL=curl
812
if [[ "$RUNNER_OS" == "Linux" && "$RUNNER_ARCH" == "X64" ]]; then
913
FLAVOR="linux-x64"
1014
elif [[ "$RUNNER_OS" == "Linux" && "$RUNNER_ARCH" == "ARM64" ]]; then
1115
FLAVOR="linux-aarch64"
1216
elif [[ "$RUNNER_OS" == "Windows" && "$RUNNER_ARCH" == "X64" ]]; then
1317
FLAVOR="windows-x64"
14-
WGET="C:\\msys64\\usr\\bin\\wget.exe"
18+
CURL="C:\\msys64\\usr\\bin\\curl.exe"
1519
elif [[ "$RUNNER_OS" == "macOS" && "$RUNNER_ARCH" == "X64" ]]; then
1620
FLAVOR="macosx-x64"
1721
elif [[ "$RUNNER_OS" == "macOS" && "$RUNNER_ARCH" == "ARM64" ]]; then
@@ -26,9 +30,11 @@ set -x
2630
mkdir -p $RUNNER_TEMP/sonarscanner
2731
cd $RUNNER_TEMP/sonarscanner
2832

29-
$WGET --no-verbose --user-agent="sonarqube-scan-action" "${INPUT_SCANNERBINARIESURL%/}/sonar-scanner-cli-$INPUT_SCANNERVERSION-$FLAVOR.zip"
33+
SCANNER_FILE_NAME_NO_EXT="sonar-scanner-cli-$INPUT_SCANNERVERSION-$FLAVOR"
34+
SCANNER_URI="${INPUT_SCANNERBINARIESURL%/}/$SCANNER_FILE_NAME_NO_EXT.zip"
35+
$CURL --user-agent "sonarqube-scan-action" --output "$SCANNER_FILE_NAME_NO_EXT.zip" $SCANNER_URI
3036

31-
unzip -q sonar-scanner-cli-$INPUT_SCANNERVERSION-$FLAVOR.zip
37+
unzip -q "$SCANNER_FILE_NAME_NO_EXT.zip"
3238

3339
# Folder name should correspond to the directory cached by the actions/cache
34-
mv sonar-scanner-$INPUT_SCANNERVERSION-$FLAVOR $RUNNER_TEMP/sonar-scanner-cli-$INPUT_SCANNERVERSION-$RUNNER_OS-$RUNNER_ARCH
40+
mv "$SCANNER_FILE_NAME_NO_EXT.zip" "$RUNNER_TEMP/sonar-scanner-cli-$INPUT_SCANNERVERSION-$RUNNER_OS-$RUNNER_ARCH"

0 commit comments

Comments
 (0)