NegativeStatusCheck
¶
Use positive conditions.
Defined by ImplicitStatusCheckRule
which supports workflows, actions in the "Default" ruleset along with NeverUseAlways
.
Description¶
Using a negated status check function is confusing. Being explicit helps in understanding the intent of the condition.
If someone has read the documentation, they might understand what !failure()
actually means,
but being explicit comes at almost no cost and helps everyone immediately understand the intent:
if: ${{ success() || cancelled() }}
Aside: In the unlikely event that GitHub introduces a new status check function, half of the negative usages will get invalid. You never know if your condition will be in the right half.
References:
Note the documentation recommends:
If you want to run a job or step regardless of its success or failure, use the recommended alternative:
if: ${{ !cancelled() }}
-- Documentation
but I strongly believe if you want to "run a job or step regardless of its success or failure",
use if: ${{ success() || failure() }}
, it's much clearer, isn't it?
Compliant example¶
if:
condition is explicitly stating the statuses to run on.
example.yml
on: push jobs: example: runs-on: ubuntu-latest steps: - run: echo "Something that could fail." - uses: actions/upload-artifact@v0 if: ${{ success() || failure() }}
Non-compliant example¶
if:
condition uses !
to negate a status check function.
example.yml
on: push jobs: example: runs-on: ubuntu-latest steps: - run: echo "Something that could fail." - uses: actions/upload-artifact@v0 if: ${{ !cancelled() }}
- Line 8: Step[actions/upload-artifact@v0] in Job[example] uses a negative condition.