chore: repo maintenance 🤖

more details: https://github.com/moul/repoman

Signed-off-by: moul-bot <bot@moul.io>
This commit is contained in:
moul-bot 2020-07-12 14:13:01 +02:00
parent 57c04e0d2a
commit 1078f8de8f
No known key found for this signature in database
GPG Key ID: 615D26EDFC55B351
3 changed files with 79 additions and 26 deletions

View File

@ -2,5 +2,6 @@
"extends": [ "extends": [
"config:base" "config:base"
], ],
"groupName": "all" "groupName": "all",
"gomodTidy": true
} }

View File

@ -9,6 +9,7 @@ Guilhem Fanton <guilhem.fanton@gmail.com>
Jan Weitz <jan@iosphere.de> Jan Weitz <jan@iosphere.de>
jhayotte <julien.hayotte@gmail.com> jhayotte <julien.hayotte@gmail.com>
Julien Hayotte <julien.hayotte@gmail.com> Julien Hayotte <julien.hayotte@gmail.com>
Manfred Touron <94029+moul@users.noreply.github.com>
Manfred Touron <m@42.am> Manfred Touron <m@42.am>
Mathieu Acthernoene <zoontek@gmail.com> Mathieu Acthernoene <zoontek@gmail.com>
Mike Lee <mike.lee@safeguardproperties.com> Mike Lee <mike.lee@safeguardproperties.com>

99
rules.mk vendored
View File

