diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 89db88b..75a122a 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -1,13 +1,16 @@ -name: commit_lint -on: [pull_request] +name: lint -permissions: - contents: read - pull-requests: read +on: + pull_request: + push: + branches: + - "main" jobs: - commitlint: + staticcheck: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: wagoid/commitlint-github-action@v5 + - uses: actions/setup-go@v3 + - run: go install honnef.co/go/tools/cmd/staticcheck@latest + - run: ~/go/bin/staticcheck -checks all diff --git a/.github/workflows/ci.yml b/.github/workflows/test.yaml similarity index 100% rename from .github/workflows/ci.yml rename to .github/workflows/test.yaml diff --git a/.github/workflows/validation.yaml b/.github/workflows/validation.yaml new file mode 100644 index 0000000..9e20dbf --- /dev/null +++ b/.github/workflows/validation.yaml @@ -0,0 +1,14 @@ +name: validation + +on: [pull_request] + +permissions: + contents: read + pull-requests: read + +jobs: + commitlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: wagoid/commitlint-github-action@v5 diff --git a/command.go b/command.go index 548689b..0b354ad 100644 --- a/command.go +++ b/command.go @@ -1,3 +1,6 @@ +// Package cmd is a simple package +// to execute shell commeand on linux, +// windows, and osx. package cmd import ( @@ -245,12 +248,12 @@ func (c *Command) ExecuteContext(ctx context.Context) error { select { case <-ctx.Done(): if err := cmd.Process.Kill(); err != nil { - return fmt.Errorf("Timeout occurred and can not kill process with pid %v", cmd.Process.Pid) + return fmt.Errorf("timeout occurred and can not kill process with pid %v", cmd.Process.Pid) } err := ctx.Err() if c.Timeout > 0 && !hasDeadline { - err = fmt.Errorf("Command timed out after %v", c.Timeout) + err = fmt.Errorf("command timed out after %v", c.Timeout) } return err case err := <-done: diff --git a/command_linux_test.go b/command_linux_test.go index 9877ea5..4a4dcfe 100644 --- a/command_linux_test.go +++ b/command_linux_test.go @@ -3,7 +3,6 @@ package cmd import ( "bytes" "context" - "io/ioutil" "os" "os/exec" "strings" @@ -12,6 +11,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCommand_ExecuteStderr(t *testing.T) { @@ -54,7 +54,8 @@ func TestCommand_WithWorkingDir(t *testing.T) { } func TestCommand_WithStandardStreams(t *testing.T) { - tmpFile, _ := ioutil.TempFile("/tmp", "stdout_") + tmpFile, err := os.CreateTemp("/tmp", "stdout_") + require.NoError(t, err) originalStdout := os.Stdout os.Stdout = tmpFile @@ -66,7 +67,7 @@ func TestCommand_WithStandardStreams(t *testing.T) { cmd := NewCommand("echo hey", WithStandardStreams) cmd.Execute() - r, err := ioutil.ReadFile(tmpFile.Name()) + r, err := os.ReadFile(tmpFile.Name()) assert.Nil(t, err) assert.Equal(t, "hey\n", string(r)) } @@ -137,7 +138,7 @@ func TestCommand_WithContext(t *testing.T) { cmd := NewCommand("sleep 3;", WithTimeout(1*time.Second)) err := cmd.Execute() assert.NotNil(t, err) - assert.Equal(t, "Command timed out after 1s", err.Error()) + assert.Equal(t, "command timed out after 1s", err.Error()) // set context timeout to 2 seconds to ensure // context takes precedence over timeout