Skip to content

Commit

Permalink
Update modules. Improve Makefile (#36)
Browse files Browse the repository at this point in the history
* Update modules. Improve Makefile

Signed-off-by: Stavros Foteinopoulos <[email protected]>

* Bump go. Add linting. Fix linting errors

Signed-off-by: Stavros Foteinopoulos <[email protected]>

---------

Signed-off-by: Stavros Foteinopoulos <[email protected]>
  • Loading branch information
stafot authored Oct 24, 2024
1 parent b0e9f66 commit 4e77a77
Show file tree
Hide file tree
Showing 16 changed files with 343 additions and 2,004 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
env:
GOFLAGS: "-buildvcs=false"
container:
image: golang:1.22.2-bookworm
image: golang:1.23.2-bookworm
steps:
- name: ci/checkout-repo
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
Expand All @@ -25,7 +25,7 @@ jobs:
test:
runs-on: ubuntu-latest
container:
image: golang:1.22.2-bookworm
image: golang:1.23.2-bookworm
steps:
- name: ci/checkout-repo
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
Expand Down
29 changes: 29 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Docs: https://golangci-lint.run/usage/configuration/#config-file

run:
timeout: 5m

issues:
max-issues-per-linter: 0
max-same-issues: 0

linters-settings:
gofmt:
simplify: true
govet:
enable-all: true
disable:
- fieldalignment
- atomicalign

linters:
disable-all: true
enable:
- gofmt
- gosimple
- govet
- ineffassign
- predeclared
- staticcheck
- unconvert
- unused
48 changes: 44 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
################################################################################

## Docker Build Versions
DOCKER_BUILD_IMAGE = golang:1.22
DOCKER_BASE_IMAGE = alpine:3.19
DOCKER_BUILD_IMAGE = golang:1.23
DOCKER_BASE_IMAGE = alpine:3.20

################################################################################

Expand All @@ -25,17 +25,24 @@ LOGRUS_VERSION := $(shell find go.mod -type f -exec cat {} + | grep ${LOGRUS_URL

LOGRUS_PATH := $(GOPATH)/pkg/mod/${LOGRUS_URL}\@${LOGRUS_VERSION}

TOOLS_BIN_DIR := $(abspath bin)


# Tools
GOLANGCILINT_VER := v1.57.2
GOLANGCILINT_VER := v1.61.0
GOLANGCILINT := $(TOOLS_BIN_DIR)/$(GOLANGCILINT_BIN)

OUTDATED_VER := master
OUTDATED_BIN := go-mod-outdated
OUTDATED_GEN := $(TOOLS_BIN_DIR)/$(OUTDATED_BIN)

export GO111MODULE=on

all: check-style dist

## Runs govet and gofmt against all packages.
.PHONY: check-style
check-style: govet lint
check-style: govet lint goformat
@echo Checking for style guide compliance

## Runs lint against all packages.
Expand All @@ -55,6 +62,26 @@ govet:
$(GO) vet ./...
@echo Govet success

## Checks if files are formatted with go fmt.
.PHONY: goformat
goformat:
@echo Checking if code is formatted
@for package in $(PACKAGES); do \
echo "Checking "$$package; \
files=$$(go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}} {{end}}' $$package); \
if [ "$$files" ]; then \
gofmt_output=$$(gofmt -d -s $$files 2>&1); \
if [ "$$gofmt_output" ]; then \
echo "$$gofmt_output"; \
echo "gofmt failed"; \
echo "To fix it, run:"; \
echo "go fmt [FAILED_PACKAGE]"; \
exit 1; \
fi; \
fi; \
done
@echo "gofmt success"; \

## Builds and thats all :)
.PHONY: dist
dist: build
Expand Down Expand Up @@ -163,10 +190,23 @@ deps:
unittest:
$(GO) test ./... -v -covermode=count -coverprofile=coverage.out

.PHONY: check-modules
check-modules: $(OUTDATED_GEN) ## Check outdated modules
@echo Checking outdated modules
$(GO) list -mod=mod -u -m -json all | $(OUTDATED_GEN) -update -direct

.PHONY: update-modules
update-modules: $(OUTDATED_GEN) ## Check outdated modules
@echo Update modules
$(GO) get -u ./...
$(GO) mod tidy

## --------------------------------------
## Tooling Binaries
## --------------------------------------

$(GOPATH)/bin/golangci-lint: ## Install golangci-lint
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCILINT_VER)

$(OUTDATED_GEN): ## Build go-mod-outdated.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/psampaz/go-mod-outdated $(OUTDATED_BIN) $(OUTDATED_VER)
4 changes: 2 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Build the Mattermost Elrond
ARG DOCKER_BUILD_IMAGE=golang:1.22
ARG DOCKER_BASE_IMAGE=alpine:3.19
ARG DOCKER_BUILD_IMAGE=golang:1.23
ARG DOCKER_BASE_IMAGE=alpine:3.20

FROM --platform=${TARGETPLATFORM} ${DOCKER_BUILD_IMAGE} AS build
ARG TARGETARCH
Expand Down
14 changes: 7 additions & 7 deletions cmd/elrond/ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,13 @@ var ringListCmd = &cobra.Command{
table.SetHeader([]string{"ID", "STATE", "NAME", "PRIORITY", "INSTALLATION GROUPS", "SOAK TIME", "REMAINING SOAK TIME", "ACTIVERELEASE", "DESIREDRELEASE", "FORCE", "RELEASE AT"})

for _, ring := range rings {
activeRelease, err := client.GetRingRelease(ring.ActiveReleaseID)
if err != nil {
return errors.Wrap(err, "failed to get active release for table output")
activeRelease, activeReleaseErr := client.GetRingRelease(ring.ActiveReleaseID)
if activeReleaseErr != nil {
return errors.Wrap(activeReleaseErr, "failed to get active release for table output")
}
desiredRelease, err := client.GetRingRelease(ring.DesiredReleaseID)
if err != nil {
return errors.Wrap(err, "failed to get active release for table output")
desiredRelease, desiredReleaseErr := client.GetRingRelease(ring.DesiredReleaseID)
if desiredReleaseErr != nil {
return errors.Wrap(desiredReleaseErr, "failed to get active release for table output")
}

var igs []string
Expand All @@ -441,7 +441,7 @@ var ringListCmd = &cobra.Command{
remainTime = int64(ring.SoakTime) - timePassed
}
}

table.Append([]string{
ring.ID,
ring.State,
Expand Down
62 changes: 30 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/mattermost/elrond

go 1.22
go 1.23

exclude github.com/mattn/go-sqlite3 v2.0.3+incompatible

Expand All @@ -10,17 +10,17 @@ require (
github.com/golang/mock v1.6.0
github.com/gorilla/mux v1.8.1
github.com/grafana/grafana-api-golang-client v0.27.0
github.com/jmoiron/sqlx v1.3.5
github.com/jmoiron/sqlx v1.4.0
github.com/lib/pq v1.10.9
github.com/mattermost/mattermost-cloud v0.83.0
github.com/mattn/go-sqlite3 v1.14.22
github.com/mattermost/mattermost-cloud v0.87.1
github.com/mattn/go-sqlite3 v1.14.24
github.com/olekukonko/tablewriter v0.0.5
github.com/pborman/uuid v1.2.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.0
github.com/prometheus/common v0.52.3
github.com/prometheus/client_golang v1.20.5
github.com/prometheus/common v0.60.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
)

Expand All @@ -31,19 +31,17 @@ replace (
)

require (
github.com/aws/aws-sdk-go v1.51.22 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/aws/aws-sdk-go v1.55.5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic v0.7.0 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand All @@ -55,36 +53,36 @@ require (
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattermost/mattermost-operator v1.21.0 // indirect
github.com/mattermost/mattermost-operator v1.22.1 // indirect
github.com/mattermost/rotator v0.2.1-0.20230830064954-61490ed26761 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.19.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.7.0 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.29.4 // indirect
k8s.io/apimachinery v0.29.4 // indirect
k8s.io/api v0.31.1 // indirect
k8s.io/apimachinery v0.31.1 // indirect
k8s.io/client-go v1.5.2 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240411171206-dc4e619f62f3 // indirect
k8s.io/utils v0.0.0-20240310230437-4693a0247e57 // indirect
sigs.k8s.io/controller-runtime v0.17.3 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20241009091222-67ed5848f094 // indirect
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6 // indirect
sigs.k8s.io/controller-runtime v0.19.0 // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace sigs.k8s.io/json => sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd
Loading

0 comments on commit 4e77a77

Please sign in to comment.