From 980b35006d17f4c9a608d5215952647b0a52285a Mon Sep 17 00:00:00 2001 From: Tsuyoshi CHO Date: Sat, 3 Aug 2024 20:21:06 +0900 Subject: [PATCH] fix: Update migration --- README.md | 24 +++++++----- action.yml | 17 +++++++-- script.sh | 105 +++++++++++++++++++++++++++++++++++------------------ 3 files changed, 99 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 8d48075..dd049ca 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,7 @@ This is a action-mypy repository for [reviewdog](https://github.com/reviewdog/reviewdog) action with release automation. **Limitation**: -**mypy report multiline error, but now, multiline error cannot be handled in one unit.** -**It handles the error line by line.** -see [Issue](https://github.com/tsuyoshicho/action-mypy/issues/38). - -**This action require mypy==1.11 or higher** +**mypy report multiline error, but now, multiline error may be handled under JSON output is enabled.** Notice: This action is `composition action`. @@ -120,21 +116,31 @@ inputs: default: 'mypy' ignore_note: description: | - Currentry always enable this option - Ignore error context NOTE: entry + Currently, this option is always true. + Ignore "note: entries" that as reported by mypy. - old description: + Old description: Ignore note entry. mypy report some error with optional note entry. This option is workaround. + required: false default: 'true' + output_json: + description: | + Use the JSON output format available in mypy 1.11 or higher. + + This option defaults to false due to version limitations + and because it is still experimental. + Note the mypy version when setting to true. + required: false + default: 'false' ``` ### Input note `mypy_flags` is used for workflow setting. (eg '--strict --strict-equality'). -Currentry always suppress note. +Currently always suppress note. ## Usage diff --git a/action.yml b/action.yml index acc28fb..98c4d99 100644 --- a/action.yml +++ b/action.yml @@ -91,14 +91,24 @@ inputs: default: 'mypy' ignore_note: description: | - Currentry always enable this option - Ignore error context NOTE: entry + Currently, this option is always true. + Ignore "note: entries" that as reported by mypy. - old description: + Old description: Ignore note entry. mypy report some error with optional note entry. This option is workaround. + required: false default: 'true' + output_json: + description: | + Use the JSON output format available in mypy 1.11 or higher. + + This option defaults to false due to version limitations + and because it is still experimental. + Note the mypy version when setting to true. + required: false + default: 'false' runs: using: 'composite' steps: @@ -123,6 +133,7 @@ runs: INPUT_TOOL_NAME: ${{ inputs.tool_name }} # INPUT_IGNORE_NOTE: ${{ inputs.ignore_note }} INPUT_INSTALL_TYPES: ${{ inputs.install_types }} + INPUT_OUTPUT_JSON: ${{ inputs.output_json }} # Ref: https://haya14busa.github.io/github-action-brandings/ branding: icon: 'check' diff --git a/script.sh b/script.sh index 3cbc4c2..6586fd7 100755 --- a/script.sh +++ b/script.sh @@ -68,9 +68,9 @@ if [[ "${INPUT_INSTALL_TYPES}" == "true" ]] ; then echo '::group:: Installing types' echo 'Pre-run and detect missing stubs' # shellcheck disable=SC2086 - ${INPUT_EXECUTE_COMMAND} \ - ${TARGETS_LIST} 2>&1 \ - || mypy_exit_val="$?" + mypy_check_output="$(${INPUT_EXECUTE_COMMAND} \ + ${TARGETS_LIST} 2>&1 \ + )" || mypy_exit_val="$?" # discard result echo 'Install types' ${INPUT_EXECUTE_COMMAND} --install-types --non-interactive @@ -102,38 +102,73 @@ set +e # first, user flags # second, set reviewdog supplement flags(abspath, column num) and suppress pretty flag # same flag: win later -# --hide-error-context : suppress error context NOTE: entry -# shellcheck disable=SC2086 -${INPUT_EXECUTE_COMMAND} \ - ${INPUT_MYPY_FLAGS} \ - --output json \ - --hide-error-context \ - --show-column-numbers \ - --show-absolute-path \ - --no-pretty \ - ${TARGETS_LIST} \ - > ${MYPYTMPDIR}/mypy_output.json \ - 2> /dev/null \ - || mypy_exit_val="$?" - -# echo "mypy output result:" -# cat "${MYPYTMPDIR}/mypy_output.json" - -python3 "${BASE_PATH}/mypy_to_rdjson/mypy_to_rdjson.py" < "${MYPYTMPDIR}/mypy_output.json" > "${MYPYTMPDIR}/mypy_rdjson.json" - -# echo "mypy output rdjson:" -# cat "${MYPYTMPDIR}/mypy_rdjson.json" - -# shellcheck disable=SC2086 -reviewdog \ - -f=rdjson \ - -name="${INPUT_TOOL_NAME:-mypy}" \ - -reporter="${INPUT_REPORTER:-github-pr-check}" \ - -filter-mode="${INPUT_FILTER_MODE}" \ - -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ - -level="${INPUT_LEVEL}" \ - ${INPUT_REVIEWDOG_FLAGS} < "${MYPYTMPDIR}/mypy_rdjson.json" \ - || reviewdog_exit_val="$?" + +if [[ "${INPUT_OUTPUT_JSON}" != "true" ]] ; then + # Do not use JSON output + + # shellcheck disable=SC2086 + mypy_check_output="$(${INPUT_EXECUTE_COMMAND} \ + ${INPUT_MYPY_FLAGS} \ + --show-column-numbers \ + --show-absolute-path \ + --no-pretty \ + ${TARGETS_LIST} 2>&1 \ + )" || mypy_exit_val="$?" + + # note ignore + IGNORE_NOTE_EFM_OPTION=("-efm=%-G%f:%l:%c: note: %m") + + # shellcheck disable=SC2086 + echo "${mypy_check_output}" | reviewdog \ + "${IGNORE_NOTE_EFM_OPTION[@]}" \ + -efm="%f:%l:%c: %t%*[^:]: %m" \ + -efm="%f:%l: %t%*[^:]: %m" \ + -efm="%f: %t%*[^:]: %m" \ + -name="${INPUT_TOOL_NAME:-mypy}" \ + -reporter="${INPUT_REPORTER:-github-pr-check}" \ + -filter-mode="${INPUT_FILTER_MODE}" \ + -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ + -level="${INPUT_LEVEL}" \ + ${INPUT_REVIEWDOG_FLAGS} || reviewdog_exit_val="$?" + +else + # Use JSON output + # require mypy==1.11 or higher + + # --hide-error-context : suppress error context NOTE: entry + # shellcheck disable=SC2086 + ${INPUT_EXECUTE_COMMAND} \ + ${INPUT_MYPY_FLAGS} \ + --output json \ + --hide-error-context \ + --show-column-numbers \ + --show-absolute-path \ + --no-pretty \ + ${TARGETS_LIST} \ + > ${MYPYTMPDIR}/mypy_output.json \ + 2> /dev/null \ + || mypy_exit_val="$?" + + # echo "mypy output result:" + # cat "${MYPYTMPDIR}/mypy_output.json" + + python3 "${BASE_PATH}/mypy_to_rdjson/mypy_to_rdjson.py" < "${MYPYTMPDIR}/mypy_output.json" > "${MYPYTMPDIR}/mypy_rdjson.json" + + # echo "mypy output rdjson:" + # cat "${MYPYTMPDIR}/mypy_rdjson.json" + + # shellcheck disable=SC2086 + reviewdog \ + -f=rdjson \ + -name="${INPUT_TOOL_NAME:-mypy}" \ + -reporter="${INPUT_REPORTER:-github-pr-check}" \ + -filter-mode="${INPUT_FILTER_MODE}" \ + -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ + -level="${INPUT_LEVEL}" \ + ${INPUT_REVIEWDOG_FLAGS} < "${MYPYTMPDIR}/mypy_rdjson.json" \ + || reviewdog_exit_val="$?" +fi + echo '::endgroup::' # Throw error if an error occurred and fail_on_error is true