-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
340 lines (289 loc) · 14 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
PACK := commandx
PROJECT := github.com/unstoppablemango/pulumi-${PACK}
PROVIDER := pulumi-resource-${PACK}
WORKING_DIR := $(shell pwd)
SCHEMA_FILE := ${WORKING_DIR}/provider/cmd/${PROVIDER}/schema.json
PROVIDER_PKG := ${WORKING_DIR}/provider/cmd/${PROVIDER}/package.json
PROVIDER_SRC := $(shell find ${WORKING_DIR}/provider/cmd/${PROVIDER} -type f -name '*.ts' -not -path '*node_modules*')
SCHEMAGEN_SRC := $(shell find ${WORKING_DIR}/schemagen -type f -name '*.go')
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOEXE ?= $(shell go env GOEXE)
LOCAL_PROVIDER_FILENAME := $(PROVIDER)$(GOEXE)
export GOWORK := off
# Only use explicitly installed plugins - this is to avoid using any ambient plugins from the PATH
export PULUMI_IGNORE_AMBIENT_PLUGINS = true
ifeq ($(CI)$(PROVIDER_VERSION),true)
$(error PROVIDER_VERSION must be set in CI environments)
endif
# Input during CI using `make [TARGET] PROVIDER_VERSION=""` or by setting a PROVIDER_VERSION environment variable
# Local builds will just used this fixed default version unless specified
PROVIDER_VERSION ?= 0.0.1-alpha.0+dev
# Ensure the leading "v" is removed - use this normalised version everywhere rather than the raw input to ensure consistency.
# These variables are lazy (no `:`) so they're not calculated until after the dependency is installed
VERSION_GENERIC = $(shell bin/pulumictl convert-version -l generic -v "$(PROVIDER_VERSION)")
VERSION_FLAGS = -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION_GENERIC}"
# Ensure make directory exists
# For targets which either don't generate a single file output, or the file is committed, we use a "sentinel"
# file within `.make/` to track the staleness of the target and only rebuild when needed. At the end of each
# relevant target we run `@touch $@` to update the file which is the name of the target.
_ := $(shell mkdir -p .make)
.PHONY: default ensure
default: provider build_sdks
ensure: bin/pulumictl .pulumi/bin/pulumi
.PHONY: schema
schema: generate_schema
# Binaries
.PHONY: provider
provider: bin/$(LOCAL_PROVIDER_FILENAME)
.PHONY: test test_dotnet test_python test_go test_nodejs
# Set TEST_TAGS to override -tags for tests
TEST_TAGS ?= all
# Set TEST_NAME to filter tests by name
TEST_NAME ?=
TEST_RUN =
ifneq ($(TEST_NAME),)
TEST_RUN = -run ^$(TEST_NAME)$$
endif
TEST_SHORT =
ifneq ($(SHORT),)
TEST_SHORT = -short
endif
export PULUMI_LOCAL_NUGET=$(WORKING_DIR)/nuget
test: provider build_dotnet build_python install_sdks bin/gotestfmt
cd examples && go test -json -v $(TEST_SHORT) -tags=$(TEST_TAGS) -timeout 2h $(TEST_RUN) | tee /tmp/gotest.log | gotestfmt
test_dotnet: provider build_dotnet install_dotnet_sdk
cd examples && go test -v $(TEST_SHORT) -tags=dotnet -timeout 2h $(TEST_RUN)
test_python: provider build_python
cd examples && go test -v $(TEST_SHORT) -tags=python -timeout 2h $(TEST_RUN)
test_go: provider
cd examples && go test -v $(TEST_SHORT) -tags=go -timeout 2h $(TEST_RUN)
test_nodejs: provider install_nodejs_sdk .make/examples_dockerfile
cd examples && go test -v $(TEST_SHORT) -tags=nodejs -timeout 2h $(TEST_RUN)
.PHONY: install_provider
install_provider: .make/install_provider
.PHONY: docker
docker: .make/examples_dockerfile
.PHONY: codegen
codegen: generate_schema
.PHONY: generate generate_java generate_nodejs generate_python generate_dotnet generate_go generate_types generate_schema
generate: generate_schema generate_types generate_java generate_nodejs generate_python generate_dotnet generate_go
generate_java: .make/generate_java
generate_nodejs: .make/generate_nodejs
generate_python: .make/generate_python
generate_dotnet: .make/generate_dotnet
generate_go: .make/generate_go
generate_types: .make/generate_types
generate_schema: provider/cmd/$(PROVIDER)/schema.json
.PHONY: local_generate_code
local_generate_code: generate_java
local_generate_code: generate_nodejs
local_generate_code: generate_python
local_generate_code: generate_dotnet
local_generate_code: generate_go
local_generate_code: generate_types
local_generate: local_generate_code
.PHONY: build only_build build_sdks build_nodejs build_python build_dotnet build_java build_go
build: local_generate provider build_sdks
# Required for the codegen action that runs in pulumi/pulumi
only_build: build
build_sdks: build_nodejs build_dotnet build_python build_go build_java
build_nodejs: .make/build_nodejs
build_python: .make/build_python
build_dotnet: .make/build_dotnet
build_java: .make/build_java
build_go: .make/build_go
.PHONY: install_dotnet_sdk install_python_sdk install_go_sdk install_java_sdk install_nodejs_sdk install_sdks
# Required by CI steps - some can be skipped
install_dotnet_sdk: .make/install_dotnet_sdk
install_python_sdk:
install_go_sdk:
install_java_sdk:
install_nodejs_sdk: .make/install_nodejs_sdk
install_sdks: install_dotnet_sdk install_nodejs_sdk
.PHONY: link link_examples
link: link_examples
link_examples: install_nodejs_sdk
find ${WORKING_DIR}/examples -type d -name '*-ts' \
-exec echo 'Linking: {}' \; \
-exec sh -c 'cd {} && yarn link "@unmango/pulumi-commandx"' \;
.PHONY: tidy
tidy:
cd examples && go mod tidy
cd schemagen && go mod tidy
cd sdk && go mod tidy
.PHONY: clean
clean:
rm -rf nuget
rm -rf .make
rm -rf bin
rm -rf dist
rm -rf provider/scripts/vendor
rm -rf sdk/dotnet/{bin,obj}
rm -rf sdk/nodejs/bin
rm -rf sdk/python/bin
rm -rf sdk/java/{.gradle,build}
rm -rf $(SCHEMA_FILE)
@if dotnet nuget list source | grep "$(WORKING_DIR)"; then \
dotnet nuget remove source "$(WORKING_DIR)" \
; fi
vendor: provider/scripts/vendor/pulumi-schema.d.ts
.PHONY: upgrade_tools upgrade_java upgrade_pulumi upgrade_pulumictl upgrade_schematools
upgrade_tools: upgrade_java upgrade_pulumi upgrade_pulumictl upgrade_schematools
upgrade_java:
gh release list --repo pulumi/pulumi-java --exclude-drafts --exclude-pre-releases --limit 1 | cut -f1 > .pulumi-java-gen.version
upgrade_pulumi:
gh release list --repo pulumi/pulumi --exclude-drafts --exclude-pre-releases --limit 1 | cut -f1 | sed 's/^v//' > .pulumi.version
upgrade_pulumictl:
gh release list --repo pulumi/pulumictl --exclude-drafts --exclude-pre-releases --limit 1 | cut -f1 | sed 's/^v//' > .pulumictl.version
upgrade_schematools:
gh release list --repo pulumi/schema-tools --exclude-drafts --exclude-pre-releases --limit 1 | cut -f1 | sed 's/^v//' > .schema-tools.version
# --------- File-based targets --------- #
.pulumi/bin/pulumi: PULUMI_VERSION := $(shell cat .pulumi.version)
.pulumi/bin/pulumi: HOME := $(WORKING_DIR)
.pulumi/bin/pulumi: .pulumi.version
curl -fsSL https://get.pulumi.com | sh -s -- --version "$(PULUMI_VERSION)"
# Download local copy of pulumictl based on the version in .pulumictl.version
# Anywhere which uses VERSION_GENERIC or VERSION_FLAGS should depend on bin/pulumictl
bin/pulumictl: PULUMICTL_VERSION := $(shell cat .pulumictl.version)
bin/pulumictl: PLAT := $(shell go version | sed -En "s/go version go.* (.*)\/(.*)/\1-\2/p")
bin/pulumictl: PULUMICTL_URL := "https://github.com/pulumi/pulumictl/releases/download/v$(PULUMICTL_VERSION)/pulumictl-v$(PULUMICTL_VERSION)-$(PLAT).tar.gz"
bin/pulumictl: .pulumictl.version
@echo "Installing pulumictl"
@mkdir -p bin
wget -q -O - "$(PULUMICTL_URL)" | tar -xzf - -C $(WORKING_DIR)/bin pulumictl
@touch bin/pulumictl
@echo "pulumictl" $$(./bin/pulumictl version)
# Download local copy of schema-tools based on the version in .schema-tools.version
bin/schema-tools: SCHEMA_TOOLS_VERSION := $(shell cat .schema-tools.version)
bin/schema-tools: PLAT := $(shell go version | sed -En "s/go version go.* (.*)\/(.*)/\1-\2/p")
bin/schema-tools: SCHEMA_TOOLS_URL := "https://github.com/pulumi/schema-tools/releases/download/v$(SCHEMA_TOOLS_VERSION)/schema-tools-v$(SCHEMA_TOOLS_VERSION)-$(PLAT).tar.gz"
bin/schema-tools: .schema-tools.version
@echo "Installing schema-tools"
@mkdir -p bin
wget -q -O - "$(SCHEMA_TOOLS_URL)" | tar -xzf - -C $(WORKING_DIR)/bin schema-tools
@touch bin/schema-tools
@echo "schema-tools" $$(./bin/schema-tools version)
bin/gotestfmt:
@mkdir -p bin
GOBIN="${WORKING_DIR}/bin" go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@v2.5.0
bin/$(LOCAL_PROVIDER_FILENAME): bin/pulumictl .make/provider_mod_download provider/cmd/$(PROVIDER)/schema.json $(PROVIDER_SRC) $(PROVIDER_PKG)
cd provider/cmd/${PROVIDER}/ && \
yarn tsc && \
cp package.json schema.json ./bin && \
sed -i.bak -e "s/\$${VERSION}/$(PROVIDER_VERSION)/g" bin/package.json && \
yarn run pkg . ${PKG_ARGS} --target node16 --output $(WORKING_DIR)/$@
bin/linux-amd64/$(PROVIDER): TARGET := linuxstatic-x64
bin/linux-arm64/$(PROVIDER): TARGET := linuxstatic-arm64
bin/darwin-amd64/$(PROVIDER): TARGET := macos-x64
bin/darwin-arm64/$(PROVIDER): TARGET := macos-arm64
bin/windows-amd64/$(PROVIDER).exe: TARGET := win-x64
bin/%/$(PROVIDER) bin/%/$(PROVIDER).exe: bin/pulumictl .make/provider_mod_download provider/cmd/$(PROVIDER)/schema.json $(PROVIDER_SRC) $(PROVIDER_PKG)
@# check the TARGET is set
test $(TARGET)
cd provider/cmd/${PROVIDER}/ && \
yarn tsc && \
cp package.json schema.json ./bin && \
sed -i.bak -e "s/\$${VERSION}/$(PROVIDER_VERSION)/g" bin/package.json && \
yarn run pkg . ${PKG_ARGS} --target node16-$(TARGET) --output $(WORKING_DIR)/$@
dist/$(PROVIDER)-v$(PROVIDER_VERSION)-linux-amd64.tar.gz: bin/linux-amd64/$(PROVIDER)
dist/$(PROVIDER)-v$(PROVIDER_VERSION)-linux-arm64.tar.gz: bin/linux-arm64/$(PROVIDER)
dist/$(PROVIDER)-v$(PROVIDER_VERSION)-darwin-amd64.tar.gz: bin/darwin-amd64/$(PROVIDER)
dist/$(PROVIDER)-v$(PROVIDER_VERSION)-darwin-arm64.tar.gz: bin/darwin-arm64/$(PROVIDER)
dist/$(PROVIDER)-v$(PROVIDER_VERSION)-windows-amd64.tar.gz: bin/windows-amd64/$(PROVIDER).exe
dist/$(PROVIDER)-v$(PROVIDER_VERSION)-%.tar.gz:
@mkdir -p dist
@# $< is the last dependency (the binary path from above)
tar --gzip -cf $@ README.md LICENSE -C $$(dirname $<) .
dist: dist/$(PROVIDER)-v$(PROVIDER_VERSION)-linux-amd64.tar.gz
dist: dist/$(PROVIDER)-v$(PROVIDER_VERSION)-linux-arm64.tar.gz
dist: dist/$(PROVIDER)-v$(PROVIDER_VERSION)-darwin-amd64.tar.gz
dist: dist/$(PROVIDER)-v$(PROVIDER_VERSION)-darwin-arm64.tar.gz
dist: dist/$(PROVIDER)-v$(PROVIDER_VERSION)-windows-amd64.tar.gz
provider/cmd/$(PROVIDER)/schema.json: $(SCHEMAGEN_SRC)
cd schemagen/cmd/pulumi-gen-commandx && \
go run main.go ${WORKING_DIR}/provider/cmd/${PROVIDER}
provider/scripts/vendor/pulumi-schema.d.ts: AWSX_VERSION := $(shell cat .awsx.version)
provider/scripts/vendor/pulumi-schema.d.ts: .awsx.version
@mkdir -p provider/scripts/vendor
curl -sSL 'https://raw.githubusercontent.com/pulumi/pulumi-awsx/v$(AWSX_VERSION)/awsx/scripts/pulumi-schema.d.ts' > $@
# --------- Sentinel targets --------- #
.make/provider_mod_download: provider/cmd/${PROVIDER}/package.json
cd provider/cmd/${PROVIDER}/ && \
yarn install
@touch $@
.make/generate_java: bin/pulumictl .pulumi/bin/pulumi provider/cmd/$(PROVIDER)/schema.json
rm -rf sdk/java
.pulumi/bin/pulumi package gen-sdk $(SCHEMA_FILE) --language java --version "${VERSION_GENERIC}"
@touch $@
.make/generate_nodejs: bin/pulumictl .pulumi/bin/pulumi provider/cmd/$(PROVIDER)/schema.json
rm -rf sdk/nodejs
.pulumi/bin/pulumi package gen-sdk $(SCHEMA_FILE) --language nodejs --version "${VERSION_GENERIC}"
sed -i.bak -e "s/sourceMap/inlineSourceMap/g" sdk/nodejs/tsconfig.json
sed -i.bak -e 's/"remote"/".\/remote"/g' sdk/nodejs/*.ts
rm sdk/nodejs/*.bak
@touch $@
.make/generate_python: bin/pulumictl .pulumi/bin/pulumi provider/cmd/$(PROVIDER)/schema.json
rm -rf sdk/python
.pulumi/bin/pulumi package gen-sdk $(SCHEMA_FILE) --language python --version "${VERSION_GENERIC}"
cp README.md sdk/python
@touch $@
.make/generate_dotnet: bin/pulumictl .pulumi/bin/pulumi provider/cmd/$(PROVIDER)/schema.json
rm -rf sdk/dotnet
.pulumi/bin/pulumi package gen-sdk $(SCHEMA_FILE) --language dotnet --version "${VERSION_GENERIC}"
sed -i.bak -e "s/<\/Nullable>/<\/Nullable>\n <UseSharedCompilation>false<\/UseSharedCompilation>/g" sdk/dotnet/UnMango.Commandx.csproj
rm -f sdk/dotnet/*.bak sdk/dotnet/**/*.bak
@touch $@
.make/generate_go: bin/pulumictl .pulumi/bin/pulumi provider/cmd/$(PROVIDER)/schema.json
rm -rf sdk/go
.pulumi/bin/pulumi package gen-sdk $(SCHEMA_FILE) --language go --version "${VERSION_GENERIC}"
@touch $@
.make/generate_types: vendor provider/cmd/$(PROVIDER)/schema.json
cd provider/scripts && yarn install && yarn gen-types
cd provider/cmd/${PROVIDER} && sed -i.bak 's/input.remote.Connection/input.remote.ConnectionArgs/g' schema-types.ts && rm schema-types.ts.bak
@touch $@
.make/nodejs_yarn_install: .make/generate_nodejs sdk/nodejs/package.json
yarn install --cwd sdk/nodejs
@touch $@
.make/build_nodejs: bin/pulumictl .make/nodejs_yarn_install
cd sdk/nodejs/ && \
NODE_OPTIONS=--max-old-space-size=12288 yarn run tsc --diagnostics --incremental && \
cp ../../README.md ../../LICENSE package.json yarn.lock ./bin/
@touch $@
.make/build_python: bin/pulumictl .make/generate_python
cd sdk/python && \
git clean -fxd && \
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 .
@touch $@
.make/build_dotnet: bin/pulumictl .make/generate_dotnet
cd sdk/dotnet && \
echo "$(VERSION_GENERIC)" >version.txt && \
dotnet build
@touch $@
.make/build_java: bin/pulumictl .make/generate_java
cd sdk/java/ && \
gradle --console=plain -Pversion=$(VERSION_GENERIC) build
@touch $@
.make/build_go: .make/generate_go
cd sdk/go/commandx && go build
@touch $@
.make/install_nodejs_sdk: .make/build_nodejs
yarn link --cwd sdk/nodejs/bin
@touch $@
.make/install_dotnet_sdk:
@mkdir -p nuget
find sdk/dotnet/bin -name '*.nupkg' -print -exec cp -p {} ${WORKING_DIR}/nuget \;
if ! dotnet nuget list source | grep ${WORKING_DIR}; then \
dotnet nuget add source ${WORKING_DIR}/nuget --name ${WORKING_DIR} \
; fi
@touch $@
.make/install_provider: bin/pulumictl provider/cmd/$(PROVIDER)/* $(PROVIDER_PKG)
cd provider/cmd/${PROVIDER}/ && \
yarn run pkg . ${PKG_ARGS} --target node16 --output ${WORKING_DIR}/bin/${PROVIDER}
@touch $@
.make/examples_dockerfile: examples/Dockerfile
cd examples && docker build -t commandx:dev .