diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..a69cf219 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,59 @@ +name: Test +on: [push] +jobs: + linux: + name: Linux + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.13 + uses: actions/setup-go@v1 + with: + go-version: 1.13 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + + - name: Build + run: go build -o ./task -v ./cmd/task + + - name: Test + run: ./task test + + windows: + name: Windows + runs-on: windows-latest + steps: + - name: Set up Go 1.13 + uses: actions/setup-go@v1 + with: + go-version: 1.13 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + + - name: Build + run: go install -v ./cmd/task + + - name: Test + run: go test -v ./... + + macos: + name: MacOS + runs-on: macOS-latest + steps: + - name: Set up Go 1.13 + uses: actions/setup-go@v1 + with: + go-version: 1.13 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + + - name: Build + run: go build -o ./task -v ./cmd/task + + - name: Test + run: ./task test diff --git a/.gitignore b/.gitignore index c5de0bc5..4a1cc9a1 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ dist/ # exuberant ctags tags + +/bin diff --git a/.travis.yml b/.travis.yml index dabf2188..8a7a63cc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: go go: - - 1.11.x - 1.12.x + - 1.13.x addons: apt: @@ -10,7 +10,7 @@ addons: - rpm script: - - go install github.com/go-task/task/cmd/task + - go install -v ./cmd/task - task ci deploy: diff --git a/cmd/task/task.go b/cmd/task/task.go index a7e08719..ed207b8a 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -11,6 +11,7 @@ import ( "github.com/go-task/task/v2" "github.com/go-task/task/v2/internal/args" "github.com/go-task/task/v2/internal/logger" + _ "github.com/go-task/task/v2/internal/homefix" "github.com/spf13/pflag" ) diff --git a/go.mod b/go.mod index fa9ced00..7390fa2d 100644 --- a/go.mod +++ b/go.mod @@ -16,3 +16,5 @@ require ( gopkg.in/yaml.v2 v2.2.1 mvdan.cc/sh v2.6.4+incompatible ) + +go 1.13 diff --git a/internal/homefix/homefix.go b/internal/homefix/homefix.go new file mode 100644 index 00000000..641ae79a --- /dev/null +++ b/internal/homefix/homefix.go @@ -0,0 +1,5 @@ +// Package homefix exists to address a bug where mvdan.cc/sh expects +// $HOME to be available in order to be able to expand "~". +// +// We should delete this package once this is fixed there. +package homefix diff --git a/internal/homefix/homefix_windows.go b/internal/homefix/homefix_windows.go new file mode 100644 index 00000000..28ed67fc --- /dev/null +++ b/internal/homefix/homefix_windows.go @@ -0,0 +1,15 @@ +package homefix + +import ( + "os" + + "github.com/mitchellh/go-homedir" +) + +func init() { + if os.Getenv("HOME") == "" { + if home, err := homedir.Dir(); err == nil { + os.Setenv("HOME", home) + } + } +} diff --git a/task_test.go b/task_test.go index ebcb51b3..6f2e4147 100644 --- a/task_test.go +++ b/task_test.go @@ -7,10 +7,12 @@ import ( "io/ioutil" "os" "path/filepath" + "runtime" "strings" "testing" "github.com/go-task/task/v2" + _ "github.com/go-task/task/v2/internal/homefix" "github.com/go-task/task/v2/internal/taskfile" "github.com/mitchellh/go-homedir" @@ -570,13 +572,16 @@ func TestSummary(t *testing.T) { } assert.NoError(t, e.Setup()) assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "task-with-summary"}, taskfile.Call{Task: "other-task-with-summary"})) - assert.Equal(t, readTestFixture(t, dir, "task-with-summary.txt"), buff.String()) -} -func readTestFixture(t *testing.T, dir string, file string) string { - b, err := ioutil.ReadFile(dir + "/" + file) - assert.NoError(t, err, "error reading text fixture") - return string(b) + data, err := ioutil.ReadFile(filepath.Join(dir, "task-with-summary.txt")) + assert.NoError(t, err) + + expectedOutput := string(data) + if runtime.GOOS == "windows" { + expectedOutput = strings.Replace(expectedOutput, "\r\n", "\n", -1) + } + + assert.Equal(t, expectedOutput, buff.String()) } func TestWhenNoDirAttributeItRunsInSameDirAsTaskfile(t *testing.T) {