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

[feature] add conditional tasks #1666

Open
piotrkowalczuk opened this issue Sep 29, 2024 · 0 comments
Open

[feature] add conditional tasks #1666

piotrkowalczuk opened this issue Sep 29, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@piotrkowalczuk
Copy link

piotrkowalczuk commented Sep 29, 2024

Is your feature request related to a problem? Please describe.
I want to be able to skip a task if the codebase does not meet the given criteria at the execution time. For example, in Go, one might want to create a task that executes go generate. The output files are known and should be defined. What's unknown is whether the given project has any //go:generate annotation in its codebase.

tasks:
  generate:
    command: 'go generate ./...'
    inputs:
      - '**/*.go'
      - 'go.mod'
      - '/go.mod'
    outputs:
      - '**/*_templ.go'

This task will produce error if run against Go project without any //go:generate templ generate ./... annotation:

Error: task_runner::missing_outputs

  × Task foo-bar:generate defines outputs but after being ran, either none or not all of them exist.
  │ If you require optional outputs, try using glob patterns instead.

Describe the solution you'd like

Having additional property condition in the Task schema. Value of this field could a simple bash script.

Bash

tasks:
  generate:
    condition: |
      if output=$(go generate -n ./... 2>&1 1>/dev/null); then
        if [[ -n "$output" ]]; then
            exit 1
        else
            exit 0
        fi
      fi

    command: 'go generate ./...'
    inputs:
      - '**/*.go'
      - 'go.mod'
      - '/go.mod'
    outputs:
      - '**/*.pb.go'
      - '**/*_templ.go'

Describe alternatives you've considered

Additional context

@piotrkowalczuk piotrkowalczuk added the enhancement New feature or request label Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant