Skip to content

Conditional inclusions #2880

@hookenz

Description

@hookenz

Description

There is a nice little feature that you support currently is preconditions.

e.g.

preconditions:
      - sh: "[ ! -f /.dockerenv ]"
        msg: "Run this from the host, not inside the devcontainer."

It would be cool to apply this to an include. For example, so I can how some tasks apply only to the task when running inside a devcontainer. Or alternatively outside a devcontainer.

Or apply to whatever precondition you define.

e.g.

includes:
  preconditions:
      - sh: "[ ! -f /.dockerenv ]"
        msg: "Run this from the host, not inside the devcontainer."
  lib:
    taskfile: ./Included.yml
    flatten: true

Unless you have a better alternative idea or is there something I can do to make this work regardless?

And why would I want to do this you ask?

Well in situations like these:

  dev:
    desc: Run dev containers (run from host, not inside devcontainer)
    preconditions:
      - sh: "[ ! -f /.dockerenv ]"
        msg: "Run this from the host, not inside the devcontainer.  The dev servers should already be running."
    cmds:
      - docker compose up --build

I'd like to hide the "dev" option or make it not even available or even show up in the help if the precondition is false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for support.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions