Skip to content

Commit 5051240

Browse files
upgrade to go 1.21
1 parent 4a1d667 commit 5051240

File tree

3 files changed

+59
-26
lines changed

3 files changed

+59
-26
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
jobs:
33
build:
44
docker:
5-
- image: circleci/golang:1.15
5+
- image: cimg/go:1.21
66
environment:
77
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
88
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results

go.mod

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
module github.com/Clever/sphinx
22

3-
go 1.15
3+
go 1.21
44

55
require (
66
github.com/Clever/leakybucket v1.1.0
77
github.com/aws/aws-sdk-go v1.29.34
8+
github.com/pborman/uuid v0.0.0-20180906182336-adf5a7427709
9+
github.com/stretchr/testify v1.5.1
10+
gopkg.in/Clever/kayvee-go.v6 v6.24.0
11+
gopkg.in/tylerb/graceful.v1 v1.2.15
12+
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0
13+
)
14+
15+
require (
16+
github.com/davecgh/go-spew v1.1.1 // indirect
817
github.com/eapache/go-resiliency v1.2.0 // indirect
918
github.com/garyburd/redigo v1.6.0 // indirect
1019
github.com/google/uuid v1.1.1 // indirect
11-
github.com/pborman/uuid v0.0.0-20180906182336-adf5a7427709
20+
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
21+
github.com/pmezard/go-difflib v1.0.0 // indirect
1222
github.com/stretchr/objx v0.2.0 // indirect
13-
github.com/stretchr/testify v1.5.1
1423
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
24+
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
1525
github.com/xeipuuv/gojsonschema v1.2.1-0.20200118195451-b537c054d4b4 // indirect
16-
gopkg.in/Clever/kayvee-go.v6 v6.24.0
17-
gopkg.in/tylerb/graceful.v1 v1.2.15
18-
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0
1926
gopkg.in/yaml.v2 v2.2.8 // indirect
2027
)

golang.mk

+45-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This is the default Clever Golang Makefile.
22
# It is stored in the dev-handbook repo, github.com/Clever/dev-handbook
33
# Please do not alter this file directly.
4-
GOLANG_MK_VERSION := 1.0.0
4+
GOLANG_MK_VERSION := 1.2.1
55

66
SHELL := /bin/bash
77
SYSTEM := $(shell uname -a | cut -d" " -f1 | tr '[:upper:]' '[:lower:]')
@@ -11,7 +11,7 @@ SYSTEM := $(shell uname -a | cut -d" " -f1 | tr '[:upper:]' '[:lower:]')
1111
export TZ=UTC
1212

1313
# go build flags for use across all commands which accept them
14-
GO_BUILD_FLAGS := "-mod=mod"
14+
export GOFLAGS := -mod=vendor $(GOFLAGS)
1515

1616
# if the gopath includes several directories, use only the first
1717
GOPATH=$(shell echo $$GOPATH | cut -d: -f1)
@@ -39,17 +39,19 @@ endef
3939
# so we're defended against it breaking or changing in the future.
4040
FGT := $(GOPATH)/bin/fgt
4141
$(FGT):
42-
go get github.com/GeertJohan/fgt@262f7b11eec07dc7b147c44641236f3212fee89d
42+
go install -mod=readonly github.com/GeertJohan/fgt@262f7b11eec07dc7b147c44641236f3212fee89d
4343

4444
golang-ensure-curl-installed:
4545
@command -v curl >/dev/null 2>&1 || { echo >&2 "curl not installed. Please install curl."; exit 1; }
4646

4747
# Golint is a tool for linting Golang code for common errors.
4848
# We pin its version because an update could add a new lint check which would make
4949
# previously passing tests start failing without changing our code.
50+
# this package is deprecated and frozen
51+
# Infra recomendation is to eventaully move to https://github.com/golangci/golangci-lint so don't fail on linting error for now
5052
GOLINT := $(GOPATH)/bin/golint
5153
$(GOLINT):
52-
go get golang.org/x/lint/golint@738671d3881b9731cc63024d5d88cf28db875626
54+
go install -mod=readonly golang.org/x/lint/golint@738671d3881b9731cc63024d5d88cf28db875626
5355

5456
# golang-fmt-deps requires the FGT tool for checking output
5557
golang-fmt-deps: $(FGT)
@@ -74,22 +76,14 @@ endef
7476
# golang-lint-deps-strict requires the golint tool for golang linting.
7577
golang-lint-deps-strict: $(GOLINT) $(FGT)
7678

