forked from infracost/infracost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
140 lines (109 loc) · 7.33 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
BINARY := infracost
PKG := github.com/infracost/infracost/cmd/infracost
VERSION := $(shell scripts/get_version.sh HEAD $(NO_DIRTY))
LD_FLAGS := -ldflags="-X 'github.com/infracost/infracost/internal/version.Version=$(VERSION)'"
BUILD_FLAGS := $(LD_FLAGS) -v
DEV_ENV := dev
ifdef INFRACOST_ENV
DEV_ENV := $(INFRACOST_ENV)
endif
.PHONY: deps run build windows linux darwin build_all install release clean test fmt lint
deps:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go mod download
run:
env INFRACOST_ENV=$(DEV_ENV) go run $(LD_FLAGS) $(PKG) $(ARGS)
jsonschema:
go run ./cmd/jsonschema/main.go --out-file ./schema/infracost.schema.json
go run ./cmd/jsonschema/main.go --out-file ./schema/config.schema.json --schema config
tagschema:
cd internal/providers/terraform/provider_schemas && \
terraform init && \
terraform providers schema -json | jq '.provider_schemas."registry.terraform.io/hashicorp/aws".resource_schemas | to_entries | map(select(.value.block.attributes.tags)) | from_entries | with_entries(.value = true)' > aws.tags.json && \
terraform providers schema -json | jq '.provider_schemas."registry.terraform.io/hashicorp/aws".resource_schemas | to_entries | map(select(.value.block.attributes.tags_all)) | from_entries | with_entries(.value = true)' > aws.tags_all.json && \
terraform providers schema -json | jq '.provider_schemas."registry.terraform.io/hashicorp/aws".resource_schemas | to_entries | map(select(.value.block.block_types.tag)) | from_entries | with_entries(.value = true)' > aws.tag_block.json && \
terraform providers schema -json | jq '.provider_schemas."registry.terraform.io/hashicorp/azurerm".resource_schemas | to_entries | map(select(.value.block.attributes.tags)) | from_entries | with_entries(.value = true)' > azurerm.tags.json && \
terraform providers schema -json | jq '.provider_schemas."registry.terraform.io/hashicorp/google".resource_schemas | to_entries | map(select(.value.block.attributes.labels)) | from_entries | with_entries(.value = true)' > google.labels.json
build:
CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/$(BINARY) $(PKG)
windows:
env GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/$(BINARY).exe $(PKG)
env GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/$(BINARY)-arm64.exe $(PKG)
linux:
env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/$(BINARY)-linux-amd64 $(PKG)
env GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/$(BINARY)-linux-arm64 $(PKG)
darwin:
env GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/$(BINARY)-darwin-amd64 $(PKG)
env GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/$(BINARY)-darwin-arm64 $(PKG)
build_all: build windows linux darwin
install:
CGO_ENABLED=0 go install $(BUILD_FLAGS) $(PKG)
release: build_all
cd build; tar -czf $(BINARY)-windows-amd64.tar.gz $(BINARY).exe; shasum -a 256 $(BINARY)-windows-amd64.tar.gz > $(BINARY)-windows-amd64.tar.gz.sha256
cd build; zip -r $(BINARY)-windows-amd64.zip $(BINARY).exe; shasum -a 256 $(BINARY)-windows-amd64.zip > $(BINARY)-windows-amd64.zip.sha256
cd build; tar -czf $(BINARY)-windows-arm64.tar.gz $(BINARY)-arm64.exe; shasum -a 256 $(BINARY)-windows-arm64.tar.gz > $(BINARY)-windows-arm64.tar.gz.sha256
cd build; mv $(BINARY)-arm64.exe $(BINARY).exe; zip -r $(BINARY)-windows-arm64.zip $(BINARY).exe; shasum -a 256 $(BINARY)-windows-arm64.zip > $(BINARY)-windows-arm64.zip.sha256
cd build; tar -czf $(BINARY)-linux-amd64.tar.gz $(BINARY)-linux-amd64; shasum -a 256 $(BINARY)-linux-amd64.tar.gz > $(BINARY)-linux-amd64.tar.gz.sha256
cd build; tar -czf $(BINARY)-linux-arm64.tar.gz $(BINARY)-linux-arm64; shasum -a 256 $(BINARY)-linux-arm64.tar.gz > $(BINARY)-linux-arm64.tar.gz.sha256
cd build; tar -czf $(BINARY)-darwin-amd64.tar.gz $(BINARY)-darwin-amd64; shasum -a 256 $(BINARY)-darwin-amd64.tar.gz > $(BINARY)-darwin-amd64.tar.gz.sha256
cd build; tar -czf $(BINARY)-darwin-arm64.tar.gz $(BINARY)-darwin-arm64; shasum -a 256 $(BINARY)-darwin-arm64.tar.gz > $(BINARY)-darwin-arm64.tar.gz.sha256
clean:
go clean
rm -rf build/$(BINARY)*
# Run only short unit tests
test:
INFRACOST_LOG_LEVEL=warn go test -short $(LD_FLAGS) ./... $(or $(ARGS), -v -cover)
# Run all tests
test_all:
INFRACOST_LOG_LEVEL=warn go test -timeout 30m $(LD_FLAGS) ./... $(or $(ARGS), -v -cover)
# Run unit tests and shared integration tests
test_shared_int:
INFRACOST_LOG_LEVEL=warn go test -timeout 30m $(LD_FLAGS) \
$(shell go list ./... | grep -v ./internal/providers/terraform/aws | grep -v ./internal/providers/terraform/google | grep -v ./internal/providers/terraform/azure) \
$(or $(ARGS), -v -cover)
test_cmd:
INFRACOST_LOG_LEVEL=warn go test -timeout 30m $(LD_FLAGS) ./cmd/infracost $(or $(ARGS), -v -cover)
test_update_cmd:
INFRACOST_LOG_LEVEL=warn go test -timeout 30m $(LD_FLAGS) ./cmd/infracost $(or $(ARGS), -update -v -cover)
test_usage:
INFRACOST_LOG_LEVEL=warn go test -timeout 30m $(LD_FLAGS) ./internal/usage $(or $(ARGS), -v -cover)
test_update_usage:
INFRACOST_LOG_LEVEL=warn go test -timeout 30m $(LD_FLAGS) ./internal/usage $(or $(ARGS), -update -v -cover)
# Run AWS resource tests
test_aws:
INFRACOST_LOG_LEVEL=warn go test -timeout 30m $(LD_FLAGS) ./internal/providers/terraform/aws $(or $(ARGS), -v -cover)
# Run Google resource tests
test_google:
INFRACOST_LOG_LEVEL=warn go test -timeout 30m $(LD_FLAGS) ./internal/providers/terraform/google $(or $(ARGS), -v -cover)
# Run Azure resource tests
test_azure:
INFRACOST_LOG_LEVEL=warn go test -timeout 30m $(LD_FLAGS) ./internal/providers/terraform/azure $(or $(ARGS), -v -cover)
# Update AWS golden files tests
test_update:
INFRACOST_LOG_LEVEL=warn go test -timeout 30m $(LD_FLAGS) ./internal/providers/... $(or $(ARGS), -update -v -cover)
# Update golden files tests
test_update_aws:
INFRACOST_LOG_LEVEL=warn go test -timeout 30m $(LD_FLAGS) ./internal/providers/terraform/aws $(or $(ARGS), -update -v -cover)
# Update Google golden files tests
test_update_google:
INFRACOST_LOG_LEVEL=warn go test -timeout 30m $(LD_FLAGS) ./internal/providers/terraform/google $(or $(ARGS), -update -v -cover)
# Update Azure golden files tests
test_update_azure:
INFRACOST_LOG_LEVEL=warn go test -timeout 30m $(LD_FLAGS) ./internal/providers/terraform/azure $(or $(ARGS), -update -v -cover)
fmt:
go fmt ./...
@find . -path '*/.*' -prune -o -name '*_with_error.tf' -prune -o -name '*.tf' -type f -print0 | xargs -0 -L1 bash -c '! test "$$(tail -c 1 "$$0")" || (echo >> "$$0" && echo "Terminating newline added to $$0")'
find . -path '*/.*' -prune -o -name '*_with_error.tf' -prune -o -name '*.tf' -exec terraform fmt {} +;
tf_fmt_check:
@echo "Checking Terraform formatting..."
@if ! find . -path '*/.*' -prune -o -name '*_with_error.tf' -prune -o -name '*.tf' -exec terraform fmt -check=true -write=false {} +; then \
echo "Terraform files not formatted. Run 'make fmt' to fix, or rename the file to '..._with_error.tf' to ignore."; \
exit 1; \
fi
@echo "Checking that .tf files end with newline..."
@if ! find . -path '*/.*' -prune -o -name '*_with_error.tf' -prune -o -name '*.tf' -type f -print0 | xargs -0 -L1 bash -c '! test "$$(tail -c 1 "$$0")" || (echo "$$0" && false)'; then \
echo "Terraform files missing terminating newline. Run 'make fmt' to fix, or rename the file to '..._with_error.tf' to ignore."; \
exit 1; \
fi
lint:
golangci-lint run