From 9d60bddfc9e974d693db462cf2d416e2b3b335d9 Mon Sep 17 00:00:00 2001 From: Dwi Siswanto Date: Thu, 16 Jun 2022 12:02:05 +0700 Subject: [PATCH] update(entrypoint): exit early on Maven/Gradle project, and - display warning on auth w/o using token - proper `sonar-project.properties` link - unset `JAVA_HOME` environment (fix #31) --- entrypoint.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index b08528c..231b4e3 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -12,9 +12,26 @@ fi REPOSITORY_NAME=$(basename "${GITHUB_REPOSITORY}") -[[ ! -z ${INPUT_PASSWORD} ]] && SONAR_PASSWORD="${INPUT_PASSWORD}" || SONAR_PASSWORD="" +if [[ ! -z ${INPUT_PASSWORD} ]]; then + echo "::warning ::Running this GitHub Action without authentication token is NOT recommended!" + SONAR_PASSWORD="${INPUT_PASSWORD}" +else + SONAR_PASSWORD="" +fi + +if [[ -f "${INPUT_PROJECTBASEDIR%/}pom.xml" ]]; then + echo "::error file=${INPUT_PROJECTBASEDIR%/}pom.xml::Maven project detected. You should run the goal 'org.sonarsource.scanner.maven:sonar' during build rather than using this GitHub Action." + exit 1 +fi -if [[ ! -f "${GITHUB_WORKSPACE}/sonar-project.properties" ]]; then +if [[ -f "${INPUT_PROJECTBASEDIR%/}build.gradle" ]]; then + echo "::error file=${INPUT_PROJECTBASEDIR%/}build.gradle::Gradle project detected. You should use the SonarQube plugin for Gradle during build rather than using this GitHub Action." + exit 1 +fi + +unset JAVA_HOME + +if [[ ! -f "${INPUT_PROJECTBASEDIR%/}sonar-project.properties" ]]; then [[ -z ${INPUT_PROJECTKEY} ]] && SONAR_PROJECTKEY="${REPOSITORY_NAME}" || SONAR_PROJECTKEY="${INPUT_PROJECTKEY}" [[ -z ${INPUT_PROJECTNAME} ]] && SONAR_PROJECTNAME="${REPOSITORY_NAME}" || SONAR_PROJECTNAME="${INPUT_PROJECTNAME}" [[ -z ${INPUT_PROJECTVERSION} ]] && SONAR_PROJECTVERSION="" || SONAR_PROJECTVERSION="${INPUT_PROJECTVERSION}" @@ -31,7 +48,6 @@ if [[ ! -f "${GITHUB_WORKSPACE}/sonar-project.properties" ]]; then else sonar-scanner \ -Dsonar.host.url=${INPUT_HOST} \ - -Dsonar.projectBaseDir=${INPUT_PROJECTBASEDIR} \ -Dsonar.login=${INPUT_LOGIN} \ -Dsonar.password=${SONAR_PASSWORD} fi