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

Default mega-linter.yml workflow generated gets tripped up with ActionLinter #3025

Closed
andrewvaughan opened this issue Oct 19, 2023 · 6 comments · Fixed by #3029
Closed

Default mega-linter.yml workflow generated gets tripped up with ActionLinter #3025

andrewvaughan opened this issue Oct 19, 2023 · 6 comments · Fixed by #3029
Labels
bug Something isn't working

Comments

@andrewvaughan
Copy link
Contributor

Describe the bug

Results of actionlint linter (version 1.6.26)
See documentation on https://megalinter.io/7.4.0/descriptors/action_actionlint/
-----------------------------------------------

❌ [ERROR] for workspace /tmp/lint
Linter raw log:
.github/workflows/mega-linter.yml:184:13: if: condition "${{ success() }} || ${{ failure() }}" is always evaluated to true because extra characters are around ${{ }} [if-cond]
    |
184 |         if: ${{ success() }} || ${{ failure() }}
    |             ^~~

To Reproduce
Steps to reproduce the behavior:

  1. Run a newly-generated workflow

A clearer way to have this functionality work would be to change the line to:

  if: '!cancelled()'

This makes it clear that the Artifacts should only upload if any action was taken except cancellation. Note that the quotes are necessary so that ! isn't flagged as a YAML tag.

@andrewvaughan andrewvaughan added the bug Something isn't working label Oct 19, 2023
@andrewvaughan
Copy link
Contributor Author

One other finding - it looks like Prettier doesn't play nicely with GitHub action linting at times. It will update what I wrote above to use double-quotes, which in turn creates an error with the other linter.

A quick and dirty way to get around this is to drop usage of the curly-brackets:

  if: success() || failure()

They are not required for if statements.

@andrewvaughan
Copy link
Contributor Author

I do believe this is an incorrect lint, btw, per:

rhysd/actionlint#367

@nvuillam
Copy link
Member

if: '!cancelled()' seems elegant , it wasn't available on Github Actions when I created the workflow :)

Would u like to make a PR ? :)

@echoix
Copy link
Collaborator

echoix commented Oct 20, 2023

I'm curious to see if it really works! At the time, it used to be that a if failure() was needed in order to not be skipped when any step failed. Since cancelled() is a status check function, the note in https://docs.github.com/en/actions/learn-github-actions/expressions#failure-with-conditions might mean that it should work ;)

@andrewvaughan
Copy link
Contributor Author

I was able to use success() || failure() without the curly brackets with success and no linting errors. Again, I think this is a mistake in the linter - but it does seem like it's best practice to not use curly brackets in if: clauses, so both projects can be updated.

@andrewvaughan
Copy link
Contributor Author

if: '!cancelled()' seems elegant , it wasn't available on Github Actions when I created the workflow :)

Would u like to make a PR ? :)

I tried this, but Prettier insisted on changing this to double quotes with "!cancelled()" which caused other linting failures. To not upset the complexity that is all these opinionated linters, I think the best course of action is to simply remove the curly brackets:

if: success() || failure()

Which seems to be the recommendation, now, to not use curly-brackets in if statements.

andrewvaughan added a commit to andrewvaughan/megalinter that referenced this issue Oct 21, 2023
A mix of linters fail here, starting with actionlint throwing an
(incorrect) "... is always evaluated to true because extra characters
are around ${{ }}". I believe this is accidentally assuming the
entire statement is curly-bracket wrapped, which it isn't.

Regardless, curly brackets are not required for `if` statements in
the YAML, and can be removed. A best-practice approach would be
changing this to the newer '!cancelled()' flag, which does the same
thing, but this will throw errors when Prettier ultimately changes
the single-quotes to double-quotes and breaks the statement.

As such, the best course of action is to simply remove the curly-
brackets from the existing statement to satisfy Checkov and prevent
linting errors in the default-generated file.
nvuillam pushed a commit that referenced this issue Oct 21, 2023
* Fix: Removed curly-brackets from if (closes #3025)

A mix of linters fail here, starting with actionlint throwing an
(incorrect) "... is always evaluated to true because extra characters
are around ${{ }}". I believe this is accidentally assuming the
entire statement is curly-bracket wrapped, which it isn't.

Regardless, curly brackets are not required for `if` statements in
the YAML, and can be removed. A best-practice approach would be
changing this to the newer '!cancelled()' flag, which does the same
thing, but this will throw errors when Prettier ultimately changes
the single-quotes to double-quotes and breaks the statement.

As such, the best course of action is to simply remove the curly-
brackets from the existing statement to satisfy Checkov and prevent
linting errors in the default-generated file.

* Added changelog entry

---------

Co-authored-by: Edouard Choinière <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants