From 120d0be84c701e0477f8cd96de83cdd82da9851b Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 11 Mar 2018 14:39:40 -0300 Subject: [PATCH 1/2] Fixes panic on `task --list` Fixes #99 --- cmd/task/task.go | 2 +- task.go | 11 ++++++----- task_test.go | 16 ++++++++-------- taskfile.go | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/cmd/task/task.go b/cmd/task/task.go index f7a5afe9..6afde2d8 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -98,7 +98,7 @@ func main() { Stdout: os.Stdout, Stderr: os.Stderr, } - if err := e.ReadTaskfile(); err != nil { + if err := e.Setup(); err != nil { log.Fatal(err) } diff --git a/task.go b/task.go index ffe739c1..cade5d35 100644 --- a/task.go +++ b/task.go @@ -52,10 +52,6 @@ type Executor struct { // Run runs Task func (e *Executor) Run(calls ...taskfile.Call) error { - if err := e.setup(); err != nil { - return err - } - // check if given tasks exist for _, c := range calls { if _, ok := e.Taskfile.Tasks[c.Task]; !ok { @@ -77,7 +73,12 @@ func (e *Executor) Run(calls ...taskfile.Call) error { return nil } -func (e *Executor) setup() error { +// Setup setups Executor's internal state +func (e *Executor) Setup() error { + if err := e.readTaskfile(); err != nil { + return err + } + v, err := semver.NewVersion(e.Taskfile.Version) if err != nil { return fmt.Errorf(`task: could not parse taskfile version "%s": %v`, e.Taskfile.Version, err) diff --git a/task_test.go b/task_test.go index c0d690cc..6e48faa8 100644 --- a/task_test.go +++ b/task_test.go @@ -38,7 +38,7 @@ func (fct fileContentTest) Run(t *testing.T) { Stdout: ioutil.Discard, Stderr: ioutil.Discard, } - assert.NoError(t, e.ReadTaskfile(), "e.ReadTaskfile()") + assert.NoError(t, e.Setup(), "e.Setup()") assert.NoError(t, e.Run(taskfile.Call{Task: fct.Target}), "e.Run(target)") for name, expectContent := range fct.Files { @@ -176,7 +176,7 @@ func TestVarsInvalidTmpl(t *testing.T) { Stdout: ioutil.Discard, Stderr: ioutil.Discard, } - assert.NoError(t, e.ReadTaskfile(), "e.ReadTaskfile()") + assert.NoError(t, e.Setup(), "e.Setup()") assert.EqualError(t, e.Run(taskfile.Call{Task: target}), expectError, "e.Run(target)") } @@ -228,7 +228,7 @@ func TestDeps(t *testing.T) { Stdout: ioutil.Discard, Stderr: ioutil.Discard, } - assert.NoError(t, e.ReadTaskfile()) + assert.NoError(t, e.Setup()) assert.NoError(t, e.Run(taskfile.Call{Task: "default"})) for _, f := range files { @@ -256,7 +256,7 @@ func TestStatus(t *testing.T) { Stderr: &buff, Silent: true, } - assert.NoError(t, e.ReadTaskfile()) + assert.NoError(t, e.Setup()) assert.NoError(t, e.Run(taskfile.Call{Task: "gen-foo"})) if _, err := os.Stat(file); err != nil { @@ -295,7 +295,7 @@ func TestGenerates(t *testing.T) { Stdout: buff, Stderr: buff, } - assert.NoError(t, e.ReadTaskfile()) + assert.NoError(t, e.Setup()) for _, theTask := range []string{relTask, absTask} { var destFile = filepath.Join(dir, theTask) @@ -347,7 +347,7 @@ func TestStatusChecksum(t *testing.T) { Stdout: &buff, Stderr: &buff, } - assert.NoError(t, e.ReadTaskfile()) + assert.NoError(t, e.Setup()) assert.NoError(t, e.Run(taskfile.Call{Task: "build"})) for _, f := range files { @@ -386,7 +386,7 @@ func TestCyclicDep(t *testing.T) { Stdout: ioutil.Discard, Stderr: ioutil.Discard, } - assert.NoError(t, e.ReadTaskfile()) + assert.NoError(t, e.Setup()) assert.IsType(t, &task.MaximumTaskCallExceededError{}, e.Run(taskfile.Call{Task: "task-1"})) } @@ -406,7 +406,7 @@ func TestTaskVersion(t *testing.T) { Stdout: ioutil.Discard, Stderr: ioutil.Discard, } - assert.NoError(t, e.ReadTaskfile()) + assert.NoError(t, e.Setup()) assert.Equal(t, test.Version, e.Taskfile.Version) assert.Equal(t, 2, len(e.Taskfile.Tasks)) }) diff --git a/taskfile.go b/taskfile.go index d6ebf9d8..8a5a37f1 100644 --- a/taskfile.go +++ b/taskfile.go @@ -12,8 +12,8 @@ import ( "gopkg.in/yaml.v2" ) -// ReadTaskfile parses Taskfile from the disk -func (e *Executor) ReadTaskfile() error { +// readTaskfile parses Taskfile from the disk +func (e *Executor) readTaskfile() error { path := filepath.Join(e.Dir, TaskFilePath) var err error From 2183e1e9f563f926666afc9b243c16683e7b2443 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 11 Mar 2018 15:31:27 -0300 Subject: [PATCH 2/2] Improve release process and testing automatic release on new tag using Travis --- .goreleaser.yml | 25 ++++++++++++++++++++++++- .travis.yml | 15 +++++++++++++++ RELEASING_TASK.md | 26 ++++++++++++++++++++++++++ Taskfile.yml | 8 +------- 4 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 RELEASING_TASK.md diff --git a/.goreleaser.yml b/.goreleaser.yml index d96a7a02..336b470a 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -22,12 +22,35 @@ archive: release: draft: true -fpm: +snapshot: + name_template: "{{.Tag}}" + +nfpm: vendor: Task homepage: https://github.com/go-task/task maintainer: Andrey Nering description: Simple task runner written in Go license: MIT + conflicts: + - taskwarrior formats: - deb - rpm + +brew: + name: go-task + github: + owner: go-task + name: homebrew-tap + commit_author: + name: Andrey Nering + email: andrey.nering@gmail.com + folder: Formula + homepage: https://github.com/go-task/task + description: Task runner / simpler Make alternative written in Go + conflicts: + - taskwarrior + install: | + bin.install "task" + test: | + system "#{bin}/task", "--help" diff --git a/.travis.yml b/.travis.yml index e78cae6f..f94223cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,25 @@ language: go + go: - '1.8' - '1.9' - '1.10' + +addons: + apt: + packages: + - rpm + script: - go install github.com/go-task/task/cmd/task - task dl-deps - task lint - task test + +deploy: + - provider: script + skip_cleanup: true + script: curl -sL http://git.io/goreleaser | bash + on: + tags: true + condition: $TRAVIS_OS_NAME = linux diff --git a/RELEASING_TASK.md b/RELEASING_TASK.md new file mode 100644 index 00000000..9d1083fd --- /dev/null +++ b/RELEASING_TASK.md @@ -0,0 +1,26 @@ +# Releasing Task + +The release process of Task is done is done with the help of +[GoReleaser][goreleaser]. You can test the release process locally by calling +the `test-release` task of the Taskfile. + +The Travis CI should release automatically when a new +Git tag is pushed to master, either for the artifact uploading (raw executables +and DEB and RPM packages) and publishing of a new version in the +[Homebrew tap][homebrewtap]. + +# Snapcraft + +The exception is the publishing of a new version of the +[snap package][snappackage]. This current require two steps after publishing +the binaries: + +* Updating the current version on [snapcraft.yaml][snapcraftyaml]; +* Moving either the `i386` and `amd64` new artifacts to the stable channel on +the [Snapscraft dashboard][snapcraftdashboard] + +[goreleaser]: https://goreleaser.com/#continuous_integration +[homebrewtap]: https://github.com/go-task/homebrew-tap +[snappackage]: https://github.com/go-task/snap +[snapcraftyaml]: https://github.com/go-task/snap/blob/master/snap/snapcraft.yaml#L2 +[snapcraftdashboard]: https://dashboard.snapcraft.io/ diff --git a/Taskfile.yml b/Taskfile.yml index 03adc289..3939c5e6 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -39,16 +39,10 @@ tasks: cmds: - go test {{.GO_PACKAGES}} - # https://github.com/goreleaser/goreleaser - release: - desc: Release Task - cmds: - - goreleaser - test-release: desc: Tests release process without publishing cmds: - - goreleaser --snapshot + - goreleaser --snapshot --rm-dist todo: desc: Prints TODO comments present in the code