diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f8fa268 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +name: Build + +on: + - pull_request + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + test: + strategy: + matrix: + go: + - "1.21" + - "1.22" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: install Go + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 + with: + go-version: ${{ matrix.go }} + - name: Build + run: make build + - name: Test + run: make test-unit diff --git a/Makefile b/Makefile index a702f00..1db6681 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ .PHONY: test build install lint clean fmt processbin +CGO_ENABLED ?= 0 + BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) BUILDDATE ?= $(shell date +"%Y-%m-%dT%H:%M:%S%z") REVISION ?= $(shell git rev-parse HEAD) @@ -18,19 +20,19 @@ test-ci: processbin go test -race ./... -count=30 test-unit: processbin - go test -short -timeout 15s ./... + CGO_ENABLED=$(CGO_ENABLED) go test -short -timeout 15s ./... processbin: - go build -o dist/processbin ./cmd/processbin + CGO_ENABLED=$(CGO_ENABLED) go build -o dist/processbin ./cmd/processbin build: - go build -ldflags "$(VERSION_LDFLAGS)" -o dist/monoceros ./cmd/monoceros + CGO_ENABLED=$(CGO_ENABLED) go build -ldflags "$(VERSION_LDFLAGS)" -o dist/monoceros ./cmd/monoceros build-race: - go build -race -ldflags "$(VERSION_LDFLAGS)" -o dist/monoceros-race ./cmd/monoceros + CGO_ENABLED=$(CGO_ENABLED) go build -race -ldflags "$(VERSION_LDFLAGS)" -o dist/monoceros-race ./cmd/monoceros install: - go install -ldflags "$(VERSION_LDFLAGS)" ./cmd/monoceros + CGO_ENABLED=$(CGO_ENABLED) go install -ldflags "$(VERSION_LDFLAGS)" ./cmd/monoceros lint: go mod tidy diff --git a/cmd/monoceros/main.go b/cmd/monoceros/main.go index 381fe15..4d68d17 100644 --- a/cmd/monoceros/main.go +++ b/cmd/monoceros/main.go @@ -4,12 +4,10 @@ package main import ( "context" "fmt" - "math/rand" "os" "os/signal" "sync" "syscall" - "time" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/version" @@ -97,7 +95,6 @@ func mainCore(config *config.MonocerosConfig, logger *zap.Logger) error { func main() { prometheus.MustRegister(version.NewCollector(AppName)) - rand.Seed(time.Now().UnixNano()) app := &cli.App{ Name: AppName, diff --git a/go.mod b/go.mod index 4d9ebac..c180a71 100644 --- a/go.mod +++ b/go.mod @@ -1,20 +1,16 @@ module github.com/reddit/monoceros -go 1.19 +go 1.21 require ( github.com/go-cmd/cmd v1.4.2 - github.com/stretchr/testify v1.8.0 // indirect - go.uber.org/zap v1.21.0 - gopkg.in/yaml.v3 v3.0.1 -) - -require ( github.com/google/go-cmp v0.6.0 github.com/prometheus/client_golang v1.13.0 github.com/prometheus/common v0.37.0 github.com/prometheus/procfs v0.8.0 github.com/urfave/cli/v2 v2.11.1 + go.uber.org/zap v1.21.0 + gopkg.in/yaml.v3 v3.0.1 ) require ( @@ -27,6 +23,7 @@ require ( github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/stretchr/testify v1.8.0 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect diff --git a/go.sum b/go.sum index 9b08149..b214e68 100644 --- a/go.sum +++ b/go.sum @@ -77,6 +77,7 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= +github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=