Skip to content

Commit

Permalink
Merge pull request #1797 from mmorel-35/golangci-lint-matrix
Browse files Browse the repository at this point in the history
chore(golangci-lint): GOOS and GOARCH matrix
  • Loading branch information
shirou authored Feb 22, 2025
2 parents 4f2f472 + 30aff03 commit edcde3a
Show file tree
Hide file tree
Showing 30 changed files with 146 additions and 118 deletions.
31 changes: 30 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,41 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- {os: macos-latest, GOOS: darwin, GOARCH: amd64}
- {os: macos-latest, GOOS: darwin, GOARCH: arm64}
- {os: ubuntu-latest, GOOS: dragonfly, GOARCH: amd64}
- {os: ubuntu-latest, GOOS: freebsd, GOARCH: amd64}
- {os: ubuntu-latest, GOOS: freebsd, GOARCH: 386}
- {os: ubuntu-latest, GOOS: freebsd, GOARCH: arm}
- {os: ubuntu-latest, GOOS: linux, GOARCH: 386}
- {os: ubuntu-latest, GOOS: linux, GOARCH: amd64}
- {os: ubuntu-latest, GOOS: linux, GOARCH: arm64}
- {os: ubuntu-latest, GOOS: linux, GOARCH: arm}
- {os: ubuntu-latest, GOOS: linux, GOARCH: mips64}
- {os: ubuntu-latest, GOOS: linux, GOARCH: mips64le}
- {os: ubuntu-latest, GOOS: linux, GOARCH: mips}
- {os: ubuntu-latest, GOOS: linux, GOARCH: mipsle}
- {os: ubuntu-latest, GOOS: linux, GOARCH: ppc64le}
- {os: ubuntu-latest, GOOS: linux, GOARCH: ppc64}
- {os: ubuntu-latest, GOOS: linux, GOARCH: riscv64}
- {os: ubuntu-latest, GOOS: linux, GOARCH: s390x}
- {os: ubuntu-latest, GOOS: netbsd, GOARCH: amd64}
- {os: ubuntu-latest, GOOS: openbsd, GOARCH: 386}
- {os: ubuntu-latest, GOOS: openbsd, GOARCH: amd64}
- {os: ubuntu-latest, GOOS: plan9, GOARCH: amd64}
- {os: ubuntu-latest, GOOS: plan9, GOARCH: 386}
- {os: ubuntu-latest, GOOS: solaris, GOARCH: amd64}
- {os: windows-latest, GOOS: windows, GOARCH: amd64}
- {os: windows-latest, GOOS: windows, GOARCH: 386}
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
name: lint
runs-on: ${{ matrix.os }}
env:
GOARCH: ${{ matrix.GOARCH }}
GOOS: ${{ matrix.GOOS }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand Down
5 changes: 3 additions & 2 deletions cpu/cpu_dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
"strings"
"unsafe"

"github.com/shirou/gopsutil/v4/internal/common"
"github.com/tklauser/go-sysconf"
"golang.org/x/sys/unix"

"github.com/shirou/gopsutil/v4/internal/common"
)