77-
# golang-lint-strict calls golint on all golang files in the pkg and fails if any lint
78-
# errors are found.
79-
# arg1: pkg path
80-
define golang-lint-strict
81-
@echo "LINTING $(1)..."
82-
@PKG_PATH=$$(go list -f '{{.Dir}}' $(1)); find $${PKG_PATH}/*.go -type f | grep -v gen_ | xargs $(FGT) $(GOLINT)
83-
endef
84-
8579
# golang-test-deps is here for consistency
8680
golang-test-deps:
8781

8882
# golang-test uses the Go toolchain to run all tests in the pkg.
8983
# arg1: pkg path
9084
define golang-test
9185
@echo "TESTING $(1)..."
92-
@go test $(GO_BUILD_FLAGS) -v $(1)
86+
@go test -v $(1)
9387
endef
9488

9589
# golang-test-strict-deps is here for consistency
@@ -99,7 +93,22 @@ golang-test-strict-deps:
9993
# arg1: pkg path
10094
define golang-test-strict
10195
@echo "TESTING $(1)..."
102-
@go test -v $(GO_BUILD_FLAGS) -race $(1)
96+
@go test -v -race $(1)
97+
endef
98+
99+
# golang-test-strict-cover-deps is here for consistency
100+
golang-test-strict-cover-deps:
101+
102+
# golang-test-strict-cover uses the Go toolchain to run all tests in the pkg with the race and cover flag.
103+
# appends coverage results to coverage.txt
104+
# arg1: pkg path
105+
define golang-test-strict-cover
106+
@echo "TESTING $(1)..."
107+
@go test -v -race -cover -coverprofile=profile.tmp -covermode=atomic $(1)
108+
@if [ -f profile.tmp ]; then \
109+
cat profile.tmp | tail -n +2 >> coverage.txt; \
110+
rm profile.tmp; \
111+
fi;
103112
endef
104113

105114
# golang-vet-deps is here for consistency
@@ -109,7 +118,7 @@ golang-vet-deps:
109118
# arg1: pkg path
110119
define golang-vet
111120
@echo "VETTING $(1)..."
112-
@go vet $(GO_BUILD_FLAGS) $(1)
121+
@go vet $(1)
113122
endef
114123

115124
# golang-test-all-deps installs all dependencies needed for different test cases.
@@ -132,24 +141,41 @@ golang-test-all-strict-deps: golang-fmt-deps golang-lint-deps-strict golang-test
132141
# arg1: pkg path
133142
define golang-test-all-strict
134143
$(call golang-fmt,$(1))
135-
$(call golang-lint-strict,$(1))
144+
$(call golang-lint,$(1))
136145
$(call golang-vet,$(1))
137146
$(call golang-test-strict,$(1))
138147
endef
139148

149+
# golang-test-all-strict-cover-deps: installs all dependencies needed for different test cases.
150+
golang-test-all-strict-cover-deps: golang-fmt-deps golang-lint-deps-strict golang-test-strict-cover-deps golang-vet-deps
151+
152+
# golang-test-all-strict-cover calls fmt, lint, vet and test on the specified pkg with strict and cover
153+
# requirements that no errors are thrown while linting.
154+
# arg1: pkg path
155+
define golang-test-all-strict-cover
156+
$(call golang-fmt,$(1))
157+
$(call golang-lint,$(1))
158+
$(call golang-vet,$(1))
159+
$(call golang-test-strict-cover,$(1))
160+
endef
161+
140162
# golang-build: builds a golang binary. ensures CGO build is done during CI. This is needed to make a binary that works with a Docker alpine image.
141163
# arg1: pkg path
142164
# arg2: executable name
143165
define golang-build
144-
@echo "BUILDING..."
166+
@echo "BUILDING $(2)..."
145167
@if [ -z "$$CI" ]; then \
146-
go build $(GO_BUILD_FLAGS) -o bin/$(2) $(1); \
168+
go build -o bin/$(2) $(1); \
147169
else \
148170
echo "-> Building CGO binary"; \
149-
CGO_ENABLED=0 go build $(GO_BUILD_FLAGS) -installsuffix cgo -o bin/$(2) $(1); \
171+
CGO_ENABLED=0 go build -installsuffix cgo -o bin/$(2) $(1); \
150172
fi;
151173
endef
152174

175+
# golang-setup-coverage: set up the coverage file
176+
golang-setup-coverage:
177+
@echo "mode: atomic" > coverage.txt
178+
153179
# golang-update-makefile downloads latest version of golang.mk
154180
golang-update-makefile:
155181
@wget https://raw.githubusercontent.com/Clever/dev-handbook/master/make/golang-v1.mk -O /tmp/golang.mk 2>/dev/null

0 commit comments

Comments
 (0)