T
Task2mo ago
bennie

sources from dynamic list of files

Is there a way to specify the sources of a task from a dynamic list of files? I'm builing a collection of reusable tasks in a monorepo and many of them accept a list of files to operate on. This list could be from the output of find or ripgrep or something similar. These tasks accept a FILES variable which I'm able to manipulate into the proper format for use in the task command. I'm unable, however, to set the sources of the task based on this variable. To be clear, the list of files is something like ['file1.txt', 'file2.txt', 'file3.txt']. It is not a pattern, and it is not fixed length. It seems that setting sources to a dynamic list of files in any intuitive way is impossible. Intuitive ways that don't work: a) Setting sources directly equal to a dynamic list:sources: '{{.MY_ARRAY}}. b) Expanding individual items of sources into multiple files, similar to how a pattern is expanded. b.i) By allowing the items to be arrays instead of just strings, similar to (a) but one level deeper. b.ii) By allowing multiple patterns per item separated by, e.g., newlines or null-bytes. Currently I'm resorting to building a massive string like {file1.txt,file2.txt,file3.txt} but even with this I'm encountering some annoying corner cases. And honestly at this point things are getting a bit silly. Am I just missing something obvious? Any advice?
6 Replies
andreynering
andreynering2mo ago
Hi @bennie! I totally see how this would be useful to you. Can you open a feature request issue on GitHub to track this? Can be mostly a copy of your post here.
bennie
bennieOP2mo ago
Hi @andreynering Thanks for your quick response! I'll open the issue and report back here. Btw, there is another little annoyance I've encountered (in an otherwise awesome tool). Should I describe it here or in a new thread? Or just open an issue for it directly?
andreynering
andreynering2mo ago
You can tell me here. If relevant, we can then open an issue to track it.
bennie
bennieOP2mo ago
GitHub
Specify task sources from dynamic list of files · Issue #2483 ·...
Description It would be extremely useful to be able to specify the sources of a task from a dynamic list of files. I'm builing a collection of reusable tasks in a monorepo and many of them acce...
bennie
bennieOP2mo ago
I've got a bunch of individual linting tasks (lint:eslint, lint:yamllint, lint:pylint etc) that I'm combining under one lint task, something like this:
tasks:
lint:
deps:
- lint:eslint
- lint:yamllint
- lint:pylint
tasks:
lint:
deps:
- lint:eslint
- lint:yamllint
- lint:pylint
The lint task differs slightly from normal tasks in that I want all its deps to run to completion and then the lint task should pass/fail as a whole. What currently ends up happening is that all remaining deps' tasks are aborted the moment the first one fails. For example, if lint:yamllint would report errors after 5s, but lint:eslint fails after 2s, then the output from lint:yamllint is never shown. If errors on the lint:* tasks are suppressed using ignore_error: true, then the exit status from task lint is 0 even if it failed, which is wrong. I tried using ignore_error: true on the deps and adding a command to the lint task to run after all deps and fail if any dep failed, but getting this info does not seem possible. So currently I'm resorting to a workaround where each lint:* task has ignore_error: true and stores its pass/fail state in a temporary file and then the main lint task has a final command which checks these files to fail if necessary. Is there an easier way to achieve what I'm trying to do?
andreynering
andreynering2mo ago
I'm afraid this is not possible to achieve currently, as you said. I think there may be a couple of feature requests in this area already. You can make a quick search maybe. If you don't find it, you're welcome to open a new issue.

Did you find this page helpful?