-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
154 lines (131 loc) · 4.7 KB
/
Copy pathMakefile
File metadata and controls
154 lines (131 loc) · 4.7 KB
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
146
147
148
149
150
151
152
153
154
SHELL=/usr/bin/env bash
NAME=tfctl
BIN_PATH ?= dist/$(NAME)
ASSETS ?= assets
VERSION_FILE ?= version/VERSION
SKILL_HASHES = skills/tfctl/known_release_hashes
SKILL_EMBEDDED = skills/tfctl/SKILL.md
CHANGELOG_FILE = CHANGELOG.md
ifeq ($(GOARCH), arm64)
GOARCH = arm64
else ifeq ($(GOARCH), s390x)
GOARCH = s390x
else
GOARCH = amd64
endif
default: help
.PHONY: linux
linux:
GOOS=linux GOARCH=$(GOARCH) $(MAKE) bin
.PHONY: docker
docker: linux
docker build --build-arg BUILD_DIRECTORY="dist" -t hashicorp/$(NAME):latest .
.PHONY: bin
bin: $(BIN_PATH)
.PHONY: $(BIN_PATH)
$(BIN_PATH):
CGO_ENABLED=0 go build -o $(BIN_PATH) -trimpath -buildvcs=false ./cmd/$(NAME)
.PHONY: clean
clean:
rm -rf $(CURDIR)/$(dir $(BIN_PATH))
.PHONY: gen/screenshot
gen/screenshot: go/install # Create a screenshot of the tfctl CLI
@go run github.com/homeport/termshot/cmd/termshot@v0.6.1 -c -f $(ASSETS)/tfctl.png -- tfctl --help
.PHONY: gen/logo
gen/logo: logotools
@lolcat -S 26 -f <(figlet -d ./assets -f "Sub-Zero.flf" tfctl) > ./cmd/tfctl/logo.txt
.PHONY: gen/openapi
gen/openapi:
@curl -s -o ./internal/pkg/openapi/spec/hcpt_v2_public_beta.json https://app.terraform.io/openapi/prerelease.json
@echo "Embedded OpenAPI spec updated successfully"
.PHONY: go/build
go/build: bin
.PHONY: go/install
go/install:
@go install ./cmd/tfctl
.PHONY: go/lint
go/lint:
@golangci-lint run
.PHONY: go/test
go/test:
@go test -v ./...
# Format code
.PHONY: go/fmt
go/fmt:
@gofmt -s -w .
# Check formatting
.PHONY: fmt-check
fmt-check:
@test -z "$$(gofmt -s -l . | tee /dev/stderr)" || (echo "Code is not formatted. Run 'make go/fmt'" && exit 1)
# Release targets
.PHONY: prepare-release
prepare-release: gen/openapi
@if [ -z "$(VERSION)" ]; then echo "VERSION is not set"; exit 1; fi
@if [ -z "$(CHANGIE_VERSION)" ]; then echo "CHANGIE_VERSION is not set"; exit 1; fi
@echo $(VERSION) > $(VERSION_FILE)
@echo "Updated $(VERSION_FILE) to $(VERSION)"
@echo "$$(shasum -a 256 $(SKILL_EMBEDDED) | cut -d' ' -f1) v$(VERSION)" >> $(SKILL_HASHES)
@echo "Appended sha256 for $(SKILL_EMBEDDED) to $(SKILL_HASHES)"
@npx -q changie@$(CHANGIE_VERSION) batch $(VERSION)
.PHONY: cleanup-release
cleanup-release:
@if [ -z "$(DEV_VERSION)" ]; then echo "DEV_VERSION is not set"; exit 1; fi
@if ! $$(git tag -l v$$(cat version/VERSION) >/dev/null 2>&1); then echo "Lastest version $$(cat version/VERSION) has not been released"; exit 1; fi
@echo $(DEV_VERSION) > $(VERSION_FILE)
@echo "## Unreleased" > $(CHANGELOG_FILE)
@echo "" >> $(CHANGELOG_FILE)
@echo "This file will be populated by automation before release. See this [CHANGELOG.md](https://github.com/hashicorp/tfctl-cli/blob/v$(VERSION)/CHANGELOG.md) for information about the latest release." >> $(CHANGELOG_FILE)
@echo "Release cleanup finished, version is now $(DEV_VERSION)"
# Install development tools
.PHONY: tools
tools:
@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v$$(cat .golangci-lint-version | head -n 1)
@command -v changie >/dev/null 2>&1 || { \
echo "Installing changie..."; \
if command -v brew >/dev/null 2>&1; then brew install changie; \
else echo "Could not auto-install changie: https://changie.dev/guide/installation/" && exit 1; \
fi; \
}
.PHONY: logotools
logotools:
@command -v lolcat >/dev/null 2>&1 || { \
echo "Installing lolcat..."; \
if command -v brew >/dev/null 2>&1; then brew install lolcat; \
else echo "Could not auto-install lolcat: https://github.com/busyloop/lolcat" && exit 1; \
fi; \
}
@command -v figlet >/dev/null 2>&1 || { \
echo "Install figlet https://www.figlet.org/" && exit 1; \
}
.PHONY: check
check: fmt-check go/lint go/test
# Help (make usage)
.PHONY: help
help:
@echo "Available targets:"
@echo ""
@echo "Tools:"
@echo " tools Install development tools"
@echo " gen/screenshot Generate a screenshot of the CLI in $(ASSETS)/"
@echo " gen/logo Generate the ASCII art logo"
@echo ""
@echo "Build:"
@echo " go/install Install tfctl binary to GOPATH/bin"
@echo " bin Build a binary for tfctl ($(BIN_PATH))"
@echo " clean Clean build artifacts"
@echo " docker Build a docker image for tfctl"
@echo ""
@echo "Code:"
@echo " check Run all checks (formatting, linting, tests)"
@echo " go/test Run all tests"
@echo " go/lint Run golangci-lint"
@echo " go/fmt Format go code"
@echo " fmt-check Check go code formatting"
@echo ""
@echo "Release:"
@echo " gen/openapi Update embedded OpenAPI spec"
@echo " prepare-release Prepare next semantic version release,"
@echo " requires VERSION argument"
@echo " cleanup-release Clean up after a release"
@echo " requires DEV_VERSION argument"
@echo ""