generated from pulumi/pulumi-provider-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Makefile
177 lines (133 loc) · 5.57 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
PROJECT_NAME := Pulumi Command Resource Provider
PACK := command
PACKDIR := sdk
PROJECT := github.com/pulumi/pulumi-command
NODE_MODULE_NAME := @pulumi/command
NUGET_PKG_NAME := Pulumi.Command
PROVIDER := pulumi-resource-${PACK}
PROVIDER_PATH := provider
VERSION_PATH := ${PROVIDER_PATH}/pkg/version.Version
PULUMI := .pulumi/bin/pulumi
SCHEMA_FILE := provider/cmd/pulumi-resource-command/schema.json
export GOPATH := $(shell go env GOPATH)
WORKING_DIR := $(shell pwd)
TESTPARALLELISM := 4
# 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 ?= 1.0.0-alpha.0+dev
# Use this normalised version everywhere rather than the raw input to ensure consistency.
VERSION_GENERIC = $(shell pulumictl convert-version --language generic --version "$(PROVIDER_VERSION)")
# Need to pick up locally pinned pulumi-langage-* plugins.
export PULUMI_IGNORE_AMBIENT_PLUGINS = true
ensure:: tidy
tidy: tidy_provider tidy_examples
cd sdk && go mod tidy
tidy_examples:
cd examples && go mod tidy
tidy_provider:
cd provider && go mod tidy && cd tests && go mod tidy
$(SCHEMA_FILE): provider $(PULUMI)
$(PULUMI) package get-schema $(WORKING_DIR)/bin/${PROVIDER} | \
jq 'del(.version)' > $(SCHEMA_FILE)
# Codegen generates the schema file and *generates* all sdks. This is a local process and
# does not require the ability to build all SDKs.
#
# To build the SDKs, use `make build_sdks`
codegen: $(SCHEMA_FILE) sdk/dotnet sdk/go sdk/nodejs sdk/python sdk/java
.PHONY: sdk/%
sdk/%: $(SCHEMA_FILE)
rm -rf $@
$(PULUMI) package gen-sdk --language $* $(SCHEMA_FILE) --version "${VERSION_GENERIC}"
sdk/java: $(SCHEMA_FILE)
rm -rf $@
$(PULUMI) package gen-sdk --language java $(SCHEMA_FILE)
sdk/python: $(SCHEMA_FILE)
rm -rf $@
$(PULUMI) package gen-sdk --language python $(SCHEMA_FILE) --version "${VERSION_GENERIC}"
cp README.md ${PACKDIR}/python/
sdk/dotnet: $(SCHEMA_FILE)
rm -rf $@
$(PULUMI) package gen-sdk --language dotnet $(SCHEMA_FILE) --version "${VERSION_GENERIC}"
# Copy the logo to the dotnet directory before building so it can be included in the nuget package archive.
# https://github.com/pulumi/pulumi-command/issues/243
cd ${PACKDIR}/dotnet/&& \
cp $(WORKING_DIR)/assets/logo.png logo.png
.PHONY: provider
provider:
cd provider && go build -o $(WORKING_DIR)/bin/${PROVIDER} -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION_GENERIC}" $(PROJECT)/${PROVIDER_PATH}/cmd/$(PROVIDER)
.PHONY: provider_debug
provider_debug:
(cd provider && go build -o $(WORKING_DIR)/bin/${PROVIDER} -gcflags="all=-N -l" -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION_GENERIC}" $(PROJECT)/${PROVIDER_PATH}/cmd/$(PROVIDER))
test_provider: tidy_provider
cd provider && go test -short -v -count=1 -cover -timeout 2h -parallel ${TESTPARALLELISM} ./...
dotnet_sdk: sdk/dotnet
cd ${PACKDIR}/dotnet/&& \
echo "${VERSION_GENERIC}" > version.txt && \
dotnet build
go_sdk: sdk/go
nodejs_sdk: sdk/nodejs
cd ${PACKDIR}/nodejs/ && \
yarn install && \
yarn run tsc
cp README.md LICENSE ${PACKDIR}/nodejs/package.json ${PACKDIR}/nodejs/yarn.lock ${PACKDIR}/nodejs/bin/
python_sdk: sdk/python
cp README.md ${PACKDIR}/python/
cd ${PACKDIR}/python/ && \
rm -rf ./bin/ ../python.bin/ && cp -R . ../python.bin && mv ../python.bin ./bin && \
python3 -m venv venv && \
./venv/bin/python -m pip install build && \
cd ./bin && \
../venv/bin/python -m build .
bin/pulumi-java-gen::
echo pulumi-java-gen is no longer necessary
java_sdk:: PACKAGE_VERSION := $(VERSION_GENERIC)
java_sdk:: sdk/java
cd sdk/java/ && \
gradle --console=plain build
.PHONY: build
build:: provider build_sdks
.PHONY: build_sdks
build_sdks: dotnet_sdk go_sdk nodejs_sdk python_sdk java_sdk
# Required for the codegen action that runs in pulumi/pulumi
only_build:: build
lint:
cd provider && golangci-lint --path-prefix provider --config ../.golangci.yml run
install:: install_nodejs_sdk install_dotnet_sdk
cp $(WORKING_DIR)/bin/${PROVIDER} ${GOPATH}/bin
GO_TEST := go test -v -count=1 -cover -timeout 2h -parallel ${TESTPARALLELISM}
test_all:: test
cd provider/pkg && $(GO_TEST) ./...
cd tests/sdk/nodejs && $(GO_TEST) ./...
cd tests/sdk/python && $(GO_TEST) ./...
cd tests/sdk/dotnet && $(GO_TEST) ./...
cd tests/sdk/go && $(GO_TEST) ./...
install_dotnet_sdk::
rm -rf $(WORKING_DIR)/nuget/$(NUGET_PKG_NAME).*.nupkg
mkdir -p $(WORKING_DIR)/nuget
find . -name '*.nupkg' -print -exec cp -p {} ${WORKING_DIR}/nuget \;
install_python_sdk::
#target intentionally blank
install_go_sdk::
#target intentionally blank
install_java_sdk::
#target intentionally blank
install_nodejs_sdk::
-yarn unlink --cwd $(WORKING_DIR)/sdk/nodejs/bin
yarn link --cwd $(WORKING_DIR)/sdk/nodejs/bin
test:: tidy_examples test_provider
cd examples && go test -v -tags=all -timeout 2h
# Keep the version of the pulumi binary used for code generation in sync with the version
# of the dependency used by github.com/pulumi/pulumi-command/provider
$(PULUMI): HOME := $(WORKING_DIR)
$(PULUMI): provider/go.mod
@ PULUMI_VERSION="$$(cd provider && go list -m github.com/pulumi/pulumi/pkg/v3 | awk '{print $$2}')"; \
if [ -x $(PULUMI) ]; then \
CURRENT_VERSION="$$($(PULUMI) version)"; \
if [ "$${CURRENT_VERSION}" != "$${PULUMI_VERSION}" ]; then \
echo "Upgrading $(PULUMI) from $${CURRENT_VERSION} to $${PULUMI_VERSION}"; \
rm $(PULUMI); \
fi; \
fi; \
if ! [ -x $(PULUMI) ]; then \
curl -fsSL https://get.pulumi.com | sh -s -- --version "$${PULUMI_VERSION#v}"; \
fi