Skip to content

Commit

Permalink
Merge pull request #86 from kolyshkin/ci
Browse files Browse the repository at this point in the history
Add GHA CI
  • Loading branch information
rhatdan authored Sep 8, 2021
2 parents e433993 + 0855da8 commit 37eb23c
Show file tree
Hide file tree
Showing 73 changed files with 123 additions and 23,844 deletions.
2 changes: 2 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[codespell]
skip = ./vendor,./.git
43 changes: 43 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: ci
on:
push:
tags:
- v*
branches:
- main
- release-*
pull_request:

jobs:
test:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
go-version: [1.16.x, 1.17.x]
race: ["-race", ""]

steps:

- name: checkout
uses: actions/checkout@v2

- name: install go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
stable: '!contains(${{ matrix.go-version }}, "beta") && !contains(${{ matrix.go-version }}, "rc")'
go-version: ${{ matrix.go-version }}

- name: install bats
uses: mig4/setup-bats@v1
with:
bats-version: 1.4.1

- name: build
run: make build EXTRA_BUILD_FLAGS="${{ matrix.race }}"

- name: unit tests
run: make test-unit EXTRA_TEST_FLAGS="${{ matrix.race }}"

- name: integration tests
run: make test-integration
31 changes: 31 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: validate
on:
push:
tags:
- v*
branches:
- main
- release-*
pull_request:

jobs:

lint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: golangci/golangci-lint-action@v2
with:
# must be specified without patch version
version: v1.40

codespell:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: install deps
# Version of codespell bundled with Ubuntu is way old, so use pip.
run: pip install codespell
- name: run codespell
run: codespell

6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# For documentation, see https://golangci-lint.run/usage/configuration/

linters:
enable:
- errorlint
- gofumpt
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

40 changes: 16 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
export GO111MODULE=off
export GOPROXY=https://proxy.golang.org

SHELL= /bin/bash
GO ?= go
BUILD_DIR := ./bin
BIN_DIR := /usr/local/bin
NAME := psgo
PROJECT := github.com/containers/psgo
BATS_TESTS := *.bats
GO_SRC=$(shell find . -name \*.go)

GO_BUILD=$(GO) build
# Go module support: set `-mod=vendor` to use the vendored sources
ifeq ($(shell go help mod >/dev/null 2>&1 && echo true), true)
GO_BUILD=GO111MODULE=on $(GO) build -mod=vendor
# Not all platforms support -buildmode=pie, plus it's incompatible with -race.
ifeq ($(shell $(GO) env GOOS),linux)
ifeq (,$(filter $(shell $(GO) env GOARCH),mips mipsle mips64 mips64le ppc64 riscv64))
ifeq (,$(findstring -race,$(EXTRA_BUILD_FLAGS)))
GO_BUILDMODE := "-buildmode=pie"
endif
endif
endif

GOBIN ?= $(GO)/bin
GO_BUILD := $(GO) build $(GO_BUILDMODE)

all: validate build

.PHONY: build
build: $(GO_SRC)
$(GO_BUILD) -buildmode=pie -o $(BUILD_DIR)/$(NAME) $(PROJECT)/sample
build:
$(GO_BUILD) $(EXTRA_BUILD_FLAGS) -o $(BUILD_DIR)/$(NAME) ./sample

.PHONY: clean
clean:
rm -rf $(BUILD_DIR)

.PHONY: vendor
vendor:
GO111MODULE=on go mod tidy
GO111MODULE=on go mod vendor
GO111MODULE=on go mod verify
go mod tidy
go mod vendor
go mod verify

.PHONY: validate
validate: .install.lint
$(GOBIN)/golangci-lint run
validate:
golangci-lint run

.PHONY: test
test: test-unit test-integration
Expand All @@ -47,17 +44,12 @@ test-integration:

.PHONY: test-unit
test-unit:
go test -v $(PROJECT)
go test -v $(PROJECT)/internal/...
$(GO) test -v $(EXTRA_TEST_FLAGS) ./...

