diff --git a/.circleci/config.yml b/.circleci/config.yml index 877efa3..49dfc6a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,9 +1,8 @@ version: 2 jobs: build: - working_directory: /go/src/github.com/Clever/sphinx docker: - - image: circleci/golang:1.13-stretch + - image: circleci/golang:1.15 environment: CIRCLE_ARTIFACTS: /tmp/circleci-artifacts CIRCLE_TEST_REPORTS: /tmp/circleci-test-results @@ -12,12 +11,18 @@ jobs: command: cd $HOME && git clone --depth 1 -v https://github.com/Clever/ci-scripts.git && cd ci-scripts && git show --oneline -s name: Clone ci-scripts - checkout + - restore_cache: + keys: + - go-mod-v1-{{ checksum "go.sum" }} - setup_remote_docker - run: command: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS name: Set up CircleCI artifacts directories - - run: make install_deps - run: make build - run: make test - run: $HOME/ci-scripts/circleci/docker-publish $DOCKER_USER $DOCKER_PASS "$DOCKER_EMAIL" $DOCKER_ORG - run: if [ "${CIRCLE_BRANCH}" == "master" ]; then make VERSION && make deb && cp deb/sphinx.deb sphinx-amd64.deb && $HOME/ci-scripts/circleci/github-release $GH_RELEASE_TOKEN sphinx-amd64.deb; fi; + - save_cache: + key: go-mod-v1-{{ checksum "go.sum" }} + paths: + - "/go/pkg/mod" diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index 0052b2c..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,222 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - digest = "1:1cd3aecaaa57090a7a977ef3c4233beae614cc095874bc2f2f219323d7afb9d9" - name = "github.com/Clever/leakybucket" - packages = [ - ".", - "dynamodb", - "memory", - "redis", - ] - pruneopts = "" - revision = "9023cbf8e611568125ce6d165d070b6686efc65e" - version = "v1.1.0" - -[[projects]] - digest = "1:0fc946169edf6aed7facaf8d0893f40aa1a3a363a4fae5e0cb4ff07fe3532655" - name = "github.com/aws/aws-sdk-go" - packages = [ - "aws", - "aws/awserr", - "aws/awsutil", - "aws/client", - "aws/client/metadata", - "aws/corehandlers", - "aws/credentials", - "aws/credentials/ec2rolecreds", - "aws/credentials/endpointcreds", - "aws/credentials/processcreds", - "aws/credentials/stscreds", - "aws/crr", - "aws/csm", - "aws/defaults", - "aws/ec2metadata", - "aws/endpoints", - "aws/request", - "aws/session", - "aws/signer/v4", - "internal/context", - "internal/ini", - "internal/sdkio", - "internal/sdkmath", - "internal/sdkrand", - "internal/sdkuri", - "internal/shareddefaults", - "internal/strings", - "internal/sync/singleflight", - "private/protocol", - "private/protocol/json/jsonutil", - "private/protocol/jsonrpc", - "private/protocol/query", - "private/protocol/query/queryutil", - "private/protocol/rest", - "private/protocol/xml/xmlutil", - "service/dynamodb", - "service/dynamodb/dynamodbattribute", - "service/dynamodb/dynamodbiface", - "service/sts", - "service/sts/stsiface", - ] - pruneopts = "" - revision = "38d919b886b050f26e53e5de9bd3b3ba46f018e8" - version = "v1.29.34" - -[[projects]] - digest = "1:0deddd908b6b4b768cfc272c16ee61e7088a60f7fe2f06c547bd3d8e1f8b8e77" - name = "github.com/davecgh/go-spew" - packages = ["spew"] - pruneopts = "" - revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" - version = "v1.1.1" - -[[projects]] - digest = "1:8c9af6e3162383951dee97404fadb761f9ae60b4806998df288a5b143afa7251" - name = "github.com/eapache/go-resiliency" - packages = ["retrier"] - pruneopts = "" - revision = "5efd2ed019fd331ec2defc6f3bd98882f1e3e636" - version = "v1.2.0" - -[[projects]] - digest = "1:9525d0e79ccf382e32edeef466b9a91f16eb0eebdca5971a03fad1bb3be9cd89" - name = "github.com/garyburd/redigo" - packages = [ - "internal", - "redis", - ] - pruneopts = "" - revision = "a69d19351219b6dd56f274f96d85a7014a2ec34e" - version = "v1.6.0" - -[[projects]] - digest = "1:ad92aa49f34cbc3546063c7eb2cabb55ee2278b72842eda80e2a20a8a06a8d73" - name = "github.com/google/uuid" - packages = ["."] - pruneopts = "" - revision = "0cd6bf5da1e1c83f8b45653022c74f71af0538a4" - version = "v1.1.1" - -[[projects]] - digest = "1:13fe471d0ed891e8544eddfeeb0471fd3c9f2015609a1c000aefdedf52a19d40" - name = "github.com/jmespath/go-jmespath" - packages = ["."] - pruneopts = "" - revision = "c2b33e84" - -[[projects]] - digest = "1:a5484d4fa43127138ae6e7b2299a6a52ae006c7f803d98d717f60abf3e97192e" - name = "github.com/pborman/uuid" - packages = ["."] - pruneopts = "" - revision = "adf5a7427709b9deb95d29d3fa8a2bf9cfd388f1" - version = "v1.2" - -[[projects]] - digest = "1:256484dbbcd271f9ecebc6795b2df8cad4c458dd0f5fd82a8c2fa0c29f233411" - name = "github.com/pmezard/go-difflib" - packages = ["difflib"] - pruneopts = "" - revision = "792786c7400a136282c1664665ae0a8db921c6c2" - version = "v1.0.0" - -[[projects]] - digest = "1:88e031206b52c11a8442f3f07e9bcddc1b248274d0506c768a948e7e254b84bb" - name = "github.com/stretchr/objx" - packages = ["."] - pruneopts = "" - revision = "ea4fe68685ee0d3cee7032121851b57e7494e8ea" - version = "v0.2.0" - -[[projects]] - digest = "1:cc4eb6813da8d08694e557fcafae8fcc24f47f61a0717f952da130ca9a486dfc" - name = "github.com/stretchr/testify" - packages = [ - "assert", - "mock", - ] - pruneopts = "" - revision = "3ebf1ddaeb260c4b1ae502a01c7844fa8c1fa0e9" - version = "v1.5.1" - -[[projects]] - branch = "master" - digest = "1:5372ed388f189f6204f1864a2bae1ce9bbdf33f47528ffc776d31a649e3978aa" - name = "github.com/xeipuuv/gojsonpointer" - packages = ["."] - pruneopts = "" - revision = "02993c407bfbf5f6dae44c4f4b1cf6a39b5fc5bb" - -[[projects]] - branch = "master" - digest = "1:604f98a38394d2805a78c462396a4992b93fdd5b7306130add330f1a99ac6b0a" - name = "github.com/xeipuuv/gojsonreference" - packages = ["."] - pruneopts = "" - revision = "bd5ef7bd5415a7ac448318e64f11a24cd21e594b" - -[[projects]] - branch = "master" - digest = "1:43ea491ae2a23ad30fe6273b50d2ecafa93b98f7ab8e3d0f533b39337c25930e" - name = "github.com/xeipuuv/gojsonschema" - packages = ["."] - pruneopts = "" - revision = "b537c054d4b486d62f64a76b8d48fdf38a0ea99d" - -[[projects]] - digest = "1:0923ed679d96b9e53b8c43892e2094ebb5dccd0a66709b20c90f43c37ff71ff1" - name = "gopkg.in/Clever/kayvee-go.v6" - packages = [ - ".", - "logger", - "middleware", - "router", - ] - pruneopts = "" - revision = "1c544ce9daf62e3673f4f1ba0bffde53cd13f502" - version = "v6.24.0" - -[[projects]] - digest = "1:8143ea52154df4cf52589d780ad447f625978a4c29713200842ccaa7c532350a" - name = "gopkg.in/tylerb/graceful.v1" - packages = ["."] - pruneopts = "" - revision = "4654dfbb6ad53cb5e27f37d99b02e16c1872fbbb" - version = "v1.2.15" - -[[projects]] - branch = "v1" - digest = "1:d6dfc13bd1ac289efe8d7d267ccb0d34dc6a6e55703a228cdea1848f5b2dc529" - name = "gopkg.in/yaml.v1" - packages = ["."] - pruneopts = "" - revision = "9f9df34309c04878acc86042b16630b0f696e1de" - -[[projects]] - branch = "v2" - digest = "1:2efc9662a6a1ff28c65c84fc2f9030f13d3afecdb2ecad445f3b0c80e75fc281" - name = "gopkg.in/yaml.v2" - packages = ["."] - pruneopts = "" - revision = "53403b58ad1b561927d19068c655246f2db79d48" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = [ - "github.com/Clever/leakybucket", - "github.com/Clever/leakybucket/dynamodb", - "github.com/Clever/leakybucket/memory", - "github.com/Clever/leakybucket/redis", - "github.com/aws/aws-sdk-go/aws", - "github.com/aws/aws-sdk-go/aws/session", - "github.com/pborman/uuid", - "github.com/stretchr/testify/mock", - "gopkg.in/Clever/kayvee-go.v6/logger", - "gopkg.in/Clever/kayvee-go.v6/middleware", - "gopkg.in/tylerb/graceful.v1", - "gopkg.in/yaml.v1", - ] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index 4bdfbf9..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,26 +0,0 @@ - -[[constraint]] - name = "github.com/Clever/leakybucket" - version = "1.1.0" - -[[constraint]] - name = "github.com/aws/aws-sdk-go" - version = "1.29.32" - -[[constraint]] - name = "github.com/pborman/uuid" - -[[constraint]] - name = "github.com/stretchr/testify" - -[[constraint]] - name = "gopkg.in/Clever/kayvee-go.v6" - version = "6.24.0" - -[[constraint]] - name = "gopkg.in/tylerb/graceful.v1" - version = "1.2.15" - -[[constraint]] - branch = "v1" - name = "gopkg.in/yaml.v1" diff --git a/Makefile b/Makefile index 6a94849..ce145be 100644 --- a/Makefile +++ b/Makefile @@ -13,10 +13,10 @@ BRANCH := $(shell git rev-parse --abbrev-ref HEAD) GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true) TESTS := $(shell find . -name "*_test.go" | sed s/\.go// | grep -v "./vendor") BENCHES := $(addsuffix "_bench", $(TESTS)) -.PHONY: test $(PKGS) run clean build-release install_deps -$(eval $(call golang-version-check,1.13)) +.PHONY: test $(PKGS) run clean build-release +$(eval $(call golang-version-check,1.15)) -test: $(PKGS) +test: golang-test-deps $(PKGS) $(PKGS): golang-test-all-strict-deps $(call golang-test-all-strict,$@) @@ -27,10 +27,10 @@ VERSION: echo $(VERSION) > VERSION bin/sphinxd: *.go **/*.go - go build -o bin/sphinxd -gcflags "-N -l" -ldflags "-X main.version=v$(VERSION)-$(BRANCH)-$(SHA)$(GIT_DIRTY)" $(PKG) + go build -mod=mod -o bin/sphinxd -gcflags "-N -l" -ldflags "-X main.version=v$(VERSION)-$(BRANCH)-$(SHA)$(GIT_DIRTY)" $(PKG) build-release: - go build -o bin/sphinxd -ldflags "-X main.version=v$(VERSION)-$(BRANCH)-$(SHA)$(GIT_DIRTY)" $(PKG) + go build -mod=mod -o bin/sphinxd -ldflags "-X main.version=v$(VERSION)-$(BRANCH)-$(SHA)$(GIT_DIRTY)" $(PKG) $(BENCHES): THE_PKG = $(addprefix $(PKG)/, $(dir $@)) $(BENCHES): READABLE_NAME = $(shell echo $@ | sed s/_bench//) @@ -57,6 +57,3 @@ clean: rm -f bin/sphinxd rm -f main/main rm -f deb/sphinx.deb - -install_deps: golang-dep-vendor-deps - $(call golang-dep-vendor) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a9e31d9 --- /dev/null +++ b/go.mod @@ -0,0 +1,20 @@ +module github.com/Clever/sphinx + +go 1.15 + +require ( + github.com/Clever/leakybucket v1.1.0 + github.com/aws/aws-sdk-go v1.29.34 + github.com/eapache/go-resiliency v1.2.0 // indirect + github.com/garyburd/redigo v1.6.0 // indirect + github.com/google/uuid v1.1.1 // indirect + github.com/pborman/uuid v0.0.0-20180906182336-adf5a7427709 + github.com/stretchr/objx v0.2.0 // indirect + github.com/stretchr/testify v1.5.1 + github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect + github.com/xeipuuv/gojsonschema v1.2.1-0.20200118195451-b537c054d4b4 // indirect + gopkg.in/Clever/kayvee-go.v6 v6.24.0 + gopkg.in/tylerb/graceful.v1 v1.2.15 + gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 + gopkg.in/yaml.v2 v2.2.8 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..679fab8 --- /dev/null +++ b/go.sum @@ -0,0 +1,52 @@ +github.com/Clever/leakybucket v1.1.0 h1:jeABIVb4EFhFLcOMt2KU08aMN+Ep5PQMtAM8VzqUup4= +github.com/Clever/leakybucket v1.1.0/go.mod h1:LAsmXbT1R/HsC3BDt7QkTUIIXy7YshdLZ3Wu37mvV/g= +github.com/aws/aws-sdk-go v1.29.34 h1:yrzwfDaZFe9oT4AmQeNNunSQA7c0m2chz0B43+bJ1ok= +github.com/aws/aws-sdk-go v1.29.34/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/eapache/go-resiliency v1.2.0 h1:v7g92e/KSN71Rq7vSThKaWIq68fL4YHvWyiUKorFR1Q= +github.com/eapache/go-resiliency v1.2.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= +github.com/garyburd/redigo v1.6.0 h1:0VruCpn7yAIIu7pWVClQC8wxCJEcG3nyzpMSHKi1PQc= +github.com/garyburd/redigo v1.6.0/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/pborman/uuid v0.0.0-20180906182336-adf5a7427709 h1:zNBQb37RGLmJybyMcs983HfUfpkw9OTFD9tbBfAViHE= +github.com/pborman/uuid v0.0.0-20180906182336-adf5a7427709/go.mod h1:VyrYX9gd7irzKovcSS6BIIEwPRkP2Wm2m9ufcdFSJ34= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +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/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= +github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo= +github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= +github.com/xeipuuv/gojsonschema v1.2.1-0.20200118195451-b537c054d4b4 h1:lJ+JoAZNiroatsJSU68wKggYQQBk6XZAb4a6v4uTrBo= +github.com/xeipuuv/gojsonschema v1.2.1-0.20200118195451-b537c054d4b4/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +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= +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/tylerb/graceful.v1 v1.2.15 h1:1JmOyhKqAyX3BgTXMI84LwT6FOJ4tP2N9e2kwTCM0nQ= +gopkg.in/tylerb/graceful.v1 v1.2.15/go.mod h1:yBhekWvR20ACXVObSSdD3u6S9DeSylanL2PAbAC/uJ8= +gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 h1:POO/ycCATvegFmVuPpQzZFJ+pGZeX22Ufu6fibxDVjU= +gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/golang.mk b/golang.mk index 63f8ab4..40c70a4 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.1 +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=mod" + # 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.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. 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