sonarqube-scan-action/entrypoint.sh
2022-07-20 10:12:28 -05:00

35 lines
1.1 KiB
Bash
Executable file

#!/bin/bash
set -e
if [[ -z "${SONAR_TOKEN}" ]]; then
echo "============================ WARNING ============================"
echo "Running this GitHub Action without SONAR_TOKEN is not recommended"
echo "============================ WARNING ============================"
fi
if [[ -z "${SONAR_HOST_URL}" ]]; then
echo "This GitHub Action requires the SONAR_HOST_URL env variable."
exit 1
fi
if [[ -f "${INPUT_PROJECTBASEDIR%/}pom.xml" ]]; then
echo "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 "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 [[ "${RUN_JEST}" == "true" ]]; then
npm install -g jest-cli jest-sonar-reporter
yarn add jest jest-environment-jsdom
yarn test --coverage --coverageDirectory='coverage'
fi
sonar-scanner -Dsonar.projectBaseDir=${INPUT_PROJECTBASEDIR} ${INPUT_ARGS}