mirror of
https://github.com/super-linter/super-linter.git
synced 2024-12-22 12:42:09 -05:00
Merge pull request #252 from v1v/feature/tap-format
Support TAP reporting format
This commit is contained in:
commit
3bc689af42
5 changed files with 147 additions and 2 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -61,4 +61,7 @@ typings/
|
|||
.next
|
||||
|
||||
# clj-kondo cache
|
||||
.cache
|
||||
.cache
|
||||
|
||||
# default output report
|
||||
super-linter.report
|
||||
|
|
|
@ -221,7 +221,10 @@ ENV GITHUB_SHA=${GITHUB_SHA} \
|
|||
RUN_LOCAL=${RUN_LOCAL} \
|
||||
TEST_CASE_RUN=${TEST_CASE_RUN} \
|
||||
ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \
|
||||
DISABLE_ERRORS=${DISABLE_ERRORS}
|
||||
DISABLE_ERRORS=${DISABLE_ERRORS} \
|
||||
OUTPUT_FORMAT=${OUTPUT_FORMAT} \
|
||||
OUTPUT_FOLDER=${OUTPUT_FOLDER} \
|
||||
OUTPUT_DETAILS=${OUTPUT_DETAILS}
|
||||
|
||||
#############################
|
||||
# Copy scripts to container #
|
||||
|
|
|
@ -193,6 +193,10 @@ and won't run anything unexpected.
|
|||
| **ACTIONS_RUNNER_DEBUG** | `false` | Flag to enable additional information about the linter, versions, and additional output. |
|
||||
| **DISABLE_ERRORS** | `false` | Flag to have the linter complete with exit code 0 even if errors were detected. |
|
||||
| **DEFAULT_WORKSPACE** | `/tmp/lint` | The location containing files to lint if you are running locally. |
|
||||
| **OUTPUT_FORMAT** | `none` | The report format to be generated, besides the stdout one. Output format of tap is currently using v13 of the specification. Supported formats: tap |
|
||||
| **OUTPUT_FOLDER** | `super-linter.report` | The location where the output reporting will be generated to. Output folder must not previously exist. |
|
||||
| **OUTPUT_DETAILS** | `simpler` | What level of details to be reported. Supported formats: simpler or detailed. |
|
||||
|
||||
|
||||
### Template rules files
|
||||
You can use the **GitHub** **Super-Linter** *with* or *without* your own personal rules sets. This allows for greater flexibility for each individual code base. The Template rules all try to follow the standards we believe should be enabled at the basic level.
|
||||
|
|
|
@ -174,6 +174,14 @@ echo "${TEST_CASE_FOLDER}" > /dev/null 2>&1 || true # Workaround SC2034
|
|||
DEFAULT_ANSIBLE_DIRECTORY="$GITHUB_WORKSPACE/ansible" # Default Ansible Directory
|
||||
echo "${DEFAULT_ANSIBLE_DIRECTORY}" > /dev/null 2>&1 || true # Workaround SC2034
|
||||
|
||||
##############
|
||||
# Format #
|
||||
##############
|
||||
OUTPUT_FORMAT="${OUTPUT_FORMAT}" # Output format to be generated. Default none
|
||||
OUTPUT_FOLDER="${OUTPUT_FOLDER:-super-linter.report}" # Folder where the reports are generated. Default super-linter.report
|
||||
OUTPUT_DETAILS="${OUTPUT_DETAILS:-simpler}" # What level of details. (simpler or detailed). Default simpler
|
||||
REPORT_OUTPUT_FOLDER="${DEFAULT_WORKSPACE}/${OUTPUT_FOLDER}"
|
||||
|
||||
##########################
|
||||
# Array of changed files #
|
||||
##########################
|
||||
|
@ -745,6 +753,13 @@ Footer() {
|
|||
echo "----------------------------------------------"
|
||||
echo ""
|
||||
|
||||
###################################
|
||||
# Prints output report if enabled #
|
||||
###################################
|
||||
if [ -z "${FORMAT_REPORT}" ] ; then
|
||||
echo "Reports generated in folder ${REPORT_OUTPUT_FOLDER}"
|
||||
fi
|
||||
|
||||
##############################
|
||||
# Prints for errors if found #
|
||||
##############################
|
||||
|
@ -828,6 +843,17 @@ Footer() {
|
|||
##########
|
||||
Header
|
||||
|
||||
##############################################################
|
||||
# check flag for validating the report folder does not exist #
|
||||
##############################################################
|
||||
if [ -n "${OUTPUT_FORMAT}" ]; then
|
||||
if [ -d "${REPORT_OUTPUT_FOLDER}" ] ; then
|
||||
echo "ERROR! Found ${REPORT_OUTPUT_FOLDER}"
|
||||
echo "Please remove the folder and try again."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
#######################
|
||||
# Get GitHub Env Vars #
|
||||
#######################
|
||||
|
|
109
lib/worker.sh
109
lib/worker.sh
|
@ -124,6 +124,16 @@ function LintCodebase() {
|
|||
echo "$LINE"
|
||||
done
|
||||
|
||||
########################################
|
||||
# Prepare context if TAP format output #
|
||||
########################################
|
||||
if IsTAP ; then
|
||||
TMPFILE=$(mktemp -q "/tmp/super-linter-${FILE_TYPE}.XXXXXX")
|
||||
INDEX=0
|
||||
mkdir -p "${REPORT_OUTPUT_FOLDER}"
|
||||
REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}"
|
||||
fi
|
||||
|
||||
##################
|
||||
# Lint the files #
|
||||
##################
|
||||
|
@ -147,6 +157,11 @@ function LintCodebase() {
|
|||
continue
|
||||
fi
|
||||
|
||||
##################################
|
||||
# Increase the linted file index #
|
||||
##################################
|
||||
(("INDEX++"))
|
||||
|
||||
##############
|
||||
# File print #
|
||||
##############
|
||||
|
@ -199,13 +214,42 @@ function LintCodebase() {
|
|||
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$LINT_CMD]${NC}"
|
||||
# Increment the error count
|
||||
(("ERRORS_FOUND_$FILE_TYPE++"))
|
||||
|
||||
#######################################################
|
||||
# Store the linting as a temporary file in TAP format #
|
||||
#######################################################
|
||||
if IsTAP ; then
|
||||
echo "not ok ${INDEX} - ${FILE}" >> "${TMPFILE}"
|
||||
##########################################
|
||||
# Report the detailed message if enabled #
|
||||
##########################################
|
||||
DETAILED_MSG=$(TransformTAPDetails "$LINT_CMD")
|
||||
if [ -n "${DETAILED_MSG}" ] ; then
|
||||
printf " ---\n message: %s\n ...\n" "$DETAILED_MSG" >> "${TMPFILE}"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
###########
|
||||
# Success #
|
||||
###########
|
||||
echo -e "${NC}${F[B]} - File:${F[W]}[$FILE_NAME]${F[B]} was linted with ${F[W]}[$LINTER_NAME]${F[B]} successfully${NC}"
|
||||
|
||||
#######################################################
|
||||
# Store the linting as a temporary file in TAP format #
|
||||
#######################################################
|
||||
if IsTAP ; then
|
||||
echo "ok ${INDEX} - ${FILE}" >> "${TMPFILE}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
#################################
|
||||
# Generate report in TAP format #
|
||||
#################################
|
||||
if IsTAP && [ ${INDEX} -gt 0 ] ; then
|
||||
printf "TAP version 13\n1..%s\n" "${INDEX}" > "${REPORT_OUTPUT_FILE}"
|
||||
cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
|
@ -592,6 +636,16 @@ function LintAnsibleFiles() {
|
|||
done
|
||||
fi
|
||||
|
||||
########################################
|
||||
# Prepare context if TAP output format #
|
||||
########################################
|
||||
if IsTAP ; then
|
||||
TMPFILE=$(mktemp -q "/tmp/super-linter-${FILE_TYPE}.XXXXXX")
|
||||
INDEX=0
|
||||
mkdir -p "${REPORT_OUTPUT_FOLDER}"
|
||||
REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}"
|
||||
fi
|
||||
|
||||
##################
|
||||
# Lint the files #
|
||||
##################
|
||||
|
@ -605,6 +659,11 @@ function LintAnsibleFiles() {
|
|||
continue
|
||||
fi
|
||||
|
||||
##################################
|
||||
# Increase the linted file index #
|
||||
##################################
|
||||
(("INDEX++"))
|
||||
|
||||
####################
|
||||
# Get the filename #
|
||||
####################
|
||||
|
@ -637,13 +696,43 @@ function LintAnsibleFiles() {
|
|||
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$LINT_CMD]${NC}"
|
||||
# Increment error count
|
||||
((ERRORS_FOUND_ANSIBLE++))
|
||||
|
||||
#######################################################
|
||||
# Store the linting as a temporary file in TAP format #
|
||||
#######################################################
|
||||
if IsTAP ; then
|
||||
echo "not ok ${INDEX} - ${FILE}" >> "${TMPFILE}"
|
||||
##########################################
|
||||
# Report the detailed message if enabled #
|
||||
##########################################
|
||||
DETAILED_MSG=$(TransformTAPDetails "$LINT_CMD")
|
||||
if [ -n "${DETAILED_MSG}" ] ; then
|
||||
printf " ---\n message: %s\n ...\n" "$DETAILED_MSG" >> "${TMPFILE}"
|
||||
fi
|
||||
fi
|
||||
|
||||
else
|
||||
###########
|
||||
# Success #
|
||||
###########
|
||||
echo -e "${NC}${F[B]} - File:${F[W]}[$FILE_NAME]${F[B]} was linted with ${F[W]}[$LINTER_NAME]${F[B]} successfully${NC}"
|
||||
|
||||
#######################################################
|
||||
# Store the linting as a temporary file in TAP format #
|
||||
#######################################################
|
||||
if IsTAP ; then
|
||||
echo "ok ${INDEX} - ${FILE}" >> "${TMPFILE}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
#################################
|
||||
# Generate report in TAP format #
|
||||
#################################
|
||||
if IsTAP && [ ${INDEX} -gt 0 ] ; then
|
||||
printf "TAP version 13\n1..%s\n" "${INDEX}" > "${REPORT_OUTPUT_FILE}"
|
||||
cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}"
|
||||
fi
|
||||
else # No ansible directory found in path
|
||||
###############################
|
||||
# Check to see if debug is on #
|
||||
|
@ -657,3 +746,23 @@ function LintAnsibleFiles() {
|
|||
fi
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function IsTap ############################################################
|
||||
function IsTAP() {
|
||||
if [ "${OUTPUT_FORMAT}" == "tap" ] ; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function TransformTAPDetails ##############################################
|
||||
function TransformTAPDetails() {
|
||||
DATA=$1
|
||||
if [ -n "${DATA}" ] && [ "${OUTPUT_DETAILS}" == "detailed" ] ; then
|
||||
#########################################################
|
||||
# Transform new lines to \\n, remove colours and colons #
|
||||
#########################################################
|
||||
echo "${DATA}" | awk 'BEGIN{RS="\n";ORS="\\n"}1' | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" | tr ':' ' '
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue