From fa469efcf5a23d3a65245cf649445e07e71206ff Mon Sep 17 00:00:00 2001 From: Chris Martin <101210272+ChrisScotMartin@users.noreply.github.com> Date: Fri, 22 Sep 2023 11:58:12 -0400 Subject: [PATCH 1/2] upgrade to go 1.21 --- .circleci/config.yml | 4 +-- go.mod | 13 ++++++--- go.sum | 4 --- golang.mk | 64 +++++++++++++++++++++++++++++++------------- tools/tools.go | 2 ++ 5 files changed, 58 insertions(+), 29 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index cd233bd..54fd56a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/go.mod b/go.mod index aebcaf1..116db08 100644 --- a/go.mod +++ b/go.mod @@ -1,18 +1,23 @@ 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 gopkg.in/yaml.v2 v2.2.3-0.20190319135612-7b8349ac747c // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 90520b0..857f5c4 100644 --- a/go.sum +++ b/go.sum @@ -23,7 +23,6 @@ github.com/xeipuuv/gojsonschema v1.1.1-0.20190423132807-354ad34c2300/go.mod h1:5 github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -35,7 +34,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -45,11 +43,9 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZe golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/Clever/kayvee-go.v6 v6.24.0 h1:xOpO9c3by6CqnbWpdhzwsK+mEpNk7HKceHpVvoWFudU= gopkg.in/Clever/kayvee-go.v6 v6.24.0/go.mod h1:G0m6nBZj7Kdz+w2hiIaawmhXl5zp7E/K0ashol3Kb2A= diff --git a/golang.mk b/golang.mk index 18e211c..db81955 100644 --- a/golang.mk +++ b/golang.mk @@ -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:]') @@ -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) @@ -39,7 +39,7 @@ 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; } @@ -47,9 +47,11 @@ golang-ensure-curl-installed: # 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) @@ -74,14 +76,6 @@ 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: @@ -89,7 +83,7 @@ golang-test-deps: # 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 @@ -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 @@ -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. @@ -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 diff --git a/tools/tools.go b/tools/tools.go index 8b7a2e0..546d3dd 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -1,4 +1,6 @@ +//go:build tools // +build tools + // see https://github.com/golang/go/issues/25922 package main From ec2ea112813a15bf4a9a4c2b9f1178bef062a832 Mon Sep 17 00:00:00 2001 From: Chris Martin <101210272+ChrisScotMartin@users.noreply.github.com> Date: Wed, 25 Oct 2023 13:49:59 -0400 Subject: [PATCH 2/2] buffer that channel --- Makefile | 2 +- cmd/sfncli/runner.go | 3 ++- go.mod | 4 ++++ go.sum | 4 ++++ tools/tools.go | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index bde8efa..e0f68dc 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/cmd/sfncli/runner.go b/cmd/sfncli/runner.go index 183e2bc..709f780 100644 --- a/cmd/sfncli/runner.go +++ b/cmd/sfncli/runner.go @@ -172,7 +172,8 @@ func (t *TaskRunner) Process(ctx context.Context, args []string, input string) e } func (t *TaskRunner) handleSignals(ctx context.Context) { - sigChan := make(chan os.Signal) + // 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) for { diff --git a/go.mod b/go.mod index 116db08..bca3730 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,10 @@ require ( 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/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 ) diff --git a/go.sum b/go.sum index 857f5c4..90520b0 100644 --- a/go.sum +++ b/go.sum @@ -23,6 +23,7 @@ github.com/xeipuuv/gojsonschema v1.1.1-0.20190423132807-354ad34c2300/go.mod h1:5 github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -34,6 +35,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -43,9 +45,11 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZe golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/Clever/kayvee-go.v6 v6.24.0 h1:xOpO9c3by6CqnbWpdhzwsK+mEpNk7HKceHpVvoWFudU= gopkg.in/Clever/kayvee-go.v6 v6.24.0/go.mod h1:G0m6nBZj7Kdz+w2hiIaawmhXl5zp7E/K0ashol3Kb2A= diff --git a/tools/tools.go b/tools/tools.go index 546d3dd..470d18b 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -6,5 +6,5 @@ package main import ( - _ "github.com/golang/mock/gomock" + _ "github.com/golang/mock/mockgen" )