mirror of
				https://github.com/kitabisa/sonarqube-action.git
				synced 2025-10-31 21:24:18 +08:00 
			
		
		
		
	 9d60bddfc9
			
		
	
	
		9d60bddfc9
		
	
	
	
	
		
			
			- display warning on auth w/o using token - proper `sonar-project.properties` link - unset `JAVA_HOME` environment (fix #31)
		
			
				
	
	
		
			54 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
| #!/bin/bash
 | |
| 
 | |
| set -e
 | |
| 
 | |
| if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
 | |
| 	EVENT_ACTION=$(jq -r ".action" "${GITHUB_EVENT_PATH}")
 | |
| 	if [[ "${EVENT_ACTION}" != "opened" ]]; then
 | |
| 		echo "No need to run analysis. It is already triggered by the push event."
 | |
| 		exit
 | |
| 	fi
 | |
| fi
 | |
| 
 | |
| REPOSITORY_NAME=$(basename "${GITHUB_REPOSITORY}")
 | |
| 
 | |
| 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 "${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}"
 | |
|   sonar-scanner \
 | |
|     -Dsonar.host.url=${INPUT_HOST} \
 | |
|     -Dsonar.projectKey=${SONAR_PROJECTKEY} \
 | |
|     -Dsonar.projectName=${SONAR_PROJECTNAME} \
 | |
|     -Dsonar.projectVersion=${SONAR_PROJECTVERSION} \
 | |
|     -Dsonar.projectBaseDir=${INPUT_PROJECTBASEDIR} \
 | |
|     -Dsonar.login=${INPUT_LOGIN} \
 | |
|     -Dsonar.password=${SONAR_PASSWORD} \
 | |
|     -Dsonar.sources=. \
 | |
|     -Dsonar.sourceEncoding=UTF-8
 | |
| else
 | |
|   sonar-scanner \
 | |
|     -Dsonar.host.url=${INPUT_HOST} \
 | |
|     -Dsonar.login=${INPUT_LOGIN} \
 | |
|     -Dsonar.password=${SONAR_PASSWORD}
 | |
| fi
 |