add support for retaining multiline comments
including MAGEFILE_MULTILINE environment variable
and //mage:multiline in-code comment
and -multiline CLI flag.
* add tests
* fix lint errors and align ci and lint workflows
* update to require go 1.18 since golangci-lint requires it, and because it adds version control info into the binary automatically
* use built-in version info from go 1.18
* remove gopath from install docs
Samples used for testing need to have build tags for new and old style:
```
//go:build tag
// +build tag
```
The particular problem here seems to be that 1.16 was actually importing the package referred in the `TestGoModules` test (`import "golang.org/x/text/unicode/norm"`) which, in the CI system's version lacks an old style go tag comment. Hence go complaining of a `//go:build` without a `// +build`. I made all files bi-tagged for consistency.
* mage: cancel context on SIGINT
On receiving an interrupt signal, mage cancels the context allowing the magefile
to perform any cleanup before exiting.
A second interrupt signal will kill the magefile process without delay.
The behaviour for a timeout remains unchanged (context is cancelled and the magefile
exits).
* mage: add cleanup timeout to cancel
Co-authored-by: Nate Finch <nate.finch@gmail.com>
Allows to pass sh.Run to mg.F as such:
mg.Deps(
mg.F(sh.Run, "go", "test", "./..."),
)
This improves the magefile by removing some of the one-liner functions
that you might end up with that are only used through mg.Deps.
Resolves#401.
* Use magefolder if no directory set and it exists.
If no directory was passed by the user as an explicit option and there is a folder named "magefolder" use that.
Workdir is kept as it is likely still "."
* Remove the default . for -d flag
Also correct os.Stat error checking to expect no error
* Add tests and test data for magefolder
* Rename magefolder and accept untagged files
Magefolder was renamed to magefiles
We now accept files that are not tagged too when using a magefiles directory
* Assume tagging when mix tagging is present
When using magefiles directory, if there are mixed tagging files assume tagging is used for mage files
* Update error format to %v
We support building for older go versions so error formatting should use %v
* sort outputs
* Accept mixed tagging in magefiles folder
When mixed tagging is found within a magefiles folder, opt to use all files
* little tweak to only do go list once when using magefiles directory
* Add magefiles directory information to the website
* Add a preference for mage files over directories
Add a temporary preference for mage files over magefiles directories and warn users this is a temporary functionality leading to a change where directory will be preferred.
Co-authored-by: Nate Finch <natefinch@github.com>
* Detect deps that have already been invoked
Detect when a dependency was accidentally already invoked
mg.Deps(MyDep())
Normally this causes a nil pointer panic when we invoke the function
Error: runtime error: invalid memory address or nil pointer dereference
Now it will print the following as soon as its detected
Error: A dependency of the current target was defined improperly, with parenthesis. Dependencies should be defined as mg.Deps(MyDep), not mg.Deps(MyDep())
I have applied this change to checkfn so that it applies to serial and
parallel deps.
Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
* Fix nil checks and improve error message
The new mg.F function is the root of the nil-pointer error that can happen
when someone accidentally calls mg.Deps(TargetA()). I have fixed the check
for whether a function was passed so that it won't panic and included
the usage for mg.F in the error message.
I then added a similar check, is the target a function, to
Deps/SerialDeps/CxtSerialDeps functions so that we can give a better
error message when it's passed a non-function. The error message
otherwise will reference mg.F which I don't think will help point people
to the real problem, which is how they called mg.Deps/SerialDeps.
Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
Co-authored-by: Nate Finch <nate.finch@gmail.com>
* fix: determanistic compiled mainfile
sort template data so resulting mainfile is consistantly reproducible,
which is important to leverage build cache and results in a consistent
build id on output (given identical build parameters, e.g. ldflags,
output file name, etc.)
Result of `mage -compile ./mage_static && go tool buildid ./mage_static`
should now always be identical on repeated invocation.
Results in a probably imperceptible build time quickening, but solves a
minor peave of mine, and adds a test as protection from regression :)
* fix: poorly spelled test
Co-authored-by: Nate Finch <nate.finch@gmail.com>
* Update parse/parse.go
got caught out not using vim's spellcheck
Co-authored-by: Paul Burlumi <paul@burlumi.com>
* Update mage/main.go
got caught out not using vim's spellcheck
Co-authored-by: Paul Burlumi <paul@burlumi.com>
* fix spelling
Co-authored-by: Paul Burlumi <paul@burlumi.com>
Co-authored-by: Nate Finch <nate.finch@gmail.com>
Co-authored-by: Paul Burlumi <paul@burlumi.com>
Co-authored-by: Nate Finch <natefinch@github.com>