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 c14fa74
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 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
7 changes: 3 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 Down Expand Up @@ -54,7 +53,7 @@ func TestCommand_WithWorkingDir(t *testing.T) {
}

func TestCommand_WithStandardStreams(t *testing.T) {
tmpFile, _ := ioutil.TempFile("/tmp", "stdout_")
tmpFile, _ := os.TempFile("/tmp", "stdout_")

Check failure on line 56 in command_linux_test.go

View workflow job for this annotation

GitHub Actions / staticcheck

undefined: os.TempFile

Check failure on line 56 in command_linux_test.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

undefined: os.TempFile
originalStdout := os.Stdout
os.Stdout = tmpFile

Expand All @@ -66,7 +65,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 +136,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

0 comments on commit c14fa74

Please sign in to comment.