Skip to content

Commit ca2de71

Browse files
committed
Add initial implementation
1 parent c79839b commit ca2de71

File tree

20 files changed

+338
-0
lines changed

20 files changed

+338
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.idea

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Go development helpers
2+
3+
## Usage
4+
5+
Add a test file (e.g. `make_test.go`) to your module with unused import.
6+
```go
7+
package mymodule_test
8+
9+
import _ "github.com/bool64/dev" // Include development helpers to project.
10+
```
11+
12+
Add `Makefile` to your module with includes standard targets.
13+
```Makefile
14+
GOLANGCI_LINT_VERSION := "v1.31.0" # Optional.
15+
16+
# The head of Makefile determines location of dev-go to include standard targets.
17+
GO ?= go
18+
export GO111MODULE = on
19+
20+
ifneq "$(GOFLAGS)" ""
21+
$(info GOFLAGS: ${GOFLAGS})
22+
endif
23+
24+
ifneq "$(wildcard ./vendor )" ""
25+
$(info >> using vendor)
26+
modVendor = -mod=vendor
27+
ifeq (,$(findstring -mod,$(GOFLAGS)))
28+
export GOFLAGS := ${GOFLAGS} ${modVendor}
29+
endif
30+
ifneq "$(wildcard ./vendor/github.com/bool64/dev)" ""
31+
DEVGO_PATH := ./vendor/github.com/bool64/dev
32+
endif
33+
endif
34+
35+
ifeq ($(DEVGO_PATH),)
36+
DEVGO_PATH := $(shell GO111MODULE=on $(GO) list ${modVendor} -f '{{.Dir}}' -m github.com/bool64/dev)
37+
ifeq ($(DEVGO_PATH),)
38+
$(info Module github.com/bool64/dev not found, downloading.)
39+
DEVGO_PATH := $(shell export GO111MODULE=on && $(GO) mod tidy && $(GO) list -f '{{.Dir}}' -m github.com/bool64/dev)
40+
endif
41+
endif
42+
43+
-include $(DEVGO_PATH)/makefiles/main.mk
44+
-include $(DEVGO_PATH)/makefiles/lint.mk
45+
-include $(DEVGO_PATH)/makefiles/test-unit.mk
46+
-include $(DEVGO_PATH)/makefiles/github-actions.mk
47+
48+
# Add your custom targets here.
49+
50+
```

doc.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Package dev contains reusable development helpers.
2+
package dev
3+
4+
// These imports workaround `go mod vendor` prune.
5+
//
6+
// See https://github.com/golang/go/issues/26366.
7+
import (
8+
_ "github.com/bool64/dev/makefiles"
9+
_ "github.com/bool64/dev/scripts"
10+
_ "github.com/bool64/dev/templates/.github/workflows"
11+
)

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/bool64/dev
2+
3+
go 1.11

go.sum

Whitespace-only changes.

makefiles/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package makefiles contains Makefile includes.
2+
package makefiles

makefiles/github-actions.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
GO ?= go
2+
3+
## Replace GitHub Actions from template
4+
github-actions:
5+
@rm -rf $(PWD)/.github && cp -r $(DEVGO_PATH)/templates/.github $(PWD)/ && rm -f $(PWD)/.github/workflows/doc.go && git add $(PWD)/.github
6+
7+
.PHONY: github-actions

makefiles/help.mk

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.PHONY: help
2+
3+
.DEFAULT_GOAL := help
4+
HELP_WIDTH=" "
5+
help:
6+
@printf "Usage\n";
7+
@awk '{ \
8+
if ($$0 ~ /^.PHONY: [a-zA-Z\-\_0-9]+$$/) { \
9+
helpCommand = substr($$0, index($$0, ":") + 2); \
10+
if (helpMessage) { \
11+
printf " \033[32m%-20s\033[0m %s\n", \
12+
helpCommand, helpMessage; \
13+
helpMessage = ""; \
14+
} \
15+
} else if ($$0 ~ /^[a-zA-Z\-\_0-9.]+:/) { \
16+
helpCommand = substr($$0, 0, index($$0, ":")); \
17+
if (helpMessage) { \
18+
printf " \033[32m%-20s\033[0m %s\n", \
19+
helpCommand, helpMessage; \
20+
helpMessage = ""; \
21+
} \
22+
} else if ($$0 ~ /^##/) { \
23+
if (helpMessage) { \
24+
helpMessage = helpMessage"\n"$(HELP_WIDTH)substr($$0, 3); \
25+
} else { \
26+
helpMessage = substr($$0, 3); \
27+
} \
28+
} else { \
29+
if (helpMessage) { \
30+
print "\n"$(HELP_WIDTH)helpMessage"\n" \
31+
} \
32+
helpMessage = ""; \
33+
} \
34+
}' \
35+
$(MAKEFILE_LIST)

makefiles/lint.mk

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
GO ?= go
2+
3+
## Check with golangci-lint
4+
lint:
5+
@DEVGO_PATH=$(DEVGO_PATH) GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) bash $(DEVGO_SCRIPTS)/lint.sh
6+
7+
## Apply goimports and gofmt
8+
fix-lint:
9+
@DEVGO_PATH=$(DEVGO_PATH) bash $(DEVGO_SCRIPTS)/fix.sh
10+
11+
.PHONY: lint fix-lint

makefiles/main.mk

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
GO ?= go
2+
3+
PWD = $(shell pwd)
4+
5+
# Detecting GOPATH and removing trailing "/" if any
6+
GOPATH = $(realpath $(shell $(GO) env GOPATH))
7+
8+
ifneq "$(wildcard ./vendor )" ""
9+
modVendor = -mod=vendor
10+
endif
11+
export MODULE_NAME := $(shell test -f go.mod && GO111MODULE=on $(GO) list $(modVendor) -m)
12+
13+
DEVGO_PATH ?= $(PWD)/vendor/github.com/bool64/dev
14+
DEVGO_SCRIPTS ?= $(DEVGO_PATH)/scripts
15+
16+
-include $(DEVGO_PATH)/makefiles/help.mk

0 commit comments

Comments
 (0)