From 82a3651a18c8610568c02a80fab995742e678437 Mon Sep 17 00:00:00 2001 From: Marco Molteni Date: Sun, 16 Jun 2019 11:33:00 +0200 Subject: [PATCH 1/8] Document dir: creation (see PR #211) --- docs/usage.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/usage.md b/docs/usage.md index ea42b945..f43e8365 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -148,6 +148,8 @@ tasks: - caddy ``` +If the directory doesn't exist, `task` creates it. + ## Task dependencies You may have tasks that depend on others. Just pointing them on `deps` will From d970e935074a3a96e7b9f1a3dbc02d8298ec9b40 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 21 Jul 2019 10:54:09 -0300 Subject: [PATCH 2/8] Add --taskfile flag (alias -t) to allow running another Taskfile Closes #221 --- CHANGELOG.md | 3 +++ cmd/task/task.go | 31 ++++++++++++++++++++++-------- internal/taskfile/read/taskfile.go | 9 +++------ task.go | 22 +++++++++++++-------- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7d83880..adaaeee6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ ([#205](https://github.com/go-task/task/pull/205)). - Create directory informed on `dir:` if it doesn't exist ([#209](https://github.com/go-task/task/issues/209), [#211](https://github.com/go-task/task/pull/211)). +- We now have a `--taskfile` flag (alias `-t`), which can be used to run + another Taskfile (other than the default `Taskfile.yml`) + ([#221](https://github.com/go-task/task/pull/221)). ## v2.5.2 - 2019-05-11 diff --git a/cmd/task/task.go b/cmd/task/task.go index 4070e1b9..b71023ac 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -5,6 +5,7 @@ import ( "log" "os" "os/signal" + "path/filepath" "syscall" "github.com/go-task/task/v2" @@ -17,7 +18,7 @@ var ( version = "master" ) -const usage = `Usage: task [-ilfwvsd] [--init] [--list] [--force] [--watch] [--verbose] [--silent] [--dir] [--dry] [--summary] [task...] +const usage = `Usage: task [-ilfwvsd] [--init] [--list] [--force] [--watch] [--verbose] [--silent] [--dir] [--taskfile] [--dry] [--summary] [task...] Runs the specified task(s). Falls back to the "default" task if no task name was specified, or lists all tasks if an unknown task name was specified. @@ -58,6 +59,7 @@ func main() { dry bool summary bool dir string + entrypoint string output string ) @@ -72,6 +74,7 @@ func main() { pflag.BoolVar(&dry, "dry", false, "compiles and prints tasks in the order that they would be run, without executing them") pflag.BoolVar(&summary, "summary", false, "show summary about a task") pflag.StringVarP(&dir, "dir", "d", "", "sets directory of execution") + pflag.StringVarP(&entrypoint, "taskfile", "t", "", `choose which Taskfile to run. Defaults to "Taskfile.yml"`) pflag.StringVarP(&output, "output", "o", "", "sets output style: [interleaved|group|prefixed]") pflag.Parse() @@ -91,14 +94,26 @@ func main() { return } + if dir != "" && entrypoint != "" { + log.Fatal("task: You can't set both --dir and --taskfile") + return + } + if entrypoint != "" { + dir = filepath.Dir(entrypoint) + entrypoint = filepath.Base(entrypoint) + } else { + entrypoint = "Taskfile.yml" + } + e := task.Executor{ - Force: force, - Watch: watch, - Verbose: verbose, - Silent: silent, - Dir: dir, - Dry: dry, - Summary: summary, + Force: force, + Watch: watch, + Verbose: verbose, + Silent: silent, + Dir: dir, + Dry: dry, + Entrypoint: entrypoint, + Summary: summary, Stdin: os.Stdin, Stdout: os.Stdout, diff --git a/internal/taskfile/read/taskfile.go b/internal/taskfile/read/taskfile.go index b3911e4e..a08360d3 100644 --- a/internal/taskfile/read/taskfile.go +++ b/internal/taskfile/read/taskfile.go @@ -15,16 +15,13 @@ import ( var ( // ErrIncludedTaskfilesCantHaveIncludes is returned when a included Taskfile contains includes ErrIncludedTaskfilesCantHaveIncludes = errors.New("task: Included Taskfiles can't have includes. Please, move the include to the main Taskfile") - - // ErrNoTaskfileFound is returned when Taskfile.yml is not found - ErrNoTaskfileFound = errors.New(`task: No Taskfile.yml found. Use "task --init" to create a new one`) ) // Taskfile reads a Taskfile for a given directory -func Taskfile(dir string) (*taskfile.Taskfile, error) { - path := filepath.Join(dir, "Taskfile.yml") +func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) { + path := filepath.Join(dir, entrypoint) if _, err := os.Stat(path); err != nil { - return nil, ErrNoTaskfileFound + return nil, fmt.Errorf(`task: No Taskfile found on "%s". Use "task --init" to create a new one`, path) } t, err := readTaskfile(path) if err != nil { diff --git a/task.go b/task.go index 1332c46c..83198192 100644 --- a/task.go +++ b/task.go @@ -32,13 +32,15 @@ const ( // Executor executes a Taskfile type Executor struct { Taskfile *taskfile.Taskfile - Dir string - Force bool - Watch bool - Verbose bool - Silent bool - Dry bool - Summary bool + + Dir string + Entrypoint string + Force bool + Watch bool + Verbose bool + Silent bool + Dry bool + Summary bool Stdin io.Reader Stdout io.Writer @@ -85,8 +87,12 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error { // Setup setups Executor's internal state func (e *Executor) Setup() error { + if e.Entrypoint == "" { + e.Entrypoint = "Taskfile.yml" + } + var err error - e.Taskfile, err = read.Taskfile(e.Dir) + e.Taskfile, err = read.Taskfile(e.Dir, e.Entrypoint) if err != nil { return err } From d8bfb3ab13165a48fe869ac928bb5ad42d4283bb Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 21 Jul 2019 11:03:20 -0300 Subject: [PATCH 3/8] Add CHANGELOG and documentation for Linux support on Homebrew Ref: https://github.com/go-task/homebrew-tap/pull/1 Thanks @dawidd6 --- CHANGELOG.md | 2 ++ docs/installation.md | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adaaeee6..beee235c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ - We now have a `--taskfile` flag (alias `-t`), which can be used to run another Taskfile (other than the default `Taskfile.yml`) ([#221](https://github.com/go-task/task/pull/221)). +- It's now possible to install Task using Homebrew on Linux + ([go-task/homebrew-tap#1](https://github.com/go-task/homebrew-tap/pull/1)). ## v2.5.2 - 2019-05-11 diff --git a/docs/installation.md b/docs/installation.md index f40609a0..364f81b8 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -8,13 +8,15 @@ The `task_checksums.txt` file contains the sha256 checksum for each file. ## Homebrew -If you're on macOS and have [Homebrew][homebrew] installed, getting Task is -as simple as running: +If you're on macOS or Linux and have [Homebrew][homebrew] installed, getting +Task is as simple as running: ```bash brew install go-task/tap/go-task ``` +> This installation method is only currently supported on amd64 architectures. + ## Snap Task is available for [Snapcraft][snapcraft], but keep in mind that your From 2eb52da0db3209f7b8089325a101c91810c3c61b Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 21 Jul 2019 11:11:30 -0300 Subject: [PATCH 4/8] v2.6.0 From 4c295b564a7da0281b70652df09d429eab77684c Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 21 Jul 2019 11:23:49 -0300 Subject: [PATCH 5/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index beee235c..da408dcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## Unreleased +## v2.6.0 - 2019-07-21 - Fixed some bugs regarding minor version checks on `version:`. - Add `preconditions:` to task From 955359b073bfb1f6fb80e2bd9fb06debeb4242c0 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sat, 10 Aug 2019 19:38:57 -0300 Subject: [PATCH 6/8] Fix nil panic bug when assigning global var and no var is declared on the Taskfile Closes #229 Ref #234 --- internal/taskfile/taskfile.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/taskfile/taskfile.go b/internal/taskfile/taskfile.go index b3869fbd..6da09dd0 100644 --- a/internal/taskfile/taskfile.go +++ b/internal/taskfile/taskfile.go @@ -40,5 +40,8 @@ func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error { if tf.Expansions <= 0 { tf.Expansions = 2 } + if tf.Vars == nil { + tf.Vars = make(Vars) + } return nil } From e414c1f7b053af03be956b4775e1cf0c2ec123d7 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sat, 10 Aug 2019 19:50:47 -0300 Subject: [PATCH 7/8] Documentation: Improve wording on the Variables section Thanks @crewjam for the suggestion Closes #234 --- docs/usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage.md b/docs/usage.md index f43e8365..d8ffbd90 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -400,7 +400,7 @@ tasks: When doing interpolation of variables, Task will look for the below. They are listed below in order of importance (e.g. most important first): -- Variables declared locally in the task +- Variables declared in the task definition - Variables given while calling a task from another. (See [Calling another task](#calling-another-task) above) - Variables declared in the `vars:` option in the `Taskfile` From a312d61d68d671328911a83880e40655dc80df36 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 11 Aug 2019 23:01:25 -0300 Subject: [PATCH 8/8] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index da408dcd..9be6fb29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased + +- Fixed panic bug when assigning a global variable + ([#229](https://github.com/go-task/task/issues/229), [#243](https://github.com/go-task/task/issues/234)). + ## v2.6.0 - 2019-07-21 - Fixed some bugs regarding minor version checks on `version:`.