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

Allow precondition to skip with warning in addition to failing. #1991

Open
simonrouse9461 opened this issue Jan 4, 2025 · 4 comments
Open
Labels
state: needs triage Waiting to be triaged by a maintainer.

Comments

@simonrouse9461
Copy link

simonrouse9461 commented Jan 4, 2025

Description

Currently, a task will fail if any of the preconditions fails. It will be very helpful to allow a task to skip conditionally without failing.

Proposal:

tasks:
  my-task:
    preconditions:
      - test $a = 1
      - sh: test $b = 2
        action: skip
        msg: "Skip!"
      - sh: test $c = 3
        action: fail
        msg: "Fail!"
  cmds:
    - echo Hello World
  • if $a != 1, the task will fail by default.
  • if $b != 2, the task will skip with a warning "Skip!".
  • if $c != 3, the task will fail with message "Fail!".
  • if both $b != 2 and $c != 3, the task will skip instead of failing.
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Jan 4, 2025
@pd93
Copy link
Member

pd93 commented Jan 4, 2025

@simonrouse9461 Correct me if I'm wrong, but this sounds like the same functionality that would be provided by an if keyword if that were ever implemented? See #608 (2nd most upvoted feature request).

@simonrouse9461
Copy link
Author

@pd93 Yes, I'm just looking for a way to do conditional logics in task. preconditions and status are the closest things available right now. I assume allowing preconditions to skip is much easier to implement than introducing an if keyword. They almost achieve the same thing.

@trulede
Copy link

trulede commented Jan 5, 2025

@simonrouse9461 how sophisticated is your problem? You can in many cases use a simple bash IF statement in either your precondition or task commands. And toggle that behaviour with an environment variable (I did not test this, but I do similar things so I know it works):

if [ -z "${SKIP_PRECOND}" ]; then return 0; else test $c = 3; fi

Run task this way:

SKIP_PRECOND=1 task <your task>

preconditions and if statements are the same thing, clearly.

EDIT: @simonrouse9461 also, you can do the same thing with the task templating ... which might be more comfortable than the bash syntax. For example I do this type of thing often:

    vars:
        AUTH: '{{if all .USER .TOKEN}}-u {{.USER}}:{{.TOKEN}}{{else}}{{end}}'

and that type of thing also works for sh commands.

@simonrouse9461
Copy link
Author

@trulede Yeah, this is the workaround I'm using right now. But the syntax is cumbersome and doesn't give too much flexibility. Especially when the logic grows too complicated, relying on conditionals in the templating syntax makes it unreadable and hard to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs triage Waiting to be triaged by a maintainer.
Projects
None yet
Development

No branches or pull requests

4 participants