.PHONY: install
install:
sudo install -D -m755 $(BUILD_DIR)/$(NAME) $(BIN_DIR)

.PHONY: .install.lint
.install.lint:
VERSION=1.24.0 GOBIN=$(GOBIN) sh ./hack/install_golangci.sh

.PHONY: uninstall
uninstall:
sudo rm $(BIN_DIR)/$(NAME)
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module github.com/containers/psgo

go 1.13
go 1.14

require (
github.com/opencontainers/runc v1.0.2
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2
)
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand Down
17 changes: 0 additions & 17 deletions hack/install_golangci.sh

This file was deleted.

2 changes: 1 addition & 1 deletion internal/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func BootTime() (int64, error) {

btimeSec, err := strconv.ParseInt(btimeStr, 10, 64)
if err != nil {
return 0, fmt.Errorf("error parsing boot time from /proc/stat: %s", err)
return 0, fmt.Errorf("error parsing boot time from /proc/stat: %w", err)
}
bootTime = &btimeSec
return btimeSec, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/proc/ns.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ReadMappings(path string) ([]IDMap, error) {
for {
line, _, err := buf.ReadLine()
if err != nil {
if err == io.EOF {
if err == io.EOF { //nolint:errorlint // False positive, see https://github.com/polyfloyd/go-errorlint/pull/12
return mappings, nil
}
return nil, fmt.Errorf("cannot read line from %s: %w", path, err)
Expand Down
8 changes: 5 additions & 3 deletions internal/proc/stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
"github.com/stretchr/testify/assert"
)

var statFile = "31404 (gedit) R 2109 2128 2128 0 -1 4194304 13153 328 0 0 590 55 0 0 20 0 6 0 1331588 419667968 19515 18446744073709551615 94120519110656 94120519115256 140737253236304 0 0 0 0 4096 0 0 0 0 17 2 0 0 62588346 0 0 94120521215368 94120521216168 94120544436224 140737253242331 140737253242369 140737253242369 140737253244905 0"
var statFileSpace = "31405 (ge d it) R 2109 2128 2128 0 -1 4194304 13153 328 0 0 590 55 0 0 20 0 6 0 1331588 419667968 19515 18446744073709551615 94120519110656 94120519115256 140737253236304 0 0 0 0 4096 0 0 0 0 17 2 0 0 62588346 0 0 94120521215368 94120521216168 94120544436224 140737253242331 140737253242369 140737253242369 140737253244905 0"
var statFileParen = "31406 (ged)it) R 2109 2128 2128 0 -1 4194304 13153 328 0 0 590 55 0 0 20 0 6 0 1331588 419667968 19515 18446744073709551615 94120519110656 94120519115256 140737253236304 0 0 0 0 4096 0 0 0 0 17 2 0 0 62588346 0 0 94120521215368 94120521216168 94120544436224 140737253242331 140737253242369 140737253242369 140737253244905 0"
var (
statFile = "31404 (gedit) R 2109 2128 2128 0 -1 4194304 13153 328 0 0 590 55 0 0 20 0 6 0 1331588 419667968 19515 18446744073709551615 94120519110656 94120519115256 140737253236304 0 0 0 0 4096 0 0 0 0 17 2 0 0 62588346 0 0 94120521215368 94120521216168 94120544436224 140737253242331 140737253242369 140737253242369 140737253244905 0"
statFileSpace = "31405 (ge d it) R 2109 2128 2128 0 -1 4194304 13153 328 0 0 590 55 0 0 20 0 6 0 1331588 419667968 19515 18446744073709551615 94120519110656 94120519115256 140737253236304 0 0 0 0 4096 0 0 0 0 17 2 0 0 62588346 0 0 94120521215368 94120521216168 94120544436224 140737253242331 140737253242369 140737253242369 140737253244905 0"
statFileParen = "31406 (ged)it) R 2109 2128 2128 0 -1 4194304 13153 328 0 0 590 55 0 0 20 0 6 0 1331588 419667968 19515 18446744073709551615 94120519110656 94120519115256 140737253236304 0 0 0 0 4096 0 0 0 0 17 2 0 0 62588346 0 0 94120521215368 94120521216168 94120544436224 140737253242331 140737253242369 140737253242369 140737253244905 0"
)

func testReadStat(file string) (string, error) {
switch file {
Expand Down
2 changes: 1 addition & 1 deletion internal/proc/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func readStatusUserNS(pid string) ([]string, error) {
c := exec.Command(args[0], args[1:]...)
output, err := c.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("error executing %q: %v", strings.Join(args, " "), err)
return nil, fmt.Errorf("error executing %q: %w", strings.Join(args, " "), err)
}

return strings.Split(string(output), "\n"), nil
Expand Down
2 changes: 1 addition & 1 deletion internal/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (p *Process) StartTime() (time.Time, error) {
return time.Unix(sinceBoot+bootTime, 0), nil
}

// CPUTime returns the cumlative CPU time of process p as a time.Duration.
// CPUTime returns the cumulative CPU time of process p as a time.Duration.
func (p *Process) CPUTime() (time.Duration, error) {
user, err := strconv.ParseInt(p.Stat.Utime, 10, 64)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions psgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,14 +620,14 @@ func findHostProcess(p *process.Process, ctx *psContext) *process.Process {
}

// processGROUP returns the effective group ID of the process. This will be
// the textual group ID, if it can be optained, or a decimal representation
// the textual group ID, if it can be obtained, or a decimal representation
// otherwise.
func processGROUP(p *process.Process, ctx *psContext) (string, error) {
return process.LookupGID(p.Status.Gids[1])
}

// processRGROUP returns the real group ID of the process. This will be
// the textual group ID, if it can be optained, or a decimal representation
// the textual group ID, if it can be obtained, or a decimal representation
// otherwise.
func processRGROUP(p *process.Process, ctx *psContext) (string, error) {
return process.LookupGID(p.Status.Gids[0])
Expand All @@ -639,14 +639,14 @@ func processPPID(p *process.Process, ctx *psContext) (string, error) {
}

// processUSER returns the effective user name of the process. This will be
// the textual user ID, if it can be optained, or a decimal representation
// the textual user ID, if it can be obtained, or a decimal representation
// otherwise.
func processUSER(p *process.Process, ctx *psContext) (string, error) {
return process.LookupUID(p.Status.Uids[1])
}

// processRUSER returns the effective user name of the process. This will be
// the textual user ID, if it can be optained, or a decimal representation
// the textual user ID, if it can be obtained, or a decimal representation
// otherwise.
func processRUSER(p *process.Process, ctx *psContext) (string, error) {
return process.LookupUID(p.Status.Uids[0])
Expand Down
12 changes: 7 additions & 5 deletions sample/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
"text/tabwriter"

"github.com/containers/psgo"
"github.com/sirupsen/logrus"
)

func main() {
Expand All @@ -25,11 +25,13 @@ func main() {
fillMappings = flag.Bool("fill-mappings", false, "fill the UID and GID mappings with the current user namespace")
)

log.SetPrefix("psgo: ")
log.SetFlags(0)

flag.Parse()

if *fillMappings && !*join {
fmt.Fprintln(os.Stderr, "-fill-mappings requires -join")
os.Exit(1)
log.Fatal("-fill-mappings requires -join")
}

if *list {
Expand All @@ -54,12 +56,12 @@ func main() {
data, err = psgo.ProcessInfoByPids(pidsList, descriptors)
}
if err != nil {
logrus.Panic(err)
log.Panic(err)
}
} else {
data, err = psgo.ProcessInfo(descriptors)
if err != nil {
logrus.Panic(err)
log.Panic(err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/pids.bats
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
! [ "$status" -eq 0]
}

@test "Proccess information with --pids vs all processes" {
@test "Process information with --pids vs all processes" {
nCtrs=5
pidsList=()
ctridList=()
Expand Down
4 changes: 0 additions & 4 deletions vendor/github.com/sirupsen/logrus/.gitignore

This file was deleted.

Loading

0 comments on commit 37eb23c

Please sign in to comment.