Skip to content

Commit

Permalink
fix: Update migration
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuyoshicho committed Aug 3, 2024
1 parent a5842b0 commit 980b350
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 47 deletions.
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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

Expand Down
17 changes: 14 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
Expand Down
105 changes: 70 additions & 35 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 980b350

Please sign in to comment.