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

Global preconditions #405

Closed
duboiss opened this issue Nov 16, 2020 · 10 comments
Closed

Global preconditions #405

duboiss opened this issue Nov 16, 2020 · 10 comments
Labels
state: duplicate Duplicates another issue.

Comments

@duboiss
Copy link

duboiss commented Nov 16, 2020

I'm new with Taskfile. I start to write my first Taskfile.yaml and I realize a serious problem : preconditions.
It's a great option but from what I see we can't store a precondition so I have several duplications.

It would be nice if we can have something similar to:

# Global preconditions available for all tasks
preconditions:
    my-first-condition:
        - sh: "[ 1 = 0 ]"
        msg: "One doesn't equal Zero, Halting"

    my-second-condition:
        - sh: "[ 1 = 0 ]"
        msg: "One doesn't equal Zero, Halting"

tasks:
    my-first-task:
        # ...
        preconditions:
            - precondition: my-first-condition
            - precondition: my-second-condition

So like when you reference a task to be executed in a task. Or if you have a better idea...

@andreynering andreynering added the type: feature A new feature or functionality. label Dec 27, 2020
@andreynering
Copy link
Member

Hi @duboiss,

This sounds like a good idea, but I have no plans to implement that soon...

@DanyHenriquez
Copy link

DanyHenriquez commented Jan 19, 2021

I will check this one out to see if i can add it with the code in the repo now.

@andreynering Will you accept a PR for this or would that be planned later and you can't accept a PR even if there was one?

Is so then you can assign me :)

@andreynering
Copy link
Member

Hi @DanyHenriquez,

I'm not sure. This is not trivial to implement so it may need some thought first. Also, there are other priorities for now.

@chermed
Copy link

chermed commented Mar 20, 2021

@andreynering @duboiss
Based on my case, I have a project that use a lot of Taskfiles under Taskfile.d for command like task service:list ..., task project:list ..., task acount:list ..., etc and the problem is that we can't share the preconditions or even tasks between (namespaces).

So I suggest, if there will be PR for that to consider a more global preconditions like global:precondition-1, global:precondition-2 etc

Example:

version: '3'

tasks:
  build:
    deps: 
      - global:precondition-1            # << precondition 1
    cmds:
      - go build -v -i main.go
    preconditions:
       - task: global:precondition-2   # << precondition 2

@DanyHenriquez
Copy link

@andreynering Hit me up and let me know where you need help

@DanyHenriquez
Copy link

Cleaning up my queue. Unfollowing since i don't know the status or if help is needed. Let me know if this changes 😄

@marco-m-pix4d
Copy link
Contributor

Looks like a duplicate of #294.

@sylv-io
Copy link
Contributor

sylv-io commented Oct 6, 2021

There is a way to reuse preconditions by the use of YAML anchors:

tasks:

  task1:
    cmds:
      - "echo task1"
    preconditions:
      - &test-precondition
        sh: "[ 1 = 0 ]"
        msg: "One doesn't equal Zero, Halting"

  task2:
    cmds:
      - "echo task2"
    preconditions:
      - *test-precondition

  task3:
    cmds:
      - "echo task3"
    preconditions:
      - *test-precondition

The anchor have to be on the same YAML file.
Adding global preconditions (e.g. #294) would only reduse duplications, if they are used on multiple imported taskfiles.

However we could reference YAML anchors in the documentation 👍

@sylv-io
Copy link
Contributor

sylv-io commented Oct 6, 2021

Since we do not use strict YAML unmarshal, even this is possible:

preconditions:
  <<: &test-precondition
    sh: "[ 1 = 0 ]"
    msg: "One doesn't equal Zero, Halting"

tasks:

  task1:
    cmds:
      - "echo task1"
    preconditions:
      - *test-precondition

  task2:
    cmds:
      - "echo task2"
    preconditions:
      - *test-precondition

  task3:
    cmds:
      - "echo task3"
    preconditions:
      - *test-precondition

@pd93 pd93 removed the v4 label Oct 15, 2022
@pd93
Copy link
Member

pd93 commented Oct 15, 2022

Duplicate of #294

@pd93 pd93 marked this as a duplicate of #294 Oct 15, 2022
@pd93 pd93 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 15, 2022
@pd93 pd93 added the state: duplicate Duplicates another issue. label Oct 15, 2022
@pd93 pd93 removed the type: feature A new feature or functionality. label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: duplicate Duplicates another issue.
Projects
None yet
Development

No branches or pull requests

8 participants