Task: Having preconditions without fail

Created on 11 Dec 2019  ·  3Comments  ·  Source: go-task/task

In order to make a project dependencies update tools, I'm interested by the preconditions options.

It allow me to run the different dependencies managers if the condition are met:

version: '2'

silent: true

tasks:
  default:
    deps:
      - composer
      - npm

  composer:
    preconditions:
      - test -f composer.lock
    cmds:
      - composer update

  npm:
    preconditions:
      - test -f package-lock.json
    cmds:
      - npm update

But the way this option is working does not fit my needs. It fail immediately if one of the task as unmet condition:

❯ task
task: `test -f package-lock.json` failed
task: `test -f composer.lock` failed
task: precondition not met
❯ touch composer.lock
❯ task
task: `test -f package-lock.json` failed
task: precondition not met

I didn't find any option to solve this issue, so I guess it was designed for.

Would you consider an evolution about this?

Regards

feature

Most helpful comment

Hi @soullivaneuh, thanks for opening this issue!

I'd say preconditions was specifically designed to explicitly fail when the condition isn't met.

Perhaps if we introduced a new keywords called something like skip_if it'd be clearer?

All 3 comments

I found a workaround using ignore_error:

composer:
  ignore_error: true
  cmds:
    - test -f composer.lock && composer update

npm:
  ignore_error: true
  cmds:
    - test -f package-lock.json && npm update

But this is not ideal, because I won't have any feedback if the task really fails.

Hi @soullivaneuh, thanks for opening this issue!

I'd say preconditions was specifically designed to explicitly fail when the condition isn't met.

Perhaps if we introduced a new keywords called something like skip_if it'd be clearer?

Hi @andreynering and sorry for the delay.

Yes, this is perfectly what I'm looking for! It would be a great addition, opening multiple possibilities to go-task.

Smart CI jobs can be written this way for example. :+1:

If you want to learn more, here is the project I'm setting up : https://gitlab.com/nexylan/kmi/merge_requests/1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fj picture fj  ·  4Comments

smyrman picture smyrman  ·  8Comments

moritzheiber picture moritzheiber  ·  3Comments

andreynering picture andreynering  ·  7Comments

marco-m picture marco-m  ·  5Comments