@ -30,6 +30,7 @@ all: help
## ##
rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
check-program = $(foreach exec,$(1),$(if $(shell PATH="$(PATH)" which $(exec)),,$(error "No $(exec) in PATH")))
## ##
## rules.mk ## rules.mk
@ -68,69 +69,99 @@ endif
ifdef GOPKG ifdef GOPKG
GO ?= go GO ?= go
GOPATH ?= $(HOME)/go GOPATH ?= $(HOME)/go
GOLIBS ?= $(shell find . -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq)
GO_INSTALL_OPTS ?= GO_INSTALL_OPTS ?=
GO_TEST_OPTS ?= -test.timeout=30s GO_TEST_OPTS ?= -test.timeout=30s
GOMOD_DIR ?= .
GOCOVERAGE_FILE ?= ./coverage.txt
GOTESTJSON_FILE ?= ./go-test.json
GOBUILDLOG_FILE ?= ./go-build.log
GOINSTALLLOG_FILE ?= ./go-install.log
ifdef GOBINS ifdef GOBINS
.PHONY: go.install .PHONY: go.install
go.install: go.install:
ifeq ($(CI),true)
@rm -f /tmp/goinstall.log
@set -e; for dir in $(GOBINS); do ( set -xe; \
cd $$dir; \
$(GO) install -v $(GO_INSTALL_OPTS) .; \
); done 2>&1 | tee $(GOINSTALLLOG_FILE)
else
@set -e; for dir in $(GOBINS); do ( set -xe; \ @set -e; for dir in $(GOBINS); do ( set -xe; \
cd $$dir; \ cd $$dir; \
$(GO) install $(GO_INSTALL_OPTS) .; \ $(GO) install $(GO_INSTALL_OPTS) .; \
); done ); done
endif
INSTALL_STEPS += go.install INSTALL_STEPS += go.install
.PHONY: go.release .PHONY: go.release
go.release: go.release:
$(call check-program, goreleaser)
goreleaser --snapshot --skip-publish --rm-dist goreleaser --snapshot --skip-publish --rm-dist
@echo -n "Do you want to release? [y/N] " && read ans && \ @echo -n "Do you want to release? [y/N] " && read ans && \
if [ $${ans:-N} = y ]; then set -xe; goreleaser --rm-dist; fi if [ $${ans:-N} = y ]; then set -xe; goreleaser --rm-dist; fi
RELEASE_STEPS += go.release RELEASE_STEPS += go.release
endif endif
.PHONY: go.unittest coverage.txt .PHONY: go.unittest
go.unittest: coverage.txt go.unittest:
coverage.txt: ifeq ($(CI),true)
@rm -f /tmp/coverage.txt @echo "mode: atomic" > /tmp/gocoverage
@touch /tmp/coverage.txt @rm -f $(GOTESTJSON_FILE)
@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 -e; (set -euf pipefail; \
cd $$dir; \ cd $$dir; \
$(GO) test $(GO_TEST_OPTS) -cover -coverprofile=/tmp/profile.out -covermode=atomic -race ./...; \ ($(GO) test ./... $(GO_TEST_OPTS) -cover -coverprofile=/tmp/profile.out -covermode=atomic -race -json | tee -a $(GOTESTJSON_FILE) 3>&1 1>&2 2>&3 | tee -a $(GOBUILDLOG_FILE); \
); \
if [ -f /tmp/profile.out ]; then \ if [ -f /tmp/profile.out ]; then \
cat /tmp/profile.out >> /tmp/coverage.txt; \ cat /tmp/profile.out | sed "/mode: atomic/d" >> /tmp/gocoverage; \
rm -f /tmp/profile.out; \
fi)); done
@mv /tmp/gocoverage $(GOCOVERAGE_FILE)
else
@echo "mode: atomic" > /tmp/gocoverage
@set -e; for dir in `find $(GOMOD_DIR) -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do (set -e; (set -xe; \
cd $$dir; \
$(GO) test ./... $(GO_TEST_OPTS) -cover -coverprofile=/tmp/profile.out -covermode=atomic -race); \
if [ -f /tmp/profile.out ]; then \
cat /tmp/profile.out | sed "/mode: atomic/d" >> /tmp/gocoverage; \
rm -f /tmp/profile.out; \ rm -f /tmp/profile.out; \
fi); done fi); done
mv /tmp/coverage.txt . @mv /tmp/gocoverage $(GOCOVERAGE_FILE)
endif
.PHONY: go.checkdoc
go.checkdoc:
go doc $(GOMOD_DIR)
.PHONY: go.coverfunc .PHONY: go.coverfunc
go.coverfunc: coverage.txt go.coverfunc: go.unittest
go tool cover -func=./coverage.txt | grep -v .pb.go: | grep -v .pb.gw.go: go tool cover -func=$(GOCOVERAGE_FILE) | grep -v .pb.go: | grep -v .pb.gw.go:
.PHONY: go.lint .PHONY: go.lint
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; \ cd $$dir; \
golangci-lint run --verbose ./...; \ golangci-lint run --verbose ./...; \
); done ); done
.PHONY: go.tidy .PHONY: go.tidy
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; \ cd $$dir; \
$(GO) mod tidy; \ $(GO) mod tidy; \
); done ); done
.PHONY: go.build .PHONY: go.build
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; \ cd $$dir; \
$(GO) build ./...; \ $(GO) build ./...; \
); done ); done
.PHONY: go.bump-deps .PHONY: go.bump-deps
go.bumpdeps: 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; \ cd $$dir; \
$(GO) get -u ./...; \ $(GO) get -u ./...; \
); done ); done
@ -138,9 +169,9 @@ go.bumpdeps:
.PHONY: go.bump-deps .PHONY: go.bump-deps
go.fmt: go.fmt:
if ! command -v goimports &>/dev/null; then GO111MODULE=off go get golang.org/x/tools/cmd/goimports; fi 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; \ cd $$dir; \
goimports -w . \ goimports -w `go list -f '{{.Dir}}' ./...)` \
); done ); done
BUILD_STEPS += go.build BUILD_STEPS += go.build
@ -151,6 +182,20 @@ UNITTEST_STEPS += go.unittest
FMT_STEPS += go.fmt FMT_STEPS += go.fmt
endif endif
##
## Gitattributes
##
ifneq ($(wildcard .gitattributes),)
.PHONY: _linguist-ignored
_linguist-kept:
@git check-attr linguist-vendored $(shell git check-attr linguist-generated $(shell find . -type f | grep -v .git/) | grep unspecified | cut -d: -f1) | grep unspecified | cut -d: -f1 | sort
.PHONY: _linguist-kept
_linguist-ignored:
@git check-attr linguist-vendored linguist-ignored `find . -not -path './.git/*' -type f` | grep '\ set$$' | cut -d: -f1 | sort -u
endif
## ##
## Node ## Node
## ##
@ -177,6 +222,15 @@ endif
## Docker ## Docker
## ##
docker_build = 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 "$2" -f "$1" "$(dir $1)"
ifndef DOCKERFILE_PATH
DOCKERFILE_PATH = ./Dockerfile
endif
ifndef DOCKER_IMAGE ifndef DOCKER_IMAGE
ifneq ($(wildcard Dockerfile),) ifneq ($(wildcard Dockerfile),)
DOCKER_IMAGE = $(notdir $(PWD)) DOCKER_IMAGE = $(notdir $(PWD))
@ -186,11 +240,8 @@ ifdef DOCKER_IMAGE
ifneq ($(DOCKER_IMAGE),none) ifneq ($(DOCKER_IMAGE),none)
.PHONY: docker.build .PHONY: docker.build
docker.build: docker.build:
docker build \ $(call check-program, docker)
--build-arg VCS_REF=`git rev-parse --short HEAD` \ $(call docker_build,$(DOCKERFILE_PATH),$(DOCKER_IMAGE))
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VERSION=`git describe --tags --always` \
-t $(DOCKER_IMAGE) .
BUILD_STEPS += docker.build BUILD_STEPS += docker.build
endif endif
@ -255,7 +306,7 @@ generate: $(PRE_GENERATE_STEPS) $(GENERATE_STEPS)
endif endif
.PHONY: help .PHONY: help
help: help::
@echo "General commands:" @echo "General commands:"
@[ "$(BUILD_STEPS)" != "" ] && echo " build" || true @[ "$(BUILD_STEPS)" != "" ] && echo " build" || true
@[ "$(BUMPDEPS_STEPS)" != "" ] && echo " bumpdeps" || true @[ "$(BUMPDEPS_STEPS)" != "" ] && echo " bumpdeps" || true