Skip to content

Commit e7a41e6

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

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

.github/workflows/qa.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,60 @@ 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+
if command -v wget 2>&1 >/dev/null
284+
then
285+
exit 1
286+
fi
287+
- name: Run action
288+
uses: ./
289+
env:
290+
NO_CACHE: true
291+
SONAR_HOST_URL: http://not_actually_used
292+
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
293+
with:
294+
args: -Dsonar.scanner.internal.dumpToFile=./output.properties
295+
- name: Assert
296+
run: |
297+
./test/assertFileExists ./output.properties
298+
failOnMissingCurl:
299+
name: Fail on missing curl
300+
runs-on: ubuntu-latest
301+
steps:
302+
- uses: actions/checkout@v4
303+
with:
304+
token: ${{ secrets.GITHUB_TOKEN }}
305+
- name: Remove curl
306+
run: sudo apt-get remove -y curl
307+
- name: Assert curl is not available
308+
run: |
309+
if command -v curl 2>&1 >/dev/null
310+
then
311+
exit 1
312+
fi
313+
- name: Run action
314+
id: runTest
315+
uses: ./
316+
continue-on-error: true
317+
env:
318+
NO_CACHE: true
319+
SONAR_HOST_URL: http://not_actually_used
320+
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
321+
with:
322+
args: -Dsonar.scanner.internal.dumpToFile=./output.properties
323+
- name: Assert failure of previous step
324+
if: steps.runTest.outcome == 'success'
325+
run: exit 1
272326
useSslCertificate:
273327
name: >
274328
'SONAR_ROOT_CERT' is converted to truststore

install-sonar-scanner-cli.sh

Lines changed: 11 additions & 5 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="sonar-scanner-cli-$INPUT_SCANNERVERSION-$FLAVOR.zip"
34+
SCANNER_URI="${INPUT_SCANNERBINARIESURL%/}/$SCANNER_FILE_NAME"
35+
$CURL --user-agent "sonarqube-scan-action" --output $SCANNER_FILE_NAME $SCANNER_URI
3036

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

3339
# Folder name should correspond to the directory cached by the actions/cache
3440
mv sonar-scanner-$INPUT_SCANNERVERSION-$FLAVOR $RUNNER_TEMP/sonar-scanner-cli-$INPUT_SCANNERVERSION-$RUNNER_OS-$RUNNER_ARCH

0 commit comments

Comments
 (0)