Skip to content

Commit

Permalink
feat: bump go1.14, rules.mk, build
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Feb 27, 2020
1 parent e806397 commit 471476f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2.1

orbs:
moul: moul/build@1.15.0 # https://github.com/moul/build
moul: moul/build@1.16.0 # https://github.com/moul/build

workflows:
main:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG VCS_REF
ARG VERSION

# build
FROM golang:1.13-alpine as builder
FROM golang:1.14-alpine as builder
RUN apk add --no-cache git gcc musl-dev make
ENV GO111MODULE=on
WORKDIR /go/src/moul.io/golang-repo-template
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ DOCKER_IMAGE ?= moul/golang-repo-template
GOBINS ?= .
NPM_PACKAGES ?= .

all: test install

-include rules.mk
include rules.mk
33 changes: 15 additions & 18 deletions rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ endif
ifdef GOPKG
GO ?= go
GOPATH ?= $(HOME)/go
GOLIBS ?= $(shell find . -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq)
GO_INSTALL_OPTS ?=
GO_TEST_OPTS ?= -test.timeout=30s
GOMOD_DIR ?= .

ifdef GOBINS
.PHONY: go.install
Expand All @@ -89,12 +89,10 @@ go.release:
RELEASE_STEPS += go.release
endif

.PHONY: go.unittest coverage.txt
go.unittest: coverage.txt
coverage.txt:
@rm -f /tmp/coverage.txt
@touch /tmp/coverage.txt
@set -e; for dir in $(GOLIBS); do ( set -xe; \
.PHONY: go.unittest
go.unittest:
echo "" > /tmp/coverage.txt
@set -e; for dir in `find $(GOMOD_DIR) -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do ( set -xe; \
cd $$dir; \
$(GO) test $(GO_TEST_OPTS) -cover -coverprofile=/tmp/profile.out -covermode=atomic -race ./...; \
if [ -f /tmp/profile.out ]; then \
Expand All @@ -103,44 +101,40 @@ coverage.txt:
fi); done
mv /tmp/coverage.txt .

.PHONY: go.coverfunc
go.coverfunc: coverage.txt
go tool cover -func=./coverage.txt | grep -v .pb.go: | grep -v .pb.gw.go:

.PHONY: go.lint
go.lint:
@set -e; for dir in $(GOLIBS); do ( set -xe; \
@set -e; for dir in `find $(GOMOD_DIR) -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do ( set -xe; \
cd $$dir; \
golangci-lint run --verbose ./...; \
); done

.PHONY: go.tidy
go.tidy:
@set -e; for dir in $(GOLIBS); do ( set -xe; \
@set -e; for dir in `find $(GOMOD_DIR) -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do ( set -xe; \
cd $$dir; \
$(GO) mod tidy; \
); done

.PHONY: go.build
go.build:
@set -e; for dir in $(GOLIBS); do ( set -xe; \
@set -e; for dir in `find $(GOMOD_DIR) -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do ( set -xe; \
cd $$dir; \
$(GO) build ./...; \
); done

.PHONY: go.bump-deps
go.bumpdeps:
@set -e; for dir in $(GOLIBS); do ( set -xe; \
@set -e; for dir in `find $(GOMOD_DIR) -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do ( set -xe; \
cd $$dir; \
$(GO) get -u ./...; \
); done

.PHONY: go.bump-deps
go.fmt:
if ! command -v goimports &>/dev/null; then GO111MODULE=off go get golang.org/x/tools/cmd/goimports; fi
@set -e; for dir in $(GOLIBS); do ( set -xe; \
@set -e; for dir in `find $(GOMOD_DIR) -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do ( set -xe; \
cd $$dir; \
goimports -w . \
goimports -w `go list -f '{{.Dir}}' ./...)` \
); done

BUILD_STEPS += go.build
Expand Down Expand Up @@ -177,6 +171,9 @@ endif
## Docker
##

ifndef DOCKERFILE_PATH
DOCKERFILE_PATH = ./Dockerfile
endif
ifndef DOCKER_IMAGE
ifneq ($(wildcard Dockerfile),)
DOCKER_IMAGE = $(notdir $(PWD))
Expand All @@ -190,7 +187,7 @@ docker.build:
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VERSION=`git describe --tags --always` \
-t $(DOCKER_IMAGE) .
-t $(DOCKER_IMAGE) -f $(DOCKERFILE_PATH) $(dir $(DOCKERFILE_PATH))

BUILD_STEPS += docker.build
endif
Expand Down

0 comments on commit 471476f

Please sign in to comment.