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

Set exit_code correctly as output #245

Merged
merged 5 commits into from
Sep 29, 2024
Merged

Conversation

sebastiaanspeck
Copy link
Contributor

Fixes #244

@mre
Copy link
Member

mre commented Sep 27, 2024

Thanks! Can you also add a test which checks that the exit code works to https://github.com/lycheeverse/lychee-action/blob/master/.github/workflows/test.yml?

Something like that:

      - name: Test exit code output (expecting failure)
        id: lychee_exit_test
        uses: ./
        with:
          args: -- inputdoesnotexist
        continue-on-error: true

      - name: Check exit code
        run: |
          echo "Lychee exit code: ${{ steps.lychee_exit_test.outputs.exit_code }}"
          if [[ "${{ steps.lychee_exit_test.outputs.exit_code }}" == "1" ]]; then
            echo "Lychee correctly failed with exit code 1"
          else
            echo "Unexpected exit code: ${{ steps.lychee_exit_test.outputs.exit_code }}"
            echo "Expected exit code 1 for failed check"
            exit 1
          fi

@mre
Copy link
Member

mre commented Sep 29, 2024

I think we need to test if lychee failed with an exit code other than 0 in case of error. Right now you're testing for 0, which is the default and should always work because otherwise the GitHub workflow stops. Did you try the code snippet I posted? 🤔

Copy link
Member

@mre mre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm thanks!

@mre mre merged commit 22c8e46 into lycheeverse:master Sep 29, 2024
3 checks passed
@kdeldycke kdeldycke mentioned this pull request Oct 9, 2024
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.
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 <12570668+sebastiaanspeck@users.noreply.github.com>
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.

${{ steps.lychee.outputs.exit_code }} is not set correctly
2 participants