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 1 commit
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
Prev Previous commit
chore: address PR feedback
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
  • Loading branch information
Planeshifter committed Apr 25, 2025
commit ed6a9d16985018abbee6a5238b40edbec2ee743f
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}" ESLINT_ERROR_LOG="$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}" ESLINT_ERROR_LOG="$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}" ESLINT_ERROR_LOG="$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}" ESLINT_ERROR_LOG="$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}" ESLINT_ERROR_LOG="$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
50 changes: 20 additions & 30 deletions tools/make/lib/lint/javascript/eslint.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,30 @@ ESLINT_CONF_BENCHMARKS ?= $(CONFIG_DIR)/eslint/.eslintrc.benchmarks.js
# Define the path to the ESLint ignore file:
ESLINT_IGNORE ?= $(ROOT_DIR)/.eslintignore

# Define optional path for storing lint failure reports:
ESLINT_ERROR_LOG ?=

# 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 @@ -91,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 @@ -132,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 @@ -173,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 @@ -214,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 @@ -252,26 +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
else ifneq ($(ESLINT_ERROR_LOG),)
$(QUIET) status=0; \
for file in $(FILES); do \
echo ''; \
echo "Linting file: $$file"; \
if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file; then \
echo 'Linting failed.'; \
$(ESLINT) $(ESLINT_FLAGS) --quiet --config $(ESLINT_CONF) $$file >> $(ESLINT_ERROR_LOG); \
status=1; \
fi; \
done; \
exit $$status;
$(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