Traverse upwards to find ./magefiles directory
This is a follow up from the other PR that has stalled. (https://github.com/magefile/mage/pull/290)
I am using mage in a monorepo, with many layers of folders that may contain magefiles. It's been a major improvement working with this repo when mage walks up the tree to find the closest magefiles folder.
This PR causes the following affects:
- By default, it searches for a
magefilesfolder within the current directory - If not found, it begins walking up the tree to find the folder
- If a
.gitfolder is detected, it stops. This is based on the assumption that many magefiles probably should be scope to their git repository - If the root is encountered, it also stops.
- You can disable this behavior by passing -no-traverse or setting
MAGEFILE_NO_TRAVERSEas an environment variable
I can see an argument for some sort of .magebuild or .mageroot file that also can be used to indicate traversal stopping.
I did not update the website. I'm open to that, however wanted to get some opinions on this before I work on it much further.
Thanks!
In my implementation of this for a similar tool, I have a case for when the current folder is the magefiles folder. I suppose you just walk up and find it but I though of it as an edge case that returns '.' rather than doing some work to make it relative.
https://github.com/DavidGamba/dgtools/blob/master/bake/build.go#L64