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

Use sources as variable #948

Open
NVolcz opened this issue Dec 5, 2022 · 3 comments · May be fixed by #1146
Open

Use sources as variable #948

NVolcz opened this issue Dec 5, 2022 · 3 comments · May be fixed by #1146
Labels
good first issue Issues that are good for first-time contributors to pick up.

Comments

@NVolcz
Copy link

NVolcz commented Dec 5, 2022

For a task, is the list of files specified in sources available for commands so it can be used as a variable?
I have a script that that I would like to pass the list of sources available to:

version: '3'

tasks:
  test:
    cmds:
      - echo {{.sources}}
      - ./test/shellcheck.sh {{.sources}}
    sources:
      - *.sh

Alternatively if it was possible to use vars for sources:

version: '3'

tasks:
  test:
    cmds:
      - echo {{.sources}}
      - ./test/shellcheck.sh {{.sources}}
    vars:
      SCRIPTS:
        sh: find . -iname '*.sh' -not -path './cygwin/*' | xargs echo
    sources:
      - {{.BASH_SCRIPTS}}
@github-actions github-actions bot added the state: needs triage Waiting to be triaged by a maintainer. label Dec 5, 2022
@andreynering andreynering added enhancement good first issue Issues that are good for first-time contributors to pick up. and removed state: needs triage Waiting to be triaged by a maintainer. labels Dec 6, 2022
@andreynering
Copy link
Member

Hi @NVolcz,

This indeed makes sense, because we already have other special variables like TASK, TIMESTAMP and CHECKSUM.

Implementation note: this variable should probably be an array (slice) because them users will have more flexibility on what to do with it (join with space or ,, loop through it, or other). TIMESTAMP is already of a different type (time.Time).

@jlucktay
Copy link

jlucktay commented Oct 4, 2023

I think this might help with a use-case I'm looking at now.
I discover go.mod files and put the results into a GO_MODULES variable at the top level of Taskfile.yaml.
Then there are tasks using cmds.for.var to execute something in each of the GO_MODULES directories.
I would like the tasks to be able to look at sources with globs relative to each of the GO_MODULES items as each iteration of the for loops run.

edit: never mind, a colleague came up with a pattern for what I want to do that works quite well as-is:

  do-thing:singular:
    desc: Run a single thing
    requires:
      vars:
        - THING
    sources:
      - 'subdir/{{.THING}}/**/*.{go,mod,sum}'
    cmds:
      - task: gotest
        vars:
          GOTESTVAR: './subdir/{{.THING}}/...'

  do-thing:plural:
    desc: Run several things
    requires:
      vars:
        - THINGS
    cmds:
      - for: { var: THINGS }
        task: do-thing:singular
        vars:
          THING: '{{.ITEM}}'

@callegar
Copy link

callegar commented Jun 4, 2024

Wonder if this is the only possible solution. May I suggest:

  • having a way to define array variables by the same glob mechanism that is now possible with sources, maybe with a suitable template function.
  • having a way to use array variables for sources.

IMHO this would be more flexible since it would let any variable be usable based on filename expansion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues that are good for first-time contributors to pick up.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants