-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
116 lines (95 loc) · 3.27 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
PROJECT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
VERSION ::= $(shell git describe --always --tags --dirty)
BUILD_TIME ::= $(shell date "+%Y-%m-%d_%H:%M:%S%:z")
COMMITISH ::= $(shell git describe --always --dirty)
ifeq (${GOPATH},)
GOPATH := ${HOME}/go
endif
OS ::= $(shell uname -s)
SHELL = /bin/bash
GO_VERSION=1.22
define build_binary
@echo "Building $(1)/$(2)..."
CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build \
-a \
-ldflags "-X github.com/cbuschka/tfvm/internal/build.buildInfoVersion=${VERSION} \
-X github.com/cbuschka/tfvm/internal/build.buildInfoBuildTime=${BUILD_TIME} \
-X github.com/cbuschka/tfvm/internal/build.buildInfoCommitish=${COMMITISH} \
-X github.com/cbuschka/tfvm/internal/build.buildInfoOs=$(1) \
-X github.com/cbuschka/tfvm/internal/build.buildInfoArch=$(2) \
-extldflags \"-static\"" \
-o dist/tfvm-$(1)_$(2)$(3) \
cmd/tfvm/tfvm.go
endef
all: clean build_linux build_windows build_macosx integration_test
check_go_version:
@if [[ ! "$$(go version)" =~ ^.*go${GO_VERSION}.*$$ ]]; then \
echo "Wrong go version. Expected go ${GO_VERSION}."; \
exit 1; \
else \
echo "Go version ok."; \
fi
init: check_go_version
@if [ "${OS}" != "Linux" ] && [ "${OS}" != "Darwin" ]; then \
echo "Sorry only Linux and macOS supported as build platform. (This is ${OS}.)"; \
exit 1; \
fi; \
mkdir -p ${GOPATH}
lint: init
@echo "### Running linter..."
go install golang.org/x/lint/golint@latest
${GOPATH}/bin/golint ./internal/... ./cmd/...
build: test lint
go vet ./...
mkdir -p dist/
build_all: build build_linux build_windows build_macosx
build_linux: build_linux_amd64 build_linux_386 build_linux_arm64
@echo "### Building Linux variants..."
$(call build_binary,linux,amd64,)
build_linux_arm64: build
$(call build_binary,linux,arm64,)
build_linux_amd64: build
$(call build_binary,linux,amd64,)
build_linux_386: build
$(call build_binary,linux,386,)
.PHONY: clean
clean: init
@echo "### Cleaning up..."
rm -rf ${PROJECT_DIR}/dist/ ${PROJECT_DIR}/.cache/
format:
gofmt -l -w -s ${PROJECT_DIR}
build_windows: build
@echo "### Building Windows variants..."
$(call build_binary,windows,amd64,.exe)
$(call build_binary,windows,386,.exe)
build_macosx: build
@echo "### Building macOS variants..."
$(call build_binary,darwin,amd64,)
$(call build_binary,darwin,arm64,)
test: init
@echo "### Running unit tests..."
go test -cover -race -coverprofile=coverage.txt -covermode=atomic ./internal/... ./cmd/...
integration_test:
@echo "### Running integration tests..."
${PROJECT_DIR}/scripts/run-integration-tests.sh
dump_tf_releases: init
(echo -e "package state\n\nconst defaultStateJSON = \`" && \
go run ./cmd/dump_tf_releases/ ./internal/... && \
echo '`' ) > ${PROJECT_DIR}/internal/inventory/default_inventory_state.go.new && \
mv ${PROJECT_DIR}/internal/inventory/default_inventory_state.go.new ${PROJECT_DIR}/internal/inventory/state/default_inventory_state.go
build_with_docker:
docker run -u $(shell id -u):$(shell id -g) \
-v ${PROJECT_DIR}:/build \
-w /build \
-e HOME=/build \
golang:${GO_VERSION}-buster \
make build
test_with_docker:
docker run -u $(shell id -u):$(shell id -g) \
-v ${PROJECT_DIR}:/build \
-w /build \
-e HOME=/build \
golang:${GO_VERSION} \
make test
update_dependencies: init
go get -t -u ./...