-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
117 lines (99 loc) · 4.34 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
# WARNING: This file is autogenerated - changes will be overwritten when regenerated by https://github.com/pulumi/ci-mgmt
PACK := terraform-module
ORG := pulumi
PROJECT := github.com/$(ORG)/pulumi-$(PACK)
GO_MODULE := $(PROJECT)
PROVIDER := pulumi-resource-$(PACK)
TESTPARALLELISM := 10
GOTESTARGS := ""
WORKING_DIR := $(shell pwd)
PULUMI_PROVIDER_BUILD_PARALLELISM ?=
# Override during CI using `make [TARGET] PROVIDER_VERSION=""` or by setting a PROVIDER_VERSION environment variable
# Local & branch builds will just used this fixed default version unless specified
PROVIDER_VERSION ?= 0.0.0-alpha.0+dev
# Check version doesn't start with a "v" - this is a common mistake
ifeq ($(shell echo $(PROVIDER_VERSION) | cut -c1),v)
$(error PROVIDER_VERSION should not start with a "v")
endif
# Strips debug information from the provider binary to reduce its size and speed up builds
LDFLAGS_STRIP_SYMBOLS=-s -w
LDFLAGS_PROJ_VERSION=-X $(GO_MODULE)/pkg/version.Version=$(PROVIDER_VERSION)
LDFLAGS=$(LDFLAGS_PROJ_VERSION) $(LDFLAGS_STRIP_SYMBOLS)
# Create a `.make` directory for tracking targets which don't generate a single file output. This should be ignored by git.
# For targets which either don't generate a single file output, or the output file is committed, we use a "sentinel"
# file within `.make/` to track the staleness of the target and only rebuild when needed.
# For each phony target, we create an internal target with the same name, but prefixed with `.make/` where the work is performed.
# At the end of each internal target we run `@touch $@` to update the file which is the name of the target.
# Ensure all directories exist before evaluating targets to avoid issues with `touch` creating directories.
_ := $(shell mkdir -p .make bin .pulumi/bin)
# Build the provider
build: install_plugins provider
# Keep aliases for old targets to ensure backwards compatibility
development: build
only_build: build
# Prepare the workspace for building the provider
# Importantly this is run by CI ahead of restoring the bin directory
prepare_local_workspace: install_plugins
# Creates all generated files which need to be committed
.PHONY: development only_build build
help:
@echo "Usage: make [target]"
@echo ""
@echo "Main Targets"
@echo " build (default) Build the provider"
@echo " provider Build the local provider binary"
@echo " lint_provider<.fix> Run the linter on the provider (& optionally fix)"
@echo " test_provider Run the provider tests"
@echo " test Run the example tests (must run 'build' first)"
@echo " clean Clean up generated files"
@echo ""
@echo "More Precise Targets"
@echo " provider_dist Build and package the provider for all platforms"
@echo ""
@echo "Tool Targets"
@echo " ci-mgmt Re-generate CI configuration from .ci-mgmt.yaml"
@echo ""
@echo "Internal Targets (automatically run as dependencies of other targets)"
@echo " prepare_local_workspace Prepare for building"
@echo " install_plugins Install plugin dependencies"
@echo ""
.PHONY: help
clean:
rm -rf bin/*
rm -rf .make/*
.PHONY: clean
lint_provider: provider
golangci-lint run -c .golangci.yml
# `lint_provider.fix` is a utility target meant to be run manually
# that will run the linter and fix errors when possible.
lint_provider.fix:
golangci-lint run -c .golangci.yml --fix
.PHONY: lint_provider lint_provider.fix
build_provider_cmd = GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build $(PULUMI_PROVIDER_BUILD_PARALLELISM) -o "$(3)" -ldflags "$(LDFLAGS)" $(GO_MODULE)/cmd/$(PROVIDER)
.PHONY: provider
provider: bin/$(PROVIDER)
bin/$(PROVIDER):
$(call build_provider_cmd,$(shell go env GOOS),$(shell go env GOARCH),$(WORKING_DIR)/bin/$(PROVIDER))
test:
cd tests && go test -parallel $(TESTPARALLELISM) -timeout 2h $(value GOTESTARGS)
.PHONY: test
test_provider_cmd = go test \
-coverprofile="coverage.txt" \
-coverpkg="./..." \
-parallel $(TESTPARALLELISM) \
./pkg/...
test_provider:
$(call test_provider_cmd)
.PHONY: test_provider
# To make an immediately observable change to .ci-mgmt.yaml:
#
# - Edit .ci-mgmt.yaml
# - Run make ci-mgmt to apply the change locally.
#
ci-mgmt: .ci-mgmt.yaml
go run github.com/pulumi/ci-mgmt/provider-ci@master generate
.PHONY: ci-mgmt
include scripts/plugins.mk
include scripts/crossbuild.mk
# Permit providers to extend the Makefile with provider-specific Make includes.
include $(wildcard .mk/*.mk)