From 014a8d414385cd29d887042a58b3cac25948dde3 Mon Sep 17 00:00:00 2001 From: moul-bot Date: Wed, 8 Jul 2020 23:20:56 +0200 Subject: [PATCH] =?UTF-8?q?chore:=20repo=20maintenance=20=F0=9F=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit more details: https://github.com/moul/repoman Signed-off-by: moul-bot --- .github/renovate.json | 3 +- AUTHORS | 1 + rules.mk | 101 +++++++++++++++++++++++++++++++----------- 3 files changed, 79 insertions(+), 26 deletions(-) diff --git a/.github/renovate.json b/.github/renovate.json index 031be2c..31ab500 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -2,5 +2,6 @@ "extends": [ "config:base" ], - "groupName": "all" + "groupName": "all", + "gomodTidy": true } diff --git a/AUTHORS b/AUTHORS index f692c65..f5dd11f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -9,6 +9,7 @@ Guilhem Fanton Jan Weitz jhayotte Julien Hayotte +Manfred Touron <94029+moul@users.noreply.github.com> Manfred Touron Mathieu Acthernoene Mike Lee diff --git a/rules.mk b/rules.mk index 020d7aa..1d90565 100644 --- a/rules.mk +++ b/rules.mk @@ -30,6 +30,7 @@ all: help ## 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 @@ -68,69 +69,99 @@ 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 ?= . +GOCOVERAGE_FILE ?= ./coverage.txt +GOTESTJSON_FILE ?= ./go-test.json +GOBUILDLOG_FILE ?= ./go-build.log +GOINSTALLLOG_FILE ?= ./go-install.log ifdef GOBINS .PHONY: 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; \ cd $$dir; \ $(GO) install $(GO_INSTALL_OPTS) .; \ ); done +endif INSTALL_STEPS += go.install .PHONY: go.release go.release: + $(call check-program, goreleaser) goreleaser --snapshot --skip-publish --rm-dist @echo -n "Do you want to release? [y/N] " && read ans && \ if [ $${ans:-N} = y ]; then set -xe; goreleaser --rm-dist; fi 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; \ - cd $$dir; \ - $(GO) test $(GO_TEST_OPTS) -cover -coverprofile=/tmp/profile.out -covermode=atomic -race ./...; \ +.PHONY: go.unittest +go.unittest: +ifeq ($(CI),true) + @echo "mode: atomic" > /tmp/gocoverage + @rm -f $(GOTESTJSON_FILE) + @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; \ + ($(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 \ - 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; \ fi); done - mv /tmp/coverage.txt . + @mv /tmp/gocoverage $(GOCOVERAGE_FILE) +endif + +.PHONY: go.checkdoc +go.checkdoc: + go doc $(GOMOD_DIR) .PHONY: go.coverfunc -go.coverfunc: coverage.txt - go tool cover -func=./coverage.txt | grep -v .pb.go: | grep -v .pb.gw.go: +go.coverfunc: go.unittest + go tool cover -func=$(GOCOVERAGE_FILE) | 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 @@ -138,9 +169,9 @@ go.bumpdeps: .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 @@ -151,6 +182,20 @@ UNITTEST_STEPS += go.unittest FMT_STEPS += go.fmt 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 ## @@ -177,6 +222,15 @@ endif ## 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 ifneq ($(wildcard Dockerfile),) DOCKER_IMAGE = $(notdir $(PWD)) @@ -186,11 +240,8 @@ ifdef DOCKER_IMAGE ifneq ($(DOCKER_IMAGE),none) .PHONY: docker.build 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 $(DOCKER_IMAGE) . + $(call check-program, docker) + $(call docker_build,$(DOCKERFILE_PATH),$(DOCKER_IMAGE)) BUILD_STEPS += docker.build endif @@ -255,7 +306,7 @@ generate: $(PRE_GENERATE_STEPS) $(GENERATE_STEPS) endif .PHONY: help -help: +help:: @echo "General commands:" @[ "$(BUILD_STEPS)" != "" ] && echo " build" || true @[ "$(BUMPDEPS_STEPS)" != "" ] && echo " bumpdeps" || true