From a2193cb9f6fcdd86cf4bd5646cc0a9fc33015d3a Mon Sep 17 00:00:00 2001 From: Konrad Pagacz Date: Tue, 5 Oct 2021 15:46:38 +0200 Subject: [PATCH] fix(R linting): try installing the R package before linting R language (#1911) * fix(R linting): try installing the R package before linting R language * the tool used to lint the R language gives false positives for files inside an R library, which is not installed * this change tries to naively install the package in the linted directory Resolves #1910 * fix code * fixed it * fixed it Co-authored-by: Admiral Awkbar --- lib/functions/detectFiles.sh | 53 ++++++++++++++++++++++++++++++++++++ lib/functions/worker.sh | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/lib/functions/detectFiles.sh b/lib/functions/detectFiles.sh index ce929927..b13b3d6b 100755 --- a/lib/functions/detectFiles.sh +++ b/lib/functions/detectFiles.sh @@ -437,4 +437,57 @@ function RunAdditionalInstalls() { done fi fi + + ############################### + # Run installs for R language # + ############################### + if [ "${VALIDATE_R}" == "true" ] && [ "${#FILE_ARRAY_R[@]}" -ne 0 ]; then + info "Detected R Language files to lint." + info "Trying to install the R package inside:[${WORKSPACE_PATH}]" + ######################### + # Run the build command # + ######################### + BUILD_CMD=$(R CMD build "${WORKSPACE_PATH}" 2>&1) + + ############## + # Error code # + ############## + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ "${ERROR_CODE}" -ne 0 ]; then + # Error + warn "ERROR! Failed to run:[R CMD build] at location:[${WORKSPACE_PATH}]" + warn "BUILD_CMD:[${BUILD_CMD}]" + else + # Get the build package + BUILD_PKG=$( + cd "${WORKSPACE_PATH}" || exit 0 + echo *.tar.gz 2>&1 + ) + ############################## + # Install the build packages # + ############################## + INSTALL_CMD=$( + cd "${WORKSPACE_PATH}" || exit 0 + R CMD INSTALL "${BUILD_PKG}" 2>&1 + ) + + ############## + # Error code # + ############## + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ "${ERROR_CODE}" -ne 0 ]; then + # Error + warn "ERROR: Failed to install the build package at:[${BUILD_PKG}]" + warn "INSTALL_CMD:[${INSTALL_CMD}]" + fi + fi + fi } diff --git a/lib/functions/worker.sh b/lib/functions/worker.sh index 0d6b36da..96c81205 100755 --- a/lib/functions/worker.sh +++ b/lib/functions/worker.sh @@ -10,7 +10,7 @@ ################################################################################ #### Function LintCodebase ##################################################### function LintCodebase() { - # Call comes thorugh as: + # Call comes through as: # LintCodebase "${LANGUAGE}" "${LINTER_NAME}" "${LINTER_COMMAND}" "${FILTER_REGEX_INCLUDE}" "${FILTER_REGEX_EXCLUDE}" "${TEST_CASE_RUN}" "${!LANGUAGE_FILE_ARRAY}" #################### # Pull in the vars #