Skip to content

Commit

Permalink
Merge pull request #32 from Clever/go-modules
Browse files Browse the repository at this point in the history
[automated] Migrate from dep to go mod
  • Loading branch information
taylor-sutton authored Jul 15, 2021
2 parents 6813c7d + 607d01d commit f5bff19
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 95 deletions.
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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://[email protected]/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;
14 changes: 0 additions & 14 deletions Gopkg.lock

This file was deleted.

25 changes: 0 additions & 25 deletions Gopkg.toml

This file was deleted.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ clean:
rm -rf build release


install_deps: golang-dep-vendor-deps
$(call golang-dep-vendor)
install_deps:
go mod vendor
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.3.0
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/Clever/csvlint

go 1.13

require github.com/stretchr/testify v1.6.1
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
73 changes: 20 additions & 53 deletions golang.mk
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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/<org>/<repo>"
# `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)
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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

0 comments on commit f5bff19

Please sign in to comment.