diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml index f4bd70c..f05e52c 100644 --- a/.github/workflows/qa.yml +++ b/.github/workflows/qa.yml @@ -68,6 +68,52 @@ jobs: - name: Assert run: | ./test/assertFileContains ./output.properties "sonar.projectBaseDir=.*/baseDir" + scannerVersionTest: + name: > + 'scannerVersion' input + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Run action with scannerVersion + uses: ./ + with: + scannerVersion: 6.1.0.4477 + args: -Dsonar.scanner.internal.dumpToFile=./output.properties + env: + NO_CACHE: true + SONAR_HOST_URL: http://not_actually_used + SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}' + - name: Assert + run: | + ./test/assertFileExists "$RUNNER_TEMP/sonarscanner/sonar-scanner-cli-6.1.0.4477-x64.zip" + scannerBinariesUrlTest: + name: > + 'scannerBinariesUrl' input with invalid URL + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Run action with scannerBinariesUrl + id: runTest + uses: ./ + continue-on-error: true + with: + scannerVersion: 6.2.1.4610 + scannerBinariesUrl: https://invalid_uri/Distribution/sonar-scanner-cli + env: + NO_CACHE: true + SONAR_HOST_URL: http://not_actually_used + SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}' + - name: Assert action failed + if: steps.runTest.outcome == 'success' + run: exit 1 + - name: Assert Sonar Scanner CLI was not downloaded + run: ./test/assertFileDoesntExist "$RUNNER_TEMP/sonarscanner/sonar-scanner-cli-6.2.1.4610-x64.zip" + - name: Assert Sonar Scanner CLI was not executed + run: ./test/assertFileDoesntExist ./output.properties dontFailGradleTest: name: > Don't fail on Gradle project diff --git a/action.yml b/action.yml index 14854e5..eb8132e 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,10 @@ inputs: description: Version of the Sonar Scanner CLI to use required: false default: 6.2.1.4610 + scannerBinariesUrl: + description: URL to download the Sonar Scanner CLI binaries from + required: false + default: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli runs: using: "composite" steps: @@ -30,11 +34,12 @@ runs: path: ${{ runner.temp }}/sonar-scanner-cli-${{ inputs.scannerVersion }}-${{ runner.os }}-${{ runner.arch }} key: sonar-scanner-cli-${{ inputs.scannerVersion }}-${{ runner.os }}-${{ runner.arch }} - name: Install Sonar Scanner CLI - if: steps.sonar-scanner-cli.outputs.cache-hit != 'true' + if: ${{ env.NO_CACHE == 'true' || steps.sonar-scanner-cli.outputs.cache-hit != 'true' }} run: ${GITHUB_ACTION_PATH}/install-sonar-scanner-cli.sh shell: bash env: INPUT_SCANNERVERSION: ${{ inputs.scannerVersion }} + INPUT_SCANNERBINARIESURL: ${{ inputs.scannerBinariesUrl }} - name: Add SonarScanner CLI to the PATH run: echo "${RUNNER_TEMP}/sonar-scanner-cli-${{ inputs.scannerVersion }}-${{ runner.os }}-${{ runner.arch }}/bin" >> $GITHUB_PATH shell: bash diff --git a/install-sonar-scanner-cli.sh b/install-sonar-scanner-cli.sh index 7509d74..5cdbedb 100755 --- a/install-sonar-scanner-cli.sh +++ b/install-sonar-scanner-cli.sh @@ -26,7 +26,7 @@ set -x mkdir -p $RUNNER_TEMP/sonarscanner cd $RUNNER_TEMP/sonarscanner -$WGET --no-verbose --user-agent="sonarqube-scan-action" https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$INPUT_SCANNERVERSION-$FLAVOR.zip +$WGET --no-verbose --user-agent="sonarqube-scan-action" "${INPUT_SCANNERBINARIESURL%/}/sonar-scanner-cli-$INPUT_SCANNERVERSION-$FLAVOR.zip" unzip -q sonar-scanner-cli-$INPUT_SCANNERVERSION-$FLAVOR.zip diff --git a/test/assertFileDoesntExists b/test/assertFileDoesntExists new file mode 100644 index 0000000..032a07c --- /dev/null +++ b/test/assertFileDoesntExists @@ -0,0 +1,8 @@ +#!/bin/bash + +error() { echo -e "\\e[31m✗ $*\\e[0m"; } + +if [ -f $1 ]; then + error "File '$1' found" + exit 1 +fi \ No newline at end of file