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 · 2 comments · May be fixed by #1146
Open

Use sources as variable #948

NVolcz opened this issue Dec 5, 2022 · 2 comments · May be fixed by #1146
Labels
good first issue Issues that are good for first-time contributors to pick up. type: enhancement A change to an existing feature or functionality.

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 type: enhancement A change to an existing feature or functionality. 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}}'

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. type: enhancement A change to an existing feature or functionality.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants