-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
98 lines (87 loc) · 2.85 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
# Determine which sed to use
ifeq ($(shell uname),Darwin)
SED=gsed
else
SED=sed -i
endif
PLUGIN_VERSION:=$(shell grep 'PluginVersion' ./version.go | awk '{ print $$3 }' | tr -d '"')
.PHONY: version
version:
@echo $(PLUGIN_VERSION)
.PHONY: lint
lint: install-tools
golangci-lint run
.PHONY: fmt
fmt: install-tools
go fmt ./...
gofumpt -w ./
.PHONY: install-tools
install-tools:
@echo "Installing tools..."
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@go install mvdan.cc/gofumpt@latest
.PHONY: test
test:
go test -v ./...
.PHONY: build
build:
@echo "Building coredns-dnsimple..."
@if [ ! -d "coredns" ]; then \
git clone https://github.com/coredns/coredns.git; \
fi
@export PLUGIN_DIR=$(shell pwd); \
cd coredns; \
if ! grep -q "replace github.com/dnsimple/coredns-dnsimple" go.mod; then \
$(SED) -i "/^go 1/a replace github.com/dnsimple/coredns-dnsimple => $$PLUGIN_DIR" go.mod; \
$(SED) -i '/route53:route53/i dnsimple:github.com\/dnsimple\/coredns-dnsimple' plugin.cfg; \
fi; \
GOFLAGS=-mod=mod go generate; \
go mod tidy; \
gitcommit=$(shell git describe --dirty --always); \
go build -o coredns -ldflags="-s -w -X github.com/coredns/coredns/coremain.GitCommit=$$gitcommit" .
@cp coredns/coredns coredns-dnsimple
.PHONY: clean
clean:
rm -rf coredns
rm -f coredns-dnsimple
.PHONY: start
start: build
./coredns-dnsimple -conf Corefile
.PHONY: release
release: lint fmt test
@echo "Checking if current branch is main"
if [ "$(shell git branch --show-current)" != "main" ]; then \
echo "Not on main branch"; \
echo "Please switch to main and try again"; \
exit 1; \
fi
@echo "Checking if there are any uncommitted changes"
if [ -n "$(shell git status --porcelain)" ]; then \
echo "There are uncommitted changes"; \
echo "Please commit or stash your changes and try again"; \
exit 1; \
fi
@echo "Checking if version $(PLUGIN_VERSION) matches the provided $(VERSION)"
if [ "$(PLUGIN_VERSION)" != "$(VERSION)" ]; then \
echo "Version mismatch"; \
echo "Please update the version in version.go to $(VERSION) or supply the correct version e.g. make release VERSION=1.2.3"; \
exit 1; \
fi
@echo "Checking if version $(PLUGIN_VERSION) already exists"
if git rev-parse v$(PLUGIN_VERSION) >/dev/null 2>&1; then \
echo "Version $(PLUGIN_VERSION) already exists"; \
echo "Please update the version in version.go and try again"; \
exit 1; \
fi
@echo "Checking if CHANGELOG.md has been updated"
if ! grep -q "## $(PLUGIN_VERSION)" CHANGELOG.md; then \
echo "CHANGELOG.md has not been updated"; \
echo "Please update CHANGELOG.md and try again"; \
exit 1; \
fi
@echo "Releasing version $(PLUGIN_VERSION)"
@echo "Tagging release"
git tag -a v$(PLUGIN_VERSION) -s -m "Release v$(PLUGIN_VERSION)"
@echo "Releasing to GitHub"
git push origin v$(PLUGIN_VERSION)
@echo "Releasing of v$(PLUGIN_VERSION) complete 🎉"