From 54cc696ee1ae1e09b4a376fe22df2d02bc5c46d2 Mon Sep 17 00:00:00 2001 From: Jake Gutierrez Date: Fri, 6 Dec 2024 12:39:45 -0600 Subject: [PATCH] update to go1.21, release darwin-arm64 --- .circleci/config.yml | 2 +- Godeps/Godeps.json | 30 ---------- Godeps/Readme | 5 -- Makefile | 8 ++- VERSION | 2 +- go.mod | 10 +++- golang.mk | 137 +++++++++++++++++++++---------------------- 7 files changed, 82 insertions(+), 112 deletions(-) delete mode 100644 Godeps/Godeps.json delete mode 100644 Godeps/Readme diff --git a/.circleci/config.yml b/.circleci/config.yml index b60e30f..aa868a5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ jobs: build: working_directory: /go/src/github.com/Clever/reposync 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/Godeps/Godeps.json b/Godeps/Godeps.json deleted file mode 100644 index 135c5b5..0000000 --- a/Godeps/Godeps.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "ImportPath": "github.com/rgarcia/reposync", - "GoVersion": "go1.6", - "GodepVersion": "v62", - "Packages": [ - "github.com/rgarcia/reposync" - ], - "Deps": [ - { - "ImportPath": "github.com/google/go-github/github", - "Rev": "7f154f4cabd28c7b5962c37a5f59bb813ae3791a" - }, - { - "ImportPath": "github.com/google/go-querystring/query", - "Rev": "9235644dd9e52eeae6fa48efd539fdc351a0af53" - }, - { - "ImportPath": "golang.org/x/net/context", - "Rev": "fb93926129b8ec0056f2f458b1f519654814edf0" - }, - { - "ImportPath": "golang.org/x/oauth2", - "Rev": "b0e2337fe6ec0c637fa4f123268b972f334504eb" - }, - { - "ImportPath": "golang.org/x/oauth2/internal", - "Rev": "b0e2337fe6ec0c637fa4f123268b972f334504eb" - } - ] -} diff --git a/Godeps/Readme b/Godeps/Readme deleted file mode 100644 index 4cdaa53..0000000 --- a/Godeps/Readme +++ /dev/null @@ -1,5 +0,0 @@ -This directory tree is generated automatically by godep. - -Please do not edit. - -See https://github.com/tools/godep for more information. diff --git a/Makefile b/Makefile index 99a5b42..a16e6eb 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ VERSION := $(shell cat VERSION) .PHONY: all build clean test vendor release $(PKGS) -$(eval $(call golang-version-check,1.13)) +$(eval $(call golang-version-check,1.21)) all: test build @@ -26,10 +26,12 @@ run: build ./bin/$(EXECUTABLE) release: - @GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.version=$(VERSION)" \ + @GOOS=linux GOARCH=amd64 go build -tags netcgo -ldflags="-s -w -X main.Version=$(VERSION)" \ -o="$@/$(EXECUTABLE)-$(VERSION)-linux-amd64" - @GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.version=$(VERSION)" \ + @GOOS=darwin GOARCH=amd64 go build -tags netcgo -ldflags="-s -w -X main.Version=$(VERSION)" \ -o="$@/$(EXECUTABLE)-$(VERSION)-darwin-amd64" + @GOOS=darwin GOARCH=arm64 go build -tags netcgo -ldflags="-s -w -X main.Version=$(VERSION)" \ + -o="$@/$(EXECUTABLE)-$(VERSION)-darwin-arm64" clean: rm -rf bin/* diff --git a/VERSION b/VERSION index faef31a..a3df0a6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.0 +0.8.0 diff --git a/go.mod b/go.mod index 7752d91..9a1351d 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,17 @@ module github.com/Clever/reposync -go 1.13 +go 1.21 + +require ( + github.com/google/go-github v0.0.0-20160409185117-7f154f4cabd2 + golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be +) require ( github.com/golang/protobuf v1.4.2 // indirect github.com/google/go-cmp v0.5.4 // indirect - github.com/google/go-github v0.0.0-20160409185117-7f154f4cabd2 github.com/google/go-querystring v0.0.0-20160401233042-9235644dd9e5 // indirect golang.org/x/net v0.0.0-20191002035440-2ec189313ef0 // indirect - golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be google.golang.org/appengine v1.4.0 // indirect + google.golang.org/protobuf v1.23.0 // indirect ) diff --git a/golang.mk b/golang.mk index a25558c..c570cbe 100644 --- a/golang.mk +++ b/golang.mk @@ -1,15 +1,18 @@ # 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 := 0.5.0 +GOLANG_MK_VERSION := 1.3.0 SHELL := /bin/bash SYSTEM := $(shell uname -a | cut -d" " -f1 | tr '[:upper:]' '[:lower:]') -.PHONY: golang-test-deps bin/dep golang-ensure-curl-installed +.PHONY: golang-test-deps golang-ensure-curl-installed # set timezone to UTC for golang to match circle and deploys export TZ=UTC +# go build flags for use across all commands which accept them +export GOFLAGS := -mod=vendor $(GOFLAGS) + # if the gopath includes several directories, use only the first GOPATH=$(shell echo $$GOPATH | cut -d: -f1) @@ -32,57 +35,23 @@ _ := $(if \ endef # FGT is a utility that exits with 1 whenever any stderr/stdout output is recieved. +# We pin its version since its a simple tool that does its job as-is; +# so we're defended against it breaking or changing in the future. FGT := $(GOPATH)/bin/fgt $(FGT): - go get github.com/GeertJohan/fgt + 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; } -DEP_VERSION = v0.5.4 -DEP_INSTALLED := $(shell [[ -e "bin/dep" ]] && bin/dep version | grep version | grep -v go | cut -d: -f2 | tr -d '[:space:]') -# Dep is a tool used to manage Golang dependencies. It is the offical vendoring experiment, but -# not yet the official tool for Golang. -ifeq ($(DEP_VERSION),$(DEP_INSTALLED)) -bin/dep: # nothing to do, dep is already up-to-date -else -CACHED_DEP = /tmp/dep-$(DEP_VERSION) -bin/dep: golang-ensure-curl-installed - @echo "Updating dep..." - @mkdir -p bin - @if [ ! -f $(CACHED_DEP) ]; then curl -o $(CACHED_DEP) -sL https://github.com/golang/dep/releases/download/$(DEP_VERSION)/dep-$(SYSTEM)-amd64; fi; - @cp $(CACHED_DEP) bin/dep - @chmod +x bin/dep || true -endif - -# figure out "github.com//" -# `go list` will fail if there are no .go files in the directory -# if this is the case, fall back to assuming github.com/Clever -REF = $(shell go list || echo github.com/Clever/$(notdir $(shell pwd))) -golang-verify-no-self-references: - @if grep -q -i "$(REF)" Gopkg.lock; then echo "Error: Gopkg.lock includes a self-reference ($(REF)), which is not allowed. See: https://github.com/golang/dep/issues/1690" && exit 1; fi; - @if grep -q -i "$(REF)" Gopkg.toml; then echo "Error: Gopkg.toml includes a self-reference ($(REF)), which is not allowed. See: https://github.com/golang/dep/issues/1690" && exit 1; fi; - -golang-dep-vendor-deps: bin/dep golang-verify-no-self-references - -# golang-godep-vendor is a target for saving dependencies with the dep tool -# to the vendor/ directory. All nested vendor/ directories are deleted via -# the prune command. -# In CI, -vendor-only is used to avoid updating the lock file. -ifndef CI -define golang-dep-vendor -bin/dep ensure -v -endef -else -define golang-dep-vendor -bin/dep ensure -v -vendor-only -endef -endif - # 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 + go install -mod=readonly golang.org/x/lint/golint@738671d3881b9731cc63024d5d88cf28db875626 # golang-fmt-deps requires the FGT tool for checking output golang-fmt-deps: $(FGT) @@ -91,7 +60,7 @@ golang-fmt-deps: $(FGT) # arg1: pkg path define golang-fmt @echo "FORMATTING $(1)..." -@$(FGT) gofmt -l=true $(GOPATH)/src/$(1)/*.go +@PKG_PATH=$$(go list -f '{{.Dir}}' $(1)); $(FGT) gofmt -l=true $${PKG_PATH}/*.go endef # golang-lint-deps requires the golint tool for golang linting. @@ -101,20 +70,12 @@ golang-lint-deps: $(GOLINT) # arg1: pkg path define golang-lint @echo "LINTING $(1)..." -@find $(GOPATH)/src/$(1)/*.go -type f | grep -v gen_ | xargs $(GOLINT) +@PKG_PATH=$$(go list -f '{{.Dir}}' $(1)); find $${PKG_PATH}/*.go -type f | grep -v gen_ | xargs $(GOLINT) 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)..." -@find $(GOPATH)/src/$(1)/*.go -type f | grep -v gen_ | xargs $(FGT) $(GOLINT) -endef - # golang-test-deps is here for consistency golang-test-deps: @@ -135,6 +96,21 @@ define golang-test-strict @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 golang-vet-deps: @@ -142,7 +118,7 @@ golang-vet-deps: # arg1: pkg path define golang-vet @echo "VETTING $(1)..." -@go vet $(GOPATH)/src/$(1)/*.go +@go vet $(1) endef # golang-test-all-deps installs all dependencies needed for different test cases. @@ -165,30 +141,53 @@ 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-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. +# 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 # arg1: pkg path # arg2: executable name define golang-build -@echo "BUILDING..." -@if [ -z "$$CI" ]; then \ - go build -o bin/$(2) $(1); \ -else \ - echo "-> Building CGO binary"; \ - CGO_ENABLED=0 go build -installsuffix cgo -o bin/$(2) $(1); \ -fi; +@@echo "BUILDING $(2)..." +@CGO_ENABLED=0 go build -o bin/$(2) $(1); endef +# golang-debug-build: builds a golang binary with debugging capabilities +# arg1: pkg path +# arg2: executable name +define golang-debug-build +@echo "BUILDING $(2) FOR DEBUG..." +@CGO_ENABLED=0 go build -gcflags="all=-N -l" -o bin/$(2) $(1); +endef + +# golang-cgo-build: builds a golang binary with CGO +# arg1: pkg path +# arg2: executable name +define golang-cgo-build +@echo "BUILDING $(2) WITH CGO ..." +@CGO_ENABLED=1 go build -installsuffix cgo -o bin/$(2) $(1); +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.mk -O /tmp/golang.mk 2>/dev/null - @if ! grep -q $(GOLANG_MK_VERSION) /tmp/golang.mk; then cp /tmp/golang.mk golang.mk && echo "golang.mk updated"; else echo "golang.mk is up-to-date"; fi - -# golang-major-update-makefile downloads latest version of golang.mk to the next major version, 1.x.x -golang-major-update-makefile-v1: @wget https://raw.githubusercontent.com/Clever/dev-handbook/master/make/golang-v1.mk -O /tmp/golang.mk 2>/dev/null @if ! grep -q $(GOLANG_MK_VERSION) /tmp/golang.mk; then cp /tmp/golang.mk golang.mk && echo "golang.mk updated"; else echo "golang.mk is up-to-date"; fi