Skip to content
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

Cleanup never runs if reviewdog fails making cleanup behaviour appear incorrect compared to intention #53

Open
electrofelix opened this issue Apr 5, 2024 · 1 comment

Comments

@electrofelix
Copy link

The action script contains set -e which tells bash to exit if any command fails:

Further down however it expects to be able to capture the exit code of executing the reviewdog binary:

EXIT_CODE=$?

But any non zero code would cause a termination before reaching that line.

Essentially the following might give the impression that some cleanup is done if the reviewdog command fails, but it's not, if the exit code is anything other than 0, the following block never gets run:

EXIT_CODE=$?

if [ "${INPUT_CLEANUP}" = "true" ]; then
  git stash drop || true
else
  git stash pop || true
fi

exit "${EXIT_CODE}"

Previously there was an || EXIT_CODE=$? that was removed as part of https://github.com/reviewdog/action-suggester/pull/31/files but this doesn't see correct if errexit is set

Instead it would appear that the command should use an && as well as an || to capture the exit code on the same line and ensure the line exit code is 0:

reviewdog \
  -name="${INPUT_TOOL_NAME:-reviewdog-suggester}" \
  -f=diff \
  -f.diff.strip=1 \
  -reporter="github-pr-review" \
  -filter-mode="${INPUT_FILTER_MODE}" \
  -fail-on-error="${INPUT_FAIL_ON_ERROR}" \
  -level="${INPUT_LEVEL}" \
  ${INPUT_REVIEWDOG_FLAGS} <"${TMPFILE}" && EXIT_CODE=$? || EXIT_CODE=$?
@haya14busa
Copy link
Member

Can you create a pr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants