forked from tj-actions/auto-doc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
71 lines (58 loc) · 1.99 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
# Self-Documented Makefile see https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
OUTPUT := README.md
FILENAME := action.yml
.DEFAULT_GOAL := help
.PHONY: help
# Put it first so that "make" without argument is like "make help".
help:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-20s-\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.PHONY: clean
clean: ## Clean binary file
@echo "Cleaning binary..."
@rm -rf bin
guard-%: ## Checks that env var is set else exits with non 0 mainly used in CI;
@if [ -z '${${*}}' ]; then echo 'Environment variable $* not set' && exit 1; fi
.PHONY: build
build: clean ## Compile go modules
@echo "Compiling *.go..."
@go build -o ./bin/auto_doc *.go
.PHONY: run
run: build guard-OUTPUT guard-FILENAME ## Execute binary
@echo "Running auto doc..."
@./bin/auto_doc --filename=$(FILENAME) --output=$(OUTPUT)
@$(MAKE) clean
.PHONY: run-help
run-help: build guard-OUTPUT guard-FILENAME ## Execute binary
@echo "Running auto doc help..."
@echo ""
@./bin/auto_doc --help
@$(MAKE) clean
upgrade-to-v2: ## Upgrade to v2
@find . -type f \
-name '*.go' \
-exec grep -q 'github.com/tj-actions/auto-doc/v2' {} \; \
&& echo "Already upgraded to v2" \
&& exit 1 \
|| echo "Upgrading to v2"
@find . -type f \
-name '*.go' \
-exec sed -i '' -e 's,github.com/tj-actions/auto-doc,github.com/tj-actions/auto-doc/v2,g' {} \;
upgrade-from-v2-to-a-major-version: guard-MAJOR_VERSION ## Upgrade from v2 to a major version
@find . -type f \
-name '*.go' \
-exec grep -q 'github.com/tj-actions/auto-doc/v$(MAJOR_VERSION)' {} \; \
&& echo "Already upgraded to v$(MAJOR_VERSION)" \
&& exit 1 \
|| echo "Upgrading to v$(MAJOR_VERSION)"
@find . -type f \
-name '*.go' \
-exec sed -i '' -e 's,github.com/tj-actions/auto-doc/v2,github.com/tj-actions/auto-doc/v$(MAJOR_VERSION),g' {} \;
.PHONY: test
test: clean
@go test ./cmd
.PHONY: format
format: ## Format go modules
@go fmt ./...
.PHONY: tidy
tidy: ## Tidy go.mod
@go mod tidy