mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-22 00:31:07 -05:00
Don't write colors and logs on disk if not necessary (#4934)
* Don't write colors and logs on disk if not necessary * Set color markers * Fix colors * Fix linting errors * Fix linting errors * Use sudo to access logs
This commit is contained in:
parent
5a8805dc4f
commit
879672e936
4 changed files with 76 additions and 28 deletions
7
.github/workflows/ci.yml
vendored
7
.github/workflows/ci.yml
vendored
|
@ -69,6 +69,7 @@ jobs:
|
|||
uses: ./
|
||||
env:
|
||||
ACTIONS_RUNNER_DEBUG: true
|
||||
CREATE_LOG_FILE: true
|
||||
ERROR_ON_MISSING_EXEC_BIT: true
|
||||
VALIDATE_ALL_CODEBASE: false
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
@ -76,6 +77,11 @@ jobs:
|
|||
RENOVATE_SHAREABLE_CONFIG_PRESET_FILE_NAMES: "default.json,hoge.json"
|
||||
TYPESCRIPT_STANDARD_TSCONFIG_FILE: ".github/linters/tsconfig.json"
|
||||
|
||||
- name: Get the contents of the log file
|
||||
run: |
|
||||
sudo cat super-linter.log
|
||||
sudo rm -v super-linter.log
|
||||
|
||||
- name: Run Test Suite
|
||||
run: make test
|
||||
|
||||
|
@ -96,7 +102,6 @@ jobs:
|
|||
run: |
|
||||
docker run \
|
||||
-e RUN_LOCAL=true \
|
||||
-e OUTPUT_DETAILS=detailed \
|
||||
-e ACTIONS_RUNNER_DEBUG=true \
|
||||
-e RENOVATE_SHAREABLE_CONFIG_PRESET_FILE_NAMES="default.json,hoge.json" \
|
||||
-e ERROR_ON_MISSING_EXEC_BIT=true \
|
||||
|
|
|
@ -278,7 +278,7 @@ But if you wish to select or exclude specific linters, we give you full control
|
|||
| **ANSIBLE_CONFIG_FILE** | `.ansible-lint.yml` | Filename for [Ansible-lint configuration](https://ansible.readthedocs.io/projects/lint/configuring/) (ex: `.ansible-lint`, `.ansible-lint.yml`) |
|
||||
| **ANSIBLE_DIRECTORY** | `/ansible` | Flag to set the root directory for Ansible file location(s), relative to `DEFAULT_WORKSPACE`. Set to `.` to use the top-level of the `DEFAULT_WORKSPACE`. |
|
||||
| **BASH_SEVERITY** | `style` | Specify the minimum severity of errors to consider in shellcheck. Valid values in order of severity are error, warning, info and style. |
|
||||
| **CREATE_LOG_FILE** | `false` | If set to `true`, it creates the log file. You can set the log filename using the `LOG_FILE` environment variable. |
|
||||
| **CREATE_LOG_FILE** | `false` | If set to `true`, it creates the log file. You can set the log filename using the `LOG_FILE` environment variable. This overrides any existing log files. |
|
||||
| **CSS_FILE_NAME** | `.stylelintrc.json` | Filename for [Stylelint configuration](https://github.com/stylelint/stylelint) (ex: `.stylelintrc.yml`, `.stylelintrc.yaml`) |
|
||||
| **DEFAULT_BRANCH** | `master` | The name of the repository default branch. |
|
||||
| **DEFAULT_WORKSPACE** | `/tmp/lint` | The location containing files to lint if you are running locally. Defaults to `GITHUB_WORKSPACE` when running in GitHub Actions. There's no need to configure this variable when running in GitHub Actions. |
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Background colors:
|
||||
# Blue
|
||||
# Cyan
|
||||
# Green
|
||||
# Black
|
||||
# Magenta
|
||||
# Red
|
||||
# White
|
||||
# Yellow
|
||||
declare -Agr B=(
|
||||
[B]=$(echo -e "\e[44m")
|
||||
[C]=$(echo -e "\e[46m")
|
||||
|
@ -10,6 +19,16 @@ declare -Agr B=(
|
|||
[W]=$(echo -e "\e[47m")
|
||||
[Y]=$(echo -e "\e[43m")
|
||||
)
|
||||
|
||||
# Foreground colors:
|
||||
# Blue
|
||||
# Cyan
|
||||
# Green
|
||||
# Black
|
||||
# Magenta
|
||||
# Red
|
||||
# White
|
||||
# Yellow
|
||||
declare -Agr F=(
|
||||
[B]=$(echo -e "\e[0;34m")
|
||||
[C]=$(echo -e "\e[0;36m")
|
||||
|
@ -20,6 +39,8 @@ declare -Agr F=(
|
|||
[W]=$(echo -e "\e[0;37m")
|
||||
[Y]=$(echo -e "\e[0;33m")
|
||||
)
|
||||
|
||||
# Reset
|
||||
NC=$(echo -e "\e[0m")
|
||||
readonly NC
|
||||
|
||||
|
@ -27,28 +48,47 @@ export B
|
|||
export F
|
||||
export NC
|
||||
|
||||
# Log Functions
|
||||
LOG_TEMP=$(mktemp) || echo "Failed to create temporary log file."
|
||||
export LOG_TEMP
|
||||
echo "super-linter Log" >"${LOG_TEMP}"
|
||||
|
||||
log() {
|
||||
local TOTERM=${1:-}
|
||||
local MESSAGE=${2:-}
|
||||
echo -e "${MESSAGE:-}" | (
|
||||
if [[ -n ${TOTERM} ]]; then
|
||||
tee -a "${LOG_TEMP}" >&2
|
||||
else
|
||||
cat >>"${LOG_TEMP}" 2>&1
|
||||
fi
|
||||
)
|
||||
local LOG_LEVEL_LABEL="[${3}]"
|
||||
|
||||
local LOG_MESSAGE_DATE
|
||||
LOG_MESSAGE_DATE="$(date +"%F %T")"
|
||||
local COLOR_MARKER
|
||||
COLOR_MARKER="${F[B]}"
|
||||
|
||||
if [ "${LOG_LEVEL_LABEL}" == "NOTICE" ]; then
|
||||
COLOR_MARKER="${F[G]}"
|
||||
elif [ "${LOG_LEVEL_LABEL}" == "WARN" ]; then
|
||||
COLOR_MARKER="${F[Y]}"
|
||||
elif [ "${LOG_LEVEL_LABEL}" == "ERROR" ] || [ "${LOG_LEVEL_LABEL}" == "FATAL" ]; then
|
||||
COLOR_MARKER="${F[R]}"
|
||||
fi
|
||||
|
||||
local COLORED_MESSAGE
|
||||
COLORED_MESSAGE="${NC}${LOG_MESSAGE_DATE} ${COLOR_MARKER}${LOG_LEVEL_LABEL}${NC} ${MESSAGE}${NC}"
|
||||
local MESSAGE_FOR_LOG_FILE
|
||||
MESSAGE_FOR_LOG_FILE="${LOG_MESSAGE_DATE} ${LOG_LEVEL_LABEL} ${MESSAGE}"
|
||||
|
||||
if [[ -n ${TOTERM} ]]; then
|
||||
echo -e "${COLORED_MESSAGE}"
|
||||
fi
|
||||
|
||||
if [ "${CREATE_LOG_FILE}" = "true" ]; then
|
||||
echo -e "${MESSAGE_FOR_LOG_FILE}" >>"${LOG_TEMP}"
|
||||
fi
|
||||
}
|
||||
trace() { log "${LOG_TRACE:-}" "${NC}$(date +"%F %T") ${F[B]}[TRACE]${NC} $*${NC}"; }
|
||||
debug() { log "${LOG_DEBUG:-}" "${NC}$(date +"%F %T") ${F[B]}[DEBUG]${NC} $*${NC}"; }
|
||||
info() { log "${LOG_VERBOSE:-}" "${NC}$(date +"%F %T") ${F[B]}[INFO]${NC} $*${NC}"; }
|
||||
notice() { log "${LOG_NOTICE:-}" "${NC}$(date +"%F %T") ${F[G]}[NOTICE]${NC} $*${NC}"; }
|
||||
warn() { log "${LOG_WARN:-}" "${NC}$(date +"%F %T") ${F[Y]}[WARN]${NC} $*${NC}"; }
|
||||
error() { log "${LOG_ERROR:-}" "${NC}$(date +"%F %T") ${F[R]}[ERROR]${NC} $*${NC}"; }
|
||||
trace() { log "${LOG_TRACE:-}" "$*" "TRACE"; }
|
||||
debug() { log "${LOG_DEBUG:-}" "$*" "DEBUG"; }
|
||||
info() { log "${LOG_VERBOSE:-}" "$*" "INFO"; }
|
||||
notice() { log "${LOG_NOTICE:-}" "$*" "NOTICE"; }
|
||||
warn() { log "${LOG_WARN:-}" "$*" "WARN"; }
|
||||
error() { log "${LOG_ERROR:-}" "$*" "ERROR"; }
|
||||
fatal() {
|
||||
log "true" "${NC}$(date +"%F %T") ${B[R]}${F[W]}[FATAL]${NC} $*${NC}"
|
||||
log "true" "$*" "FATAL"
|
||||
exit 1
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ IMAGE="${IMAGE:-standard}" # Version of the Super-lin
|
|||
# Log Vars #
|
||||
# Define these early, so we can use debug logging ASAP if needed #
|
||||
##################################################################
|
||||
LOG_FILE="${LOG_FILE:-super-linter.log}" # Default log file name (located in GITHUB_WORKSPACE folder)
|
||||
LOG_LEVEL="${LOG_LEVEL:-VERBOSE}" # Default log level (VERBOSE, DEBUG, TRACE)
|
||||
LOG_FILE="${LOG_FILE:-"super-linter.log"}" # Default log file name (located in GITHUB_WORKSPACE folder)
|
||||
LOG_LEVEL="${LOG_LEVEL:-VERBOSE}" # Default log level (VERBOSE, DEBUG, TRACE)
|
||||
CREATE_LOG_FILE="${CREATE_LOG_FILE:-"false"}"
|
||||
export CREATE_LOG_FILE
|
||||
|
||||
|
@ -96,6 +96,8 @@ LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter rules directo
|
|||
VERSION_FILE='/action/lib/functions/linterVersions.txt' # File to store linter versions
|
||||
export VERSION_FILE # Workaround SC2034
|
||||
|
||||
debug "CREATE_LOG_FILE: ${CREATE_LOG_FILE}"
|
||||
|
||||
###############
|
||||
# Rules files #
|
||||
###############
|
||||
|
@ -649,10 +651,7 @@ CallStatusAPI() {
|
|||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ "${ERROR_CODE}" -ne 0 ]; then
|
||||
# ERROR
|
||||
info "ERROR! Failed to call GitHub Status API!"
|
||||
info "ERROR:[${SEND_STATUS_CMD}]"
|
||||
# Not going to fail the script on this yet...
|
||||
info "Failed to call GitHub Status API: ${SEND_STATUS_CMD}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -775,13 +774,17 @@ UpdateLoopsForImage() {
|
|||
# shellcheck disable=SC2317
|
||||
cleanup() {
|
||||
local -ri EXIT_CODE=$?
|
||||
# Define this variable here so we can rely on it as soon as possible
|
||||
local LOG_FILE_PATH="${GITHUB_WORKSPACE}/${LOG_FILE}"
|
||||
debug "CREATE_LOG_FILE: ${CREATE_LOG_FILE}, LOG_FILE_PATH: ${LOG_FILE_PATH}"
|
||||
debug "LOG_FILE_PATH: ${LOG_FILE_PATH}"
|
||||
if [ "${CREATE_LOG_FILE}" = "true" ]; then
|
||||
debug "Creating log file: ${LOG_FILE_PATH}"
|
||||
sh -c "cat ${LOG_TEMP} >> ${LOG_FILE_PATH}" || true
|
||||
debug "Moving log file from ${LOG_TEMP} to ${LOG_FILE_PATH}"
|
||||
mv \
|
||||
--force \
|
||||
--verbose \
|
||||
"${LOG_TEMP}" "${LOG_FILE_PATH}"
|
||||
else
|
||||
debug "Skipping the log file creation"
|
||||
debug "Skipping the moving of the log file from ${LOG_TEMP} to ${LOG_FILE_PATH}"
|
||||
fi
|
||||
|
||||
exit "${EXIT_CODE}"
|
||||
|
|
Loading…
Reference in a new issue