- Notifications
You must be signed in to change notification settings - Fork139
Description
Context
In a CI environment I want to structure the output and reduce the noise by defining collapsible output sections. This is a feature supported byGitlab,Travis CI,Azure Pipelines,TeamCity andJenkins (via Plugin)
Problem
I want to wrap every cargo-make task into such a section to structurize my CI output log.
Looking through the documentation I didn't find an easy way to define such pre- and post-steps for every task.
The workarounds I found were not very satisfying and quite clunky. The best solution I found, was to define a base task, which echos the section markers in it's pre and post scripts and extend from it:
[tasks.sections]script.pre ='''print_section_start.sh "$SECTION_NAME"'''script.main =""script.post ='''print_section_end.sh'''[tasks.build]extend ="sections"env = {"SECTION_NAME" ="build"}script.main ="cargo build"[tasks.test]extend ="sections"env = {"SECTION_NAME" ="test"}script.main ="cargo test"
As it get's obvious, for this very tiny requirement I need to redefine everything, which cargo-make otherwise ships out of the box. I either have very limit section support or I lose many of cargo-makes features.
Proposal
It would be nice, if I could extend tasks globally with some hook definition. I imagine something like this:
[config]pre_hook ="section_start"post_hook ="section_end"[tasks.section_start]# Idea: Hooks are only called for public tasks to avoid recursionprivate =true# By default $HOOK_CALLER is set to the name of the actual taskscript ='''echo "Start: $HOOK_CALLER"'''[tasks.section_end]private =truescript ='''echo "Finished: $HOOK_CALLER"'''[tasks.with_customized_hook]pre_hook ="custom_hook"post_hook ="custom_hook"script ="echo\"Customized\""[tasks.custom_hook]command ="echo"args = ["Wrap","$HOOK_CALLER"]
The output would then look like this:
$ cargo make buildStart: build# ... cargo build outputEnd: build$ cargo make with_customized_hookStart: Wrap with_customized_hook CustomizedEnd: Wrap with_customized_hookAs a shorthand it would be convenient to be able to define scripts directly to overwrite hooks.
[tasks.with_customized_hook_scripts]pre_hook.script ="echo\"special pre step\""post_hook.script ="echo\"special post step\""
I could imagine, there are also other interesting use cases for such hooks, besides section markers, e.g. performance analysis. Is this feature something, that would fit the vision of cargo-make? And would the codebase allow to extend cargo-make in such a way without too much effort?