var (
Expand Down Expand Up @@ -135,7 +136,7 @@ func parseDmesgBoot(fileName string) (InfoStat, error) {
c.VendorID = matches[1]
t, err := strconv.ParseInt(matches[2], 10, 32)
if err != nil {
return c, fmt.Errorf("unable to parse DragonflyBSD CPU stepping information from %q: %v", line, err)
return c, fmt.Errorf("unable to parse DragonflyBSD CPU stepping information from %q: %w", line, err)
}
c.Stepping = int32(t)
} else if matches := featuresMatch.FindStringSubmatch(line); matches != nil {
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_netbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TimesWithContext(ctx context.Context, percpu bool) (ret []TimesStat, err er

ncpu, err := unix.SysctlUint32("hw.ncpu")
if err != nil {
return
return //nolint:nakedret //FIXME
}

var i uint32
Expand Down
5 changes: 3 additions & 2 deletions cpu/cpu_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"runtime"
"unsafe"

"github.com/shirou/gopsutil/v4/internal/common"
"github.com/tklauser/go-sysconf"
"golang.org/x/sys/unix"

"github.com/shirou/gopsutil/v4/internal/common"
)

const (
Expand Down Expand Up @@ -74,7 +75,7 @@ func TimesWithContext(ctx context.Context, percpu bool) (ret []TimesStat, err er

ncpu, err := unix.SysctlUint32("hw.ncpu")
if err != nil {
return
return //nolint:nakedret //FIXME
}

var i uint32
Expand Down
1 change: 1 addition & 0 deletions cpu/cpu_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"runtime"

stats "github.com/lufia/plan9stats"

"github.com/shirou/gopsutil/v4/internal/common"
)

Expand Down
32 changes: 16 additions & 16 deletions cpu/cpu_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var kstatSplit = regexp.MustCompile(`[:\s]+`)
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
kstatSysOut, err := invoke.CommandWithContext(ctx, "kstat", "-p", "cpu_stat:*:*:/^idle$|^user$|^kernel$|^iowait$|^swap$/")
if err != nil {
return nil, fmt.Errorf("cannot execute kstat: %s", err)
return nil, fmt.Errorf("cannot execute kstat: %w", err)
}
cpu := make(map[float64]float64)
idle := make(map[float64]float64)
Expand All @@ -57,29 +57,29 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
}
cpuNumber, err := strconv.ParseFloat(fields[1], 64)
if err != nil {
return nil, fmt.Errorf("cannot parse cpu number: %s", err)
return nil, fmt.Errorf("cannot parse cpu number: %w", err)
}
cpu[cpuNumber] = cpuNumber
switch fields[3] {
case "idle":
idle[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
if err != nil {
return nil, fmt.Errorf("cannot parse idle: %s", err)
return nil, fmt.Errorf("cannot parse idle: %w", err)
}
case "user":
user[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
if err != nil {
return nil, fmt.Errorf("cannot parse user: %s", err)
return nil, fmt.Errorf("cannot parse user: %w", err)
}
case "kernel":
kern[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
if err != nil {
return nil, fmt.Errorf("cannot parse kernel: %s", err)
return nil, fmt.Errorf("cannot parse kernel: %w", err)
}
case "iowait":
iowt[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
if err != nil {
return nil, fmt.Errorf("cannot parse iowait: %s", err)
return nil, fmt.Errorf("cannot parse iowait: %w", err)
}
//not sure how this translates, don't report, add to kernel, something else?
/*case "swap":
Expand Down Expand Up @@ -121,22 +121,22 @@ func Info() ([]InfoStat, error) {
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
psrInfoOut, err := invoke.CommandWithContext(ctx, "psrinfo", "-p", "-v")
if err != nil {
return nil, fmt.Errorf("cannot execute psrinfo: %s", err)
return nil, fmt.Errorf("cannot execute psrinfo: %w", err)
}

procs, err := parseProcessorInfo(string(psrInfoOut))
if err != nil {
return nil, fmt.Errorf("error parsing psrinfo output: %s", err)
return nil, fmt.Errorf("error parsing psrinfo output: %w", err)
}

isaInfoOut, err := invoke.CommandWithContext(ctx, "isainfo", "-b", "-v")
if err != nil {
return nil, fmt.Errorf("cannot execute isainfo: %s", err)
return nil, fmt.Errorf("cannot execute isainfo: %w", err)
}

flags, err := parseISAInfo(string(isaInfoOut))
if err != nil {
return nil, fmt.Errorf("error parsing isainfo output: %s", err)
return nil, fmt.Errorf("error parsing isainfo output: %w", err)
}

result := make([]InfoStat, 0, len(flags))
Expand All @@ -160,7 +160,7 @@ func parseISAInfo(cmdOutput string) ([]string, error) {
}

flags := make([]string, len(words)-4)
for i, val := range words[4:] {
for i, val := range words[4:] { //nolint:gosimple //FIXME
flags[i] = val
}
sort.Strings(flags)
Expand Down Expand Up @@ -194,15 +194,15 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
if physicalCPU[psrStepOffset] != "" {
stepParsed, err := strconv.ParseInt(physicalCPU[psrStepOffset], 10, 32)
if err != nil {
return nil, fmt.Errorf("cannot parse value %q for step as 32-bit integer: %s", physicalCPU[9], err)
return nil, fmt.Errorf("cannot parse value %q for step as 32-bit integer: %w", physicalCPU[9], err)
}
step = int32(stepParsed)
}

if physicalCPU[psrClockOffset] != "" {
clockParsed, err := strconv.ParseInt(physicalCPU[psrClockOffset], 10, 64)
if err != nil {
return nil, fmt.Errorf("cannot parse value %q for clock as 32-bit integer: %s", physicalCPU[10], err)
return nil, fmt.Errorf("cannot parse value %q for clock as 32-bit integer: %w", physicalCPU[10], err)
}
clock = float64(clockParsed)
}
Expand All @@ -214,7 +214,7 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
case physicalCPU[psrNumCoresOffset] != "":
numCores, err = strconv.ParseInt(physicalCPU[psrNumCoresOffset], 10, 32)
if err != nil {
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %s", physicalCPU[1], err)
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %w", physicalCPU[1], err)
}

for i := 0; i < int(numCores); i++ {
Expand All @@ -235,12 +235,12 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
case physicalCPU[psrNumCoresHTOffset] != "":
numCores, err = strconv.ParseInt(physicalCPU[psrNumCoresHTOffset], 10, 32)
if err != nil {
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %s", physicalCPU[3], err)
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %w", physicalCPU[3], err)
}

numHT, err = strconv.ParseInt(physicalCPU[psrNumHTOffset], 10, 32)
if err != nil {
return nil, fmt.Errorf("cannot parse value %q for hyperthread count as 32-bit integer: %s", physicalCPU[4], err)
return nil, fmt.Errorf("cannot parse value %q for hyperthread count as 32-bit integer: %w", physicalCPU[4], err)
}

for i := 0; i < int(numCores); i++ {
Expand Down
3 changes: 2 additions & 1 deletion disk/disk_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
"context"
"encoding/binary"

"github.com/shirou/gopsutil/v4/internal/common"
"golang.org/x/sys/unix"

"github.com/shirou/gopsutil/v4/internal/common"
)

func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
Expand Down
6 changes: 4 additions & 2 deletions disk/disk_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"math"
"os"
Expand All @@ -16,8 +17,9 @@ import (
"strconv"
"strings"

"github.com/shirou/gopsutil/v4/internal/common"
"golang.org/x/sys/unix"

"github.com/shirou/gopsutil/v4/internal/common"
)

const (
Expand Down Expand Up @@ -100,7 +102,7 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC
}
lines := strings.Split(strings.TrimSpace(string(kstatSysOut)), "\n")
if len(lines) == 0 {
return nil, fmt.Errorf("no disk class found")
return nil, errors.New("no disk class found")
}
dnamearr := make(map[string]string)
nreadarr := make(map[string]uint64)
Expand Down
3 changes: 2 additions & 1 deletion host/host_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
"strings"
"unsafe"

"golang.org/x/sys/unix"

"github.com/shirou/gopsutil/v4/internal/common"
"github.com/shirou/gopsutil/v4/process"
"golang.org/x/sys/unix"
)

const (
Expand Down
16 changes: 8 additions & 8 deletions host/host_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"os"
"regexp"
Expand All @@ -31,14 +32,13 @@ func HostIDWithContext(ctx context.Context) (string, error) {
line := sc.Text()

// If we're in the global zone, rely on the hostname.
if line == "global" {
hostname, err := os.Hostname()
if err == nil {
return hostname, nil
}
} else {
if line != "global" {
return strings.TrimSpace(line), nil
}
hostname, err := os.Hostname()
if err == nil {
return hostname, nil
}
}
}
}
Expand Down Expand Up @@ -84,7 +84,7 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
}

func UptimeWithContext(ctx context.Context) (uint64, error) {
bootTime, err := BootTime()
bootTime, err := BootTime() //nolint:contextcheck //FIXME
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -139,7 +139,7 @@ func parseUnameOutput(ctx context.Context) (string, string, string, error) {

fields := strings.Fields(string(out))
if len(fields) < 3 {
return "", "", "", fmt.Errorf("malformed `uname` output")
return "", "", "", errors.New("malformed `uname` output")
}

return fields[0], fields[1], fields[2], nil
Expand Down
19 changes: 9 additions & 10 deletions mem/mem_bsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

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

const validFreeBSD = `Device: 1kB-blocks Used:
Expand All @@ -24,33 +25,31 @@ const invalid = `Device: 512-blocks Used:
`

func TestParseSwapctlOutput_FreeBSD(t *testing.T) {
assert := assert.New(t)
stats, err := parseSwapctlOutput(validFreeBSD)
assert.NoError(err)
require.NoError(t, err)

assert.Equal(*stats[0], SwapDevice{
assert.Equal(t, SwapDevice{
Name: "/dev/gpt/swapfs",
UsedBytes: 1263616,
FreeBytes: 1072478208,
})
}, *stats[0])

assert.Equal(*stats[1], SwapDevice{
assert.Equal(t, SwapDevice{
Name: "/dev/md0",
UsedBytes: 681984,
FreeBytes: 1073059840,
})
}, *stats[1])
}

func TestParseSwapctlOutput_OpenBSD(t *testing.T) {
assert := assert.New(t)
stats, err := parseSwapctlOutput(validOpenBSD)
assert.NoError(err)
require.NoError(t, err)

assert.Equal(*stats[0], SwapDevice{
assert.Equal(t, SwapDevice{
Name: "/dev/wd0b",
UsedBytes: 1234 * 1024,
FreeBytes: 653791 * 1024,
})
}, *stats[0])
}

func TestParseSwapctlOutput_Invalid(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions mem/mem_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,16 @@ const invalidFile = `INVALID Type Size Used Priority
`

func TestParseSwapsFile_ValidFile(t *testing.T) {
assert := assert.New(t)
stats, err := parseSwapsFile(context.Background(), strings.NewReader(validFile))
require.NoError(t, err)

assert.Equal(SwapDevice{
assert.Equal(t, SwapDevice{
Name: "/dev/dm-2",
UsedBytes: 502566912,
FreeBytes: 68128825344,
}, *stats[0])

assert.Equal(SwapDevice{
assert.Equal(t, SwapDevice{
Name: "/swapfile",
UsedBytes: 1024,
FreeBytes: 1024,
Expand Down
Loading

0 comments on commit edcde3a

Please sign in to comment.