Skip to content

Commit

Permalink
ci: add staticcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanhitt committed Jan 31, 2024
1 parent bc77ccb commit 1aa508e
Show file tree
Hide file tree
Showing 14 changed files with 3,750 additions and 14 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
14 changes: 14 additions & 0 deletions .github/workflows/validation.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions command.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Package cmd is a simple package
// to execute shell commeand on linux,
// windows, and osx.
package cmd

import (
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion command_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

func TestCommand_ExecuteStderr(t *testing.T) {
cmd := NewCommand(">&2 echo hello")

err := cmd.Execute()

assert.Nil(t, err)
Expand Down
9 changes: 5 additions & 4 deletions command_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"bytes"
"context"
"io/ioutil"
"os"
"os/exec"
"strings"
Expand All @@ -12,6 +11,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCommand_ExecuteStderr(t *testing.T) {
Expand Down Expand Up @@ -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

Expand All @@ -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))
}
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions vendor/github.com/stretchr/testify/require/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions vendor/github.com/stretchr/testify/require/forward_requirements.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1aa508e

Please sign in to comment.