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

test: test fail-argument #251

Closed
wants to merge 5 commits into from

Conversation

sebastiaanspeck
Copy link
Contributor

No description provided.

@sebastiaanspeck
Copy link
Contributor Author

This PR demonstrates that setting fail to false does not work ATM.

@YDX-2147483647
Copy link
Contributor

YDX-2147483647 commented Nov 5, 2024

The cause of this issue is trivial: $INPUT_FAIL gets changed to true because of failIfEmpty: true, which is the default. The line INPUT_FAIL=true was introduced in #86.

# Overwrite the exit code in case no links were found
# and `failIfEmpty` is set to `true` (and it is by default)
if [ "${INPUT_FAILIFEMPTY}" = "true" ]; then
# Explicitly set INPUT_FAIL to true to ensure the script fails
# if no links are found
INPUT_FAIL=true

lychee-action/action.yml

Lines 17 to 19 in ae46991

failIfEmpty:
description: "Fail entire pipeline if no links were found"
default: true

To verify it, I set failIfEmpty: false to the step in test.yml, and now it does pass. Directly adding echo "$INPUT_FAIL" also confirms it.

  - name: test disable fail - it's okay if we fail
    uses: ./
    with:
      args: --no-progress foo.bar
      fail: false
+     failIfEmpty: false

Thanks https://github.com/nektos/act for making it a lot easier to debug.

Possible fix

Document this behaviour, or edit entrypoint.sh:

	# Overwrite the exit code in case no links were found
	# and `failIfEmpty` is set to `true` (and it is by default)
	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
+	        # Explicitly set INPUT_FAIL to true to ensure the script fails
+	        # if no links are found
+	        INPUT_FAIL=true
	    fi
	fi

I can make a PR if wanted.

@mre
Copy link
Member

mre commented Nov 5, 2024

Thanks for the investigation. I'm all for changing the code here. The way I see it,

  • If fail: false and failIfEmpty is not set, don't fail if the status code is not 0 but fail if links were found.
  • If fail is not set, and failIfEmpty: false, fail if the status code is not 0 but don't fail if there are no links.
  • If none is set, use the defaults: fail if the status code is not 0 or no links were found.

Please correct me if I'm wrong.

I'd appreciate a pull request.

YDX-2147483647 added a commit to YDX-2147483647/lychee-action that referenced this pull request Nov 5, 2024
This commit also makes sure `outputs.exit_code` is “The exit code returned from Lychee”. `failIfEmpty` no longer changes it to `1`.

Relevant docs:
- [Setting exit codes for actions - GitHub Docs](https://docs.github.com/en/actions/sharing-automations/creating-actions/setting-exit-codes-for-actions)
- [exit - POSIX Programmer's Manual](https://manned.org/exit.1posix)

Relates to lycheeverse#86, lycheeverse#128, lycheeverse#145, lycheeverse#245, and lycheeverse#251.
YDX-2147483647 added a commit to YDX-2147483647/lychee-action that referenced this pull request Nov 5, 2024
This commit also makes sure `outputs.exit_code` is “The exit code returned from Lychee”. `failIfEmpty` no longer changes it to `1`.

Relevant docs:
- [Setting exit codes for actions - GitHub Docs](https://docs.github.com/en/actions/sharing-automations/creating-actions/setting-exit-codes-for-actions)
- [exit - POSIX Programmer's Manual](https://manned.org/exit.1posix)

Relates to lycheeverse#86, lycheeverse#128, lycheeverse#145, lycheeverse#245, and lycheeverse#251.
YDX-2147483647 added a commit to YDX-2147483647/lychee-action that referenced this pull request Nov 5, 2024
This commit also makes sure `outputs.exit_code` is “The exit code returned from Lychee”. `failIfEmpty` no longer changes it to `1`.

Relevant docs:
- [Setting exit codes for actions - GitHub Docs](https://docs.github.com/en/actions/sharing-automations/creating-actions/setting-exit-codes-for-actions)
- [exit - POSIX Programmer's Manual](https://manned.org/exit.1posix)

Relates to lycheeverse#86, lycheeverse#128, lycheeverse#145, lycheeverse#245, and lycheeverse#251.
YDX-2147483647 added a commit to YDX-2147483647/lychee-action that referenced this pull request Nov 5, 2024
This commit also makes sure `outputs.exit_code` is “The exit code returned from Lychee”. `failIfEmpty` no longer changes it to `1`.

Relevant docs:
- [Setting exit codes for actions - GitHub Docs](https://docs.github.com/en/actions/sharing-automations/creating-actions/setting-exit-codes-for-actions)
- [exit - POSIX Programmer's Manual](https://manned.org/exit.1posix)

Relates to lycheeverse#86, lycheeverse#128, lycheeverse#145, lycheeverse#245, and lycheeverse#251.
@YDX-2147483647
Copy link
Contributor

Maybe this PR can be merged first?
If #262 needs more tests, but this PR is not merged, then there will be a merge conflict later.

@mre
Copy link
Member

mre commented Nov 6, 2024

Maybe this PR can be merged first?

Do you mean this PR? (251)

Because it currently fails.
I checked out your PR (#262) and that passes and seems to fix the issue, no? I think we can close this one (251) and merge yours. Or am I missing something?

@mre
Copy link
Member

mre commented Nov 6, 2024

Ah, I think I understand now. Can you merge the changes of this PR into your branch? Then we have all changes (including a passing test) in one pull request. I prefer that, because it's a single atomic change and we can make sure it works. I'd rather not merge a change if the pipeline is red. 😉

YDX-2147483647 pushed a commit to YDX-2147483647/lychee-action that referenced this pull request Nov 6, 2024
Edited from lycheeverse#251.

Co-Authored-By: Sebastiaan Speck <[email protected]>
mre pushed a commit that referenced this pull request Nov 7, 2024
-   **fix: Make `fail: false` effective even when `failIfEmpty: true`**

This commit also makes sure `outputs.exit_code` is “The exit code returned from Lychee”. `failIfEmpty` no longer changes it to `1`.

Relevant docs:
- [Setting exit codes for actions - GitHub Docs](https://docs.github.com/en/actions/sharing-automations/creating-actions/setting-exit-codes-for-actions)
- [exit - POSIX Programmer's Manual](https://manned.org/exit.1posix)

Relates to #86, #128, #145, #245, and #251.

-   **fix: Update `env.exit_code` to `outputs.exit_code`**

The previous expression always gives `false`.
Both `env.exit_code` and `env.lychee_exit_code` are `null`, probably since the docker→composite refactor #128. When GitHub evaluates the expression, it finds the types do not match, and coerces them to number, namely, `null` → `0`.

See [Evaluate expressions in workflows and actions - GitHub Docs](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#operators).

Relates to #253.



Co-authored-by: Sebastiaan Speck <[email protected]>
@mre
Copy link
Member

mre commented Nov 7, 2024

@sebastiaanspeck, this PR got merged as part of #262 by @YDX-2147483647.
Good work by both of you. 🎉

@mre mre closed this Nov 7, 2024
@sebastiaanspeck sebastiaanspeck deleted the patch-1 branch November 7, 2024 06:19
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

Successfully merging this pull request may close these issues.

3 participants