forked from terraform-docs/terraform-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
145 lines (114 loc) · 4.44 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Copyright 2021 The terraform-docs Authors.
#
# Licensed under the MIT license (the "License"); you may not
# use this file except in compliance with the License.
#
# You may obtain a copy of the License at the LICENSE file in
# the root directory of this source tree.
# Project variables
PROJECT_NAME := terraform-docs
PROJECT_OWNER := terraform-docs
DESCRIPTION := generate documentation from Terraform modules in various output formats
PROJECT_URL := https://github.com/$(PROJECT_OWNER)/$(PROJECT_NAME)
LICENSE := MIT
# Build variables
BUILD_DIR := bin
COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null)
CUR_VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo "v0.0.0-$(COMMIT_HASH)")
COVERAGE_OUT := coverage.out
# Go variables
GO ?= go
GO_PACKAGE := github.com/$(PROJECT_OWNER)/$(PROJECT_NAME)
GOOS ?= $(shell $(GO) env GOOS)
GOARCH ?= $(shell $(GO) env GOARCH)
GOLDFLAGS += -X $(GO_PACKAGE)/internal/version.commit=$(COMMIT_HASH)
GOBUILD ?= CGO_ENABLED=0 $(GO) build -ldflags="$(GOLDFLAGS)"
GORUN ?= GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) run
GOIMPORTS_LOCAL_ARG := -local github.com/terraform-docs
# Docker variables
DEFAULT_TAG ?= $(shell echo "$(CUR_VERSION)" | tr -d 'v')
DOCKER_IMAGE := quay.io/$(PROJECT_OWNER)/$(PROJECT_NAME)
DOCKER_TAG ?= $(DEFAULT_TAG)
# Binary versions
GOLANGCI_VERSION := v1.55.2
.PHONY: all
all: clean verify checkfmt lint test build
###############
##@ Development
.PHONY: checkfmt
checkfmt: ## Check formatting of all go files
@ $(MAKE) --no-print-directory log-$@
@ goimports -l $(GOIMPORTS_LOCAL_ARG) main.go cmd/ internal/ scripts/docs/ && echo "OK"
.PHONY: clean
clean: ## Clean workspace
@ $(MAKE) --no-print-directory log-$@
rm -rf ./$(BUILD_DIR) ./$(COVERAGE_OUT)
.PHONY: fmt
fmt: ## Format all go files
@ $(MAKE) --no-print-directory log-$@
goimports -w $(GOIMPORTS_LOCAL_ARG) main.go cmd/ internal/ scripts/docs/
.PHONY: lint
lint: ## Run linter
@ $(MAKE) --no-print-directory log-$@
golangci-lint run ./...
.PHONY: staticcheck
staticcheck: ## Run staticcheck
@ $(MAKE) --no-print-directory log-$@
$(GO) run honnef.co/go/tools/cmd/staticcheck@2024.1.1 -- ./...
.PHONY: test
test: ## Run tests
@ $(MAKE) --no-print-directory log-$@
$(GO) test -coverprofile=$(COVERAGE_OUT) -covermode=atomic -v ./...
.PHONY: verify
verify: ## Verify 'vendor' dependencies
@ $(MAKE) --no-print-directory log-$@
$(GO) mod verify
# removed and gitignoreed 'vendor/', not needed anymore #
.PHONY: vendor deps
vendor:
deps:
#########
##@ Build
.PHONY: build
build: clean ## Build binary for current OS/ARCH
@ $(MAKE) --no-print-directory log-$@
$(GOBUILD) -o ./$(BUILD_DIR)/$(GOOS)-$(GOARCH)/$(PROJECT_NAME)
.PHONY: docker
docker: ## Build Docker image
@ $(MAKE) --no-print-directory log-$@
docker build --pull --tag $(DOCKER_IMAGE):$(DOCKER_TAG) --file Dockerfile .
.PHONY: push
push: ## Push Docker image
@ $(MAKE) --no-print-directory log-$@
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)
.PHONY: docs
docs: ## Generate document of formatter commands
@ $(MAKE) --no-print-directory log-$@
$(GORUN) ./scripts/docs/generate.go
###########
##@ Helpers
.PHONY: goimports
goimports: ## Install goimports
ifeq (, $(shell which goimports))
$(GO) install golang.org/x/tools/cmd/goimports@latest
endif
.PHONY: golangci
golangci: ## Install golangci
ifeq (, $(shell which golangci-lint))
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell $(GO) env GOPATH)/bin $(GOLANGCI_VERSION)
endif
.PHONY: tools
tools: ## Install required tools
@ $(MAKE) --no-print-directory log-$@
@ $(MAKE) --no-print-directory goimports golangci
########################################################################
## Self-Documenting Makefile Help ##
## https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html ##
########################################################################
########
##@ Help
.PHONY: help
help: ## Display this help
@awk -v "col=\033[36m" -v "nocol=\033[0m" ' BEGIN { FS = ":.*##" ; printf "Usage:\n make %s<target>%s\n", col, nocol } /^[a-zA-Z_-]+:.*?##/ { printf " %s%-12s%s %s\n", col, $$1, nocol, $$2 } /^##@/ { printf "\n%s%s%s\n", nocol, substr($$0, 5), nocol } ' $(MAKEFILE_LIST)
log-%:
@grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN { FS = ":.*?## " }; { printf "\033[36m==> %s\033[0m\n", $$2 }'