Skip to content

Commit

Permalink
Merge pull request #111 from Clever/go1.21-update
Browse files Browse the repository at this point in the history
upgrade to go 1.21
  • Loading branch information
philippeclever authored Sep 25, 2024
2 parents dd1a56e + e7e3656 commit de0701d
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: 2
jobs:
build:
working_directory: /go/src/github.com/Clever/sfncli
working_directory: ~/go/src/github.com/Clever/sfncli
docker:
- image: circleci/golang:1.13-stretch
- image: cimg/go:1.21
environment:
GOPRIVATE: github.com/Clever/*
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ clean:

mocks:
mkdir -p bin
go build -o ./bin/mockgen github.com/golang/mock/mockgen
go build -o bin/mockgen -mod=vendor ./vendor/github.com/golang/mock/mockgen
rm -rf mocks/mock_*.go
./bin/mockgen -source ./vendor/github.com/aws/aws-sdk-go/service/sfn/sfniface/interface.go -destination mocks/mock_sfn.go -package mocks
./bin/mockgen -source ./vendor/github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface/interface.go -destination mocks/mock_cloudwatch.go -package mocks
Expand Down
1 change: 1 addition & 0 deletions cmd/sfncli/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func (t *TaskRunner) Process(ctx context.Context, args []string, input string) e
}

func (t *TaskRunner) handleSignals(ctx context.Context) {
// a buffer of one should be safe here as we're basically just catching container exits
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan)
defer signal.Stop(sigChan)
Expand Down
17 changes: 13 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
module github.com/Clever/sfncli

go 1.13
go 1.21

require (
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e
github.com/aws/aws-sdk-go v1.23.13
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/mock v1.6.0
github.com/stretchr/testify v1.7.0
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
gopkg.in/Clever/kayvee-go.v6 v6.24.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.1.1-0.20190423132807-354ad34c2300 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
gopkg.in/Clever/kayvee-go.v6 v6.24.0
golang.org/x/mod v0.4.2 // indirect
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
golang.org/x/tools v0.1.1 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/yaml.v2 v2.2.3-0.20190319135612-7b8349ac747c // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
64 changes: 45 additions & 19 deletions golang.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This is the default Clever Golang Makefile.
# It is stored in the dev-handbook repo, github.com/Clever/dev-handbook
# Please do not alter this file directly.
GOLANG_MK_VERSION := 1.0.0
GOLANG_MK_VERSION := 1.2.1

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

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

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

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

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

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

# golang-lint-strict calls golint on all golang files in the pkg and fails if any lint
# errors are found.
# arg1: pkg path
define golang-lint-strict
@echo "LINTING $(1)..."
@PKG_PATH=$$(go list -f '{{.Dir}}' $(1)); find $${PKG_PATH}/*.go -type f | grep -v gen_ | xargs $(FGT) $(GOLINT)
endef

# golang-test-deps is here for consistency
golang-test-deps:

# golang-test uses the Go toolchain to run all tests in the pkg.
# arg1: pkg path
define golang-test
@echo "TESTING $(1)..."
@go test $(GO_BUILD_FLAGS) -v $(1)
@go test -v $(1)
endef

# golang-test-strict-deps is here for consistency
Expand All @@ -99,7 +93,22 @@ golang-test-strict-deps:
# arg1: pkg path
define golang-test-strict
@echo "TESTING $(1)..."
@go test -v $(GO_BUILD_FLAGS) -race $(1)
@go test -v -race $(1)
endef

# golang-test-strict-cover-deps is here for consistency
golang-test-strict-cover-deps:

# golang-test-strict-cover uses the Go toolchain to run all tests in the pkg with the race and cover flag.
# appends coverage results to coverage.txt
# arg1: pkg path
define golang-test-strict-cover
@echo "TESTING $(1)..."
@go test -v -race -cover -coverprofile=profile.tmp -covermode=atomic $(1)
@if [ -f profile.tmp ]; then \
cat profile.tmp | tail -n +2 >> coverage.txt; \
rm profile.tmp; \
fi;
endef

# golang-vet-deps is here for consistency
Expand All @@ -109,7 +118,7 @@ golang-vet-deps:
# arg1: pkg path
define golang-vet
@echo "VETTING $(1)..."
@go vet $(GO_BUILD_FLAGS) $(1)
@go vet $(1)
endef

# golang-test-all-deps installs all dependencies needed for different test cases.
Expand All @@ -132,24 +141,41 @@ golang-test-all-strict-deps: golang-fmt-deps golang-lint-deps-strict golang-test
# arg1: pkg path
define golang-test-all-strict
$(call golang-fmt,$(1))
$(call golang-lint-strict,$(1))
$(call golang-lint,$(1))
$(call golang-vet,$(1))
$(call golang-test-strict,$(1))
endef

# golang-test-all-strict-cover-deps: installs all dependencies needed for different test cases.
golang-test-all-strict-cover-deps: golang-fmt-deps golang-lint-deps-strict golang-test-strict-cover-deps golang-vet-deps

# golang-test-all-strict-cover calls fmt, lint, vet and test on the specified pkg with strict and cover
# requirements that no errors are thrown while linting.
# arg1: pkg path
define golang-test-all-strict-cover
$(call golang-fmt,$(1))
$(call golang-lint,$(1))
$(call golang-vet,$(1))
$(call golang-test-strict-cover,$(1))
endef

# 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.
# arg1: pkg path
# arg2: executable name
define golang-build
@echo "BUILDING..."
@echo "BUILDING $(2)..."
@if [ -z "$$CI" ]; then \
go build $(GO_BUILD_FLAGS) -o bin/$(2) $(1); \
go build -o bin/$(2) $(1); \
else \
echo "-> Building CGO binary"; \
CGO_ENABLED=0 go build $(GO_BUILD_FLAGS) -installsuffix cgo -o bin/$(2) $(1); \
CGO_ENABLED=0 go build -installsuffix cgo -o bin/$(2) $(1); \
fi;
endef

# golang-setup-coverage: set up the coverage file
golang-setup-coverage:
@echo "mode: atomic" > coverage.txt

# golang-update-makefile downloads latest version of golang.mk
golang-update-makefile:
@wget https://raw.githubusercontent.com/Clever/dev-handbook/master/make/golang-v1.mk -O /tmp/golang.mk 2>/dev/null
Expand Down
4 changes: 3 additions & 1 deletion tools/tools.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//go:build tools
// +build tools

// see https://github.com/golang/go/issues/25922

package main

import (
_ "github.com/golang/mock/gomock"
_ "github.com/golang/mock/mockgen"
)

0 comments on commit de0701d

Please sign in to comment.