-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Fix bugs about the exit code #262
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
#!/bin/bash -l | ||
set -uo pipefail | ||
|
||
# We use ‘set +e’ to prevent the script from exiting immediately if lychee fails. | ||
# This ensures that: | ||
# 1. Lychee exit code can be captured and passed to subsequent steps via `$GITHUB_OUTPUT`. | ||
# 2. This step’s outcome (success/failure) can be controlled according to inputs | ||
# by manually calling the ‘exit’ command. | ||
set +e | ||
|
||
# Enable optional debug output | ||
if [ "${INPUT_DEBUG}" = true ]; then | ||
echo "Debug output enabled" | ||
|
@@ -29,19 +36,17 @@ fi | |
|
||
# Execute lychee | ||
eval lychee ${FORMAT} --output ${LYCHEE_TMP} ${ARGS} | ||
exit_code=$? | ||
LYCHEE_EXIT_CODE=$? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I change it to uppercase to imply the variable is immutable and does not describe the exit code of |
||
|
||
# Overwrite the exit code in case no links were found | ||
# and `failIfEmpty` is set to `true` (and it is by default) | ||
# If no links were found and `failIfEmpty` is set to `true` (and it is by default), | ||
# fail with an error later, but leave lychee exit code untouched. | ||
should_fail_because_empty=false | ||
if [ "${INPUT_FAILIFEMPTY}" = "true" ]; then | ||
# Explicitly set INPUT_FAIL to true to ensure the script fails | ||
# if no links are found | ||
INPUT_FAIL=true | ||
# This is a somewhat crude way to check the Markdown output of lychee | ||
if grep -E 'Total\s+\|\s+0' "${LYCHEE_TMP}"; then | ||
echo "No links were found. This usually indicates a configuration error." >> "${LYCHEE_TMP}" | ||
echo "If this was expected, set 'failIfEmpty: false' in the args." >> "${LYCHEE_TMP}" | ||
exit_code=1 | ||
should_fail_because_empty=true | ||
fi | ||
fi | ||
|
||
|
@@ -67,12 +72,16 @@ if [ "${INPUT_FORMAT}" == "markdown" ]; then | |
fi | ||
fi | ||
|
||
# Pass lychee exit code to next step | ||
echo "exit_code=$exit_code" >> $GITHUB_OUTPUT | ||
# Pass lychee exit code to subsequent steps | ||
echo "exit_code=$LYCHEE_EXIT_CODE" >> "$GITHUB_OUTPUT" | ||
|
||
# If `fail` is set to `true` (and it is by default), propagate the real exit | ||
# value to the workflow runner. This will cause the pipeline to fail on | ||
# `exit != # 0`. | ||
if [ "$INPUT_FAIL" = true ] ; then | ||
exit ${exit_code} | ||
# Determine the outcome of this step | ||
# Exiting with a nonzero value will fail the pipeline, but the specific value | ||
# does not matter. (GitHub does not share it with subsequent steps for composite actions.) | ||
if [ "$should_fail_because_empty" = true ] ; then | ||
# If we decided previously to fail because no links were found, fail | ||
exit 1 | ||
elif [ "$INPUT_FAIL" = true ] ; then | ||
# If `fail` is set to `true` (and it is by default), propagate lychee exit code | ||
exit ${LYCHEE_EXIT_CODE} | ||
fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@YDX-2147483647, this seems to have led to a false-positive issue creation here: #264
Note that there were no issues with the check run, but it still created the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry… I guess
${{ steps.lychee.outputs.exit_code }} != 0
evaluates to"0 != 0"
(a string), and becomestrue
when GitHub coerces its type.So it should be
if: steps.lychee.outputs.exit_code != 0
orif: ${{ steps.lychee.outputs.exit_code != 0 }}
. Not sure, however. I'll test it in my own repo later (in one or two days).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have just tested it, and it works for both success and failure. Please see #265.