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

feat: add option to declare an included Taskfile as flatten #1704

Merged
merged 9 commits into from
Aug 26, 2024

Conversation

vmaerten
Copy link
Member

@vmaerten vmaerten commented Jul 1, 2024

It's one of the most upvoted feature ! So I gave it a try

Closes : #273

@vmaerten vmaerten marked this pull request as ready for review July 1, 2024 17:54
Copy link

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please accept my humble code review

.editorconfig Outdated Show resolved Hide resolved
task_test.go Outdated Show resolved Hide resolved
task_test.go Outdated Show resolved Hide resolved
taskfile/ast/taskfile.go Outdated Show resolved Hide resolved
@vmaerten
Copy link
Member Author

vmaerten commented Jul 1, 2024

Thanks a lot @ccoVeille for your review. I've done all fixes in one commit

@ccoVeille
Copy link

You are welcome

Copy link
Member

@andreynering andreynering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @vmaerten, thanks for working on this!

I noticed a bug: dir: is not being respected on includes: when flatten: true is given.

version: '3'

tasks:
  pwd:
    desc: Print working directory
    cmds:
      - pwd
includes:
  included:
    taskfile: ./TaskfileIncluded.yml
    dir: ./website
    flatten: true

With flatten: true, it prints the root directory instead of the specified one (dir: ./website in my example).

Also @pd93 mentioned here (#273 (comment)) that he has refactors in mind that could affect this work. Worth getting an opinion before merging.

@vmaerten
Copy link
Member Author

vmaerten commented Jul 5, 2024

Thank @andreynering for the review. I've forgot the AdvancedImport's part
It's now fixed and work as intended. Let me know if there are some usecase I've forgotten

@elocke
Copy link

elocke commented Jul 16, 2024

Thank @andreynering for the review. I've forgot the AdvancedImport's part It's now fixed and work as intended. Let me know if there are some usecase I've forgotten

Awesome to see this feature in a PR, I've been eager to build something with this.

An usecase that I would benefit from, would be if I could specify override as an option to flatten. If set, the inheriting Taskfile's cmd would take precedence over the included files set to flatten. I could then provide sets of Task "templates" but my users could override specific cmds if they need to.

@vmaerten
Copy link
Member Author

Thank @andreynering for the review. I've forgot the AdvancedImport's part It's now fixed and work as intended. Let me know if there are some usecase I've forgotten

Awesome to see this feature in a PR, I've been eager to build something with this.

An usecase that I would benefit from, would be if I could specify override as an option to flatten. If set, the inheriting Taskfile's cmd would take precedence over the included files set to flatten. I could then provide sets of Task "templates" but my users could override specific cmds if they need to.

I agree but for now, I would keep this feature as simple as possible
We can iterate through this after ffc

Copy link
Member

@pd93 pd93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also @pd93 mentioned here (#273 (comment)) that he has refactors in mind that could affect this work. Worth getting an opinion before merging.

I have some WIP code that removes the merging altogether. This feature will need to be reworked into that at some point. However, I've not had the time to work on it recently and I don't see any reason to delay this functionality given its popularity.

The PR seems well thought out and reimplementing it if merging is removed should be simple enough.

1 minor comment, but otherwise happy. Thanks for working on this @vmaerten! 🚀

}

func (err *TaskNameFlattenConflictError) Error() string {
return fmt.Sprintf(`task: Found multiple tasks (%s) included by "%s""`, err.TaskName, err.Include)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error is also returned when a task in a child taskfile conflicts with one in a parent taskfile (as opposed to two children taskfiles). We could improve the message to include those cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think about CodeTaskNameConflict or another one ?
At first I used CodeTaskNameConflict but I found more readable to distinct both. That being said, it would make sense, so I'll give a try to adjust the message

@vmaerten vmaerten changed the title feat: add flatten task feat: add option to declare an included Taskfile as flatten Aug 26, 2024
@vmaerten vmaerten merged commit ef3b853 into go-task:main Aug 26, 2024
14 checks passed
@vmaerten vmaerten deleted the feat/flatten branch August 26, 2024 21:17
vmaerten added a commit that referenced this pull request Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to 'flatten' included taskfiles
5 participants