Skip to content

build: ensure only errors are displayed in issue via log file #5751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions .github/workflows/lint_random_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,30 @@ jobs:
fi

# Combined error file:
ERR_FILE="lint_javascript_errors.txt"
ERR_FILE="$GITHUB_WORKSPACE/lint_javascript_errors.txt"
> "$ERR_FILE" # Initialize a clean file

# Initialize error flag:
error_occurred=0

run_make_lint() {
local files_to_lint="$1"
local make_args="$2"
local eslint_conf_arg="$3"
local error_log_file="$4"

local make_cmd="make lint-javascript-files FIX=${FIX} FAST_FAIL=0 FILES=\"${files_to_lint}\" ${make_args} ${eslint_conf_arg}"

echo "Running: ${make_cmd}"
if ! eval "${make_cmd}"; then
echo "Initial linting failed. Retrying with --quiet and logging errors..."

# Run again with --quiet flag and log output:
eval "${make_cmd} ESLINT_FLAGS='--quiet'" >> "${error_log_file}" 2>&1
error_occurred=1
fi
}

# Lint JavaScript source files:
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '\.js$' | grep -v -e '/examples' -e '/test' -e '/benchmark' -e '^dist/' | tr '\n' ' ')

Expand All @@ -335,31 +356,38 @@ jobs:
done
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest moving this logic to a separate Bash script. This will make refactoring and linting easier.


if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" 2>&1 | tee -a "$ERR_FILE"
run_make_lint "${files}" "" "" "${ERR_FILE}"
fi

# Lint JavaScript command-line interfaces...
# Lint JavaScript command-line interfaces:
file=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '\.js$' | grep -E '/bin/cli$' | tr '\n' ' ')
if [[ -n "${file}" ]]; then
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${file}" 2>&1 | tee -a "$ERR_FILE"
run_make_lint "${file}" "" "" "${ERR_FILE}"
fi

# Lint JavaScript example files:
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '/examples/.*\.js$' | tr '\n' ' ')
if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_examples_conf}" 2>&1 | tee -a "$ERR_FILE"
run_make_lint "${files}" "" "ESLINT_CONF=\"${eslint_examples_conf}\"" "${ERR_FILE}"
fi

# Lint JavaScript test files:
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '/test/.*\.js$' | tr '\n' ' ')
if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_tests_conf}" 2>&1 | tee -a "$ERR_FILE"
run_make_lint "${files}" "" "ESLINT_CONF=\"${eslint_tests_conf}\"" "${ERR_FILE}"
fi

# Lint JavaScript benchmark files:
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '/benchmark/.*\.js$' | tr '\n' ' ')
if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_benchmarks_conf}" 2>&1 | tee -a "$ERR_FILE"
run_make_lint "${files}" "" "ESLINT_CONF=\"${eslint_benchmarks_conf}\"" "${ERR_FILE}"
fi

# Check if any errors occurred during linting:
if [[ "$error_occurred" -eq 1 ]]; then
echo "JavaScript linting errors occurred. See details below or in the artifact."
cat "$ERR_FILE" # Print errors to the workflow log
exit 1
fi

# Create sub-issue for JavaScript lint failures:
Expand Down Expand Up @@ -392,7 +420,7 @@ jobs:
"5377" \
"Good First Issue"

rm "$BODY_FILE"
rm "$BODY_FILE" "$ERR_FILE"

# Lint Python files:
- name: 'Lint Python files'
Expand Down
35 changes: 20 additions & 15 deletions tools/make/lib/lint/javascript/eslint.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,29 @@ ESLINT_CONF_BENCHMARKS ?= $(CONFIG_DIR)/eslint/.eslintrc.benchmarks.js
ESLINT_IGNORE ?= $(ROOT_DIR)/.eslintignore

# Define the command-line options to use when invoking the ESLint executable:
ESLINT_FLAGS ?= \
eslint_flags := \
--ignore-path $(ESLINT_IGNORE) \
--report-unused-disable-directives

# Define user-supplied command-line options:
ESLINT_FLAGS ?=

ifeq ($(AUTOFIX),true)
ESLINT_FLAGS += --fix
eslint_flags += --fix
endif

FIX_TYPE ?=
ifneq ($(FIX_TYPE),)
ESLINT_FLAGS += --fix-type $(FIX_TYPE)
eslint_flags += --fix-type $(FIX_TYPE)
else
ifeq ($(AUTOFIX),true)
ESLINT_FLAGS += --fix-type problem,layout,directive
eslint_flags += --fix-type problem,layout,directive
endif
endif

# Append user-supplied command-line options:
eslint_flags += ESLINT_FLAGS

# RULES #

#/
Expand All @@ -88,14 +94,14 @@ ifeq ($(FAIL_FAST), true)
$(QUIET) $(FIND_SOURCES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
$(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file || exit 1; \
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file || exit 1; \
done
else
$(QUIET) status=0; \
$(FIND_SOURCES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file; then \
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file; then \
echo 'Linting failed.'; \
status=1; \
fi; \
Expand Down Expand Up @@ -129,14 +135,14 @@ ifeq ($(FAIL_FAST), true)
$(QUIET) $(FIND_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
$(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_TESTS) $$file || exit 1; \
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_TESTS) $$file || exit 1; \
done
else
$(QUIET) status=0; \
$(FIND_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_TESTS) $$file; then \
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_TESTS) $$file; then \
echo 'Linting failed.'; \
status=1; \
fi; \
Expand Down Expand Up @@ -170,14 +176,14 @@ ifeq ($(FAIL_FAST), true)
$(QUIET) $(FIND_EXAMPLES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
$(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_EXAMPLES) $$file || exit 1; \
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_EXAMPLES) $$file || exit 1; \
done
else
$(QUIET) status=0; \
$(FIND_EXAMPLES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_EXAMPLES) $$file; then \
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_EXAMPLES) $$file; then \
echo 'Linting failed.'; \
status=1; \
fi; \
Expand Down Expand Up @@ -211,14 +217,14 @@ ifeq ($(FAIL_FAST), true)
$(QUIET) $(FIND_BENCHMARKS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
$(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_BENCHMARKS) $$file || exit 1; \
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_BENCHMARKS) $$file || exit 1; \
done
else
$(QUIET) status=0; \
$(FIND_BENCHMARKS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_BENCHMARKS) $$file; then \
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_BENCHMARKS) $$file; then \
echo 'Linting failed.'; \
status=1; \
fi; \
Expand Down Expand Up @@ -249,14 +255,13 @@ ifeq ($(FAIL_FAST), true)
$(QUIET) for file in $(FILES); do \
echo ''; \
echo "Linting file: $$file"; \
$(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file || exit 1; \
done
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file || exit 1; \
else
$(QUIET) status=0; \
for file in $(FILES); do \
echo ''; \
echo "Linting file: $$file"; \
if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file; then \
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file; then \
echo 'Linting failed.'; \
status=1; \
fi; \
Expand Down
Loading