-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathMakefile
56 lines (45 loc) · 1.8 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
EXE := tfswitch
PKG := github.com/warrensbox/terraform-switcher
BUILDPATH := build
PATH := $(BUILDPATH):$(PATH)
VER ?= $(shell git ls-remote --tags --sort=version:refname [email protected]:warrensbox/terraform-switcher.git | awk '{if ($$2 ~ "\\^\\{\\}$$") next; print vers[split($$2,vers,"\\/")]}' | tail -1)
# Managing Go installations: Installing multiple Go versions
# https://go.dev/doc/manage-install
GOBINARY ?= $(shell (egrep -m1 '^go[[:space:]]+[[:digit:]]+\.' go.mod | tr -d '[:space:]' | xargs which) || echo go)
GOOS ?= $(shell $(GOBINARY) env GOOS)
GOARCH ?= $(shell $(GOBINARY) env GOARCH)
$(EXE): version go.mod *.go lib/*.go
mkdir -p "$(BUILDPATH)/"
$(GOBINARY) build -v -ldflags "-X 'main.version=$(VER)'" -o "$(BUILDPATH)/$@" $(PKG)
.PHONY: release
release: $(EXE) darwin linux windows
.PHONY: darwin linux windows
darwin linux windows: version
GOOS=$@ $(GOBINARY) build -ldflags "-X 'main.version=$(VER)'" -o "$(BUILDPATH)/$(EXE)-$(word 1, $(VER))-$@-$(GOARCH)" $(PKG)
.PHONY: clean
clean:
rm -vrf "$(BUILDPATH)/"
.PHONY: test
test: vet $(EXE)
$(GOBINARY) test -v ./...
.PHONY: test-single-function
test-single-function: vet
@([ -z "$(TEST_FUNC_NAME)" ] && echo "TEST_FUNC_NAME is not set" && false) || true
$(GOBINARY) test -v -run="$(TEST_FUNC_NAME)" ./...
.PHONY: vet
vet: version
$(GOBINARY) vet ./...
.PHONY: version
version:
@echo "Running $(GOBINARY) ($(shell $(GOBINARY) version))"
.PHONY: install
install: $(EXE)
mkdir -p ~/bin
mv "$(BUILDPATH)/$(EXE)" ~/bin/
.PHONY: docs
docs:
@#cd docs; bundle install --path vendor/bundler; bundle exec jekyll build -c _config.yml; cd ..
cd www && mkdocs gh-deploy --force
.PHONY: goreleaser-release-snapshot
goreleaser-release-snapshot:
RELEASE_VERSION=$(VER) goreleaser release --config ./.goreleaser.yml --snapshot --clean