From 607d01debe0d89934fc30110bf3ed7d24ff2bbe2 Mon Sep 17 00:00:00 2001 From: Taylor Sutton Date: Thu, 15 Jul 2021 16:48:59 -0400 Subject: [PATCH] [automated] Migrate from dep to go mod --- .circleci/config.yml | 6 ++++ Gopkg.lock | 14 --------- Gopkg.toml | 25 --------------- Makefile | 4 +-- VERSION | 2 +- go.mod | 5 +++ go.sum | 11 +++++++ golang.mk | 73 ++++++++++++-------------------------------- 8 files changed, 45 insertions(+), 95 deletions(-) delete mode 100644 Gopkg.lock delete mode 100644 Gopkg.toml create mode 100644 go.mod create mode 100644 go.sum diff --git a/.circleci/config.yml b/.circleci/config.yml index 62afe6d..fcd31f6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,6 +5,7 @@ jobs: docker: - image: circleci/golang:1.13-stretch environment: + GOPRIVATE: github.com/Clever/* CIRCLE_ARTIFACTS: /tmp/circleci-artifacts CIRCLE_TEST_REPORTS: /tmp/circleci-test-results steps: @@ -16,6 +17,11 @@ jobs: - run: command: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS name: Set up CircleCI artifacts directories + - run: + command: git config --global "url.ssh://git@github.com/Clever".insteadOf "https://github.com/Clever" + - run: + name: Add github.com to known hosts + command: mkdir -p ~/.ssh && touch ~/.ssh/known_hosts && echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==' >> ~/.ssh/known_hosts - run: make install_deps - run: make test - run: if [ "${CIRCLE_BRANCH}" == "master" ]; then make release && $HOME/ci-scripts/circleci/github-release $GH_RELEASE_TOKEN release; fi; diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index 38a38cb..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,14 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - name = "github.com/stretchr/testify" - packages = ["assert"] - revision = "2eaa4b48b8954bf871229043b8064ca156a542a5" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "c940d1337f45f8152f2f5a9070e0260267261b8089ca6aeab1020e71dfb4253d" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index adff59e..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,25 +0,0 @@ - -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" - - -[[constraint]] - name = "github.com/stretchr/testify" diff --git a/Makefile b/Makefile index b4c2688..78e1cb3 100644 --- a/Makefile +++ b/Makefile @@ -44,5 +44,5 @@ clean: rm -rf build release -install_deps: golang-dep-vendor-deps - $(call golang-dep-vendor) \ No newline at end of file +install_deps: + go mod vendor diff --git a/VERSION b/VERSION index 0ea3a94..0d91a54 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.0 +0.3.0 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..36e6419 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/Clever/csvlint + +go 1.13 + +require github.com/stretchr/testify v1.6.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..afe7890 --- /dev/null +++ b/go.sum @@ -0,0 +1,11 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/golang.mk b/golang.mk index 6035eac..18e211c 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.4.0 +GOLANG_MK_VERSION := 1.0.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 +GO_BUILD_FLAGS := "-mod=vendor" + # if the gopath includes several directories, use only the first GOPATH=$(shell echo $$GOPATH | cut -d: -f1) @@ -32,57 +35,21 @@ _ := $(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 get 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.4.1 -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. GOLINT := $(GOPATH)/bin/golint $(GOLINT): - go get golang.org/x/lint/golint + go get golang.org/x/lint/golint@738671d3881b9731cc63024d5d88cf28db875626 # golang-fmt-deps requires the FGT tool for checking output golang-fmt-deps: $(FGT) @@ -91,7 +58,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,7 +68,7 @@ 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. @@ -112,7 +79,7 @@ golang-lint-deps-strict: $(GOLINT) $(FGT) # arg1: pkg path define golang-lint-strict @echo "LINTING $(1)..." -@find $(GOPATH)/src/$(1)/*.go -type f | grep -v gen_ | xargs $(FGT) $(GOLINT) +@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 @@ -122,7 +89,7 @@ golang-test-deps: # arg1: pkg path define golang-test @echo "TESTING $(1)..." -@go test -v $(1) +@go test $(GO_BUILD_FLAGS) -v $(1) endef # golang-test-strict-deps is here for consistency @@ -132,7 +99,7 @@ golang-test-strict-deps: # arg1: pkg path define golang-test-strict @echo "TESTING $(1)..." -@go test -v -race $(1) +@go test -v $(GO_BUILD_FLAGS) -race $(1) endef # golang-vet-deps is here for consistency @@ -142,7 +109,7 @@ golang-vet-deps: # arg1: pkg path define golang-vet @echo "VETTING $(1)..." -@go vet $(GOPATH)/src/$(1)/*.go +@go vet $(GO_BUILD_FLAGS) $(1) endef # golang-test-all-deps installs all dependencies needed for different test cases. @@ -176,14 +143,14 @@ endef define golang-build @echo "BUILDING..." @if [ -z "$$CI" ]; then \ - go build -o bin/$(2) $(1); \ + go build $(GO_BUILD_FLAGS) -o bin/$(2) $(1); \ else \ echo "-> Building CGO binary"; \ - CGO_ENABLED=0 go build -installsuffix cgo -o bin/$(2) $(1); \ + CGO_ENABLED=0 go build $(GO_BUILD_FLAGS) -installsuffix cgo -o bin/$(2) $(1); \ fi; endef # 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 + @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