-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
143 lines (112 loc) · 5.83 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
PROJECT_NAME := checkly Package
SHELL := /bin/bash
PACK := checkly
ORG := checkly
PROJECT := github.com/${ORG}/pulumi-${PACK}
NODE_MODULE_NAME := @checkly/${PACK}
TF_NAME := ${PACK}
PROVIDER_PATH := provider
VERSION_PATH := ${PROVIDER_PATH}/pkg/version.Version
TFGEN := pulumi-tfgen-${PACK}
PROVIDER := pulumi-resource-${PACK}
VERSION := $(shell pulumictl get version --omit-commit-hash)
TESTPARALLELISM := 4
WORKING_DIR := $(shell pwd)
OS := $(shell uname)
EMPTY_TO_AVOID_SED := ""
prepare::
@if test -z "${NAME}"; then echo "NAME not set"; exit 1; fi
@if test -z "${REPOSITORY}"; then echo "REPOSITORY not set"; exit 1; fi
@if test ! -d "provider/cmd/pulumi-tfgen-x${EMPTY_TO_AVOID_SED}yz"; then "Project already prepared"; exit 1; fi
mv "provider/cmd/pulumi-tfgen-x${EMPTY_TO_AVOID_SED}yz" provider/cmd/pulumi-tfgen-${NAME}
mv "provider/cmd/pulumi-resource-x${EMPTY_TO_AVOID_SED}yz" provider/cmd/pulumi-resource-${NAME}
if [[ "${OS}" != "Darwin" ]]; then \
sed -i 's,github.com/pulumi/pulumi-checkly,${REPOSITORY},g' provider/go.mod; \
find ./ ! -path './.git/*' -type f -exec sed -i 's/[x]yz/${NAME}/g' {} \; &> /dev/null; \
fi
# In MacOS the -i parameter needs an empty string to execute in place.
if [[ "${OS}" == "Darwin" ]]; then \
sed -i '' 's,github.com/pulumi/pulumi-checkly,${REPOSITORY},g' provider/go.mod; \
find ./ ! -path './.git/*' -type f -exec sed -i '' 's/[x]yz/${NAME}/g' {} \; &> /dev/null; \
fi
.PHONY: development provider build_sdks build_nodejs_sdk build_dotnet_sdk build_go_sdk build_python_sdk cleanup
development:: install_plugins provider lint_provider build_sdks install_sdks cleanup # Build the provider & SDKs for a development environment
# Required for the codegen action that runs in pulumi/pulumi and pulumi/pulumi-terraform-bridge
build:: install_plugins provider build_sdks install_sdks
only_build:: build
tfgen:: install_plugins
(cd provider && go build -o $(WORKING_DIR)/bin/${TFGEN} -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION}" ${PROJECT}/${PROVIDER_PATH}/cmd/${TFGEN})
$(WORKING_DIR)/bin/${TFGEN} schema --out provider/cmd/${PROVIDER}
(cd provider && VERSION=$(VERSION) go generate cmd/${PROVIDER}/main.go)
provider:: tfgen install_plugins # build the provider binary
(cd provider && go build -o $(WORKING_DIR)/bin/${PROVIDER} -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION}" ${PROJECT}/${PROVIDER_PATH}/cmd/${PROVIDER})
build_sdks:: install_plugins provider build_nodejs_sdk build_python_sdk build_go_sdk build_dotnet_sdk
build_nodejs_sdk:: VERSION := $(shell pulumictl get version --omit-commit-hash)
build_nodejs_sdk:: install_plugins tfgen # build the node sdk
$(WORKING_DIR)/bin/$(TFGEN) nodejs --overlays provider/overlays/nodejs --out sdk/nodejs/
cd sdk/nodejs/ && \
yarn install && \
yarn run tsc && \
cp -R scripts/ bin && \
cp ../../README.md ../../LICENSE package.json yarn.lock ./bin/ && \
sed -i.bak -e "s/\$${VERSION}/$(VERSION)/g" ./bin/package.json
build_python_sdk:: PYPI_VERSION := $(shell pulumictl get version --language python --omit-commit-hash)
build_python_sdk:: install_plugins tfgen # build the python sdk
$(WORKING_DIR)/bin/$(TFGEN) python --overlays provider/overlays/python --out sdk/python/
cd sdk/python/ && \
cp ../../README.md . && \
python3 setup.py clean --all 2>/dev/null && \
rm -rf ./bin/ ../python.bin/ && cp -R . ../python.bin && mv ../python.bin ./bin && \
sed -i.bak -e 's/^VERSION = .*/VERSION = "$(PYPI_VERSION)"/g' -e 's/^PLUGIN_VERSION = .*/PLUGIN_VERSION = "$(VERSION)"/g' ./bin/setup.py && \
rm ./bin/setup.py.bak && \
cd ./bin && python3 setup.py build sdist
build_dotnet_sdk:: DOTNET_VERSION := $(shell pulumictl get version --language dotnet --omit-commit-hash)
build_dotnet_sdk:: install_plugins tfgen # build the dotnet sdk
pulumictl get version --language dotnet --omit-commit-hash
$(WORKING_DIR)/bin/$(TFGEN) dotnet --overlays provider/overlays/dotnet --out sdk/dotnet/
cd sdk/dotnet/ && \
echo "${DOTNET_VERSION}" >version.txt && \
dotnet build /p:Version=${DOTNET_VERSION}
build_go_sdk:: install_plugins tfgen # build the go sdk
$(WORKING_DIR)/bin/$(TFGEN) go --overlays provider/overlays/go --out sdk/go/
lint_provider:: provider # lint the provider code
cd provider && golangci-lint run -c ../.golangci.yml
cleanup:: # cleans up the temporary directory
rm -r $(WORKING_DIR)/bin
rm -f provider/cmd/${PROVIDER}/schema.go
help::
@grep '^[^.#]\+:\s\+.*#' Makefile | \
sed "s/\(.\+\):\s*\(.*\) #\s*\(.*\)/`printf "\033[93m"`\1`printf "\033[0m"` \3 [\2]/" | \
expand -t20
clean::
rm -rf sdk/{dotnet,nodejs,go,python}
install_plugins::
[ -x $(shell which pulumi) ] || curl -fsSL https://get.pulumi.com | sh
pulumi plugin install resource random 4.3.1
install_dotnet_sdk::
mkdir -p $(WORKING_DIR)/nuget
find . -name '*.nupkg' -print -exec cp -p {} ${WORKING_DIR}/nuget \;
install_python_sdk::
install_go_sdk::
install_nodejs_sdk::
yarn link --cwd $(WORKING_DIR)/sdk/nodejs/bin
install_sdks:: install_dotnet_sdk install_python_sdk install_nodejs_sdk
test::
cd examples && go test -v -tags=all -parallel ${TESTPARALLELISM} -timeout 2h
sync::
make tfgen
make provider
make build_sdks
sync-examples: CURRENT_VERSION=$(shell git describe --tags --abbrev=0 | cut -c 2-)
sync-examples:
jq --arg v "${CURRENT_VERSION}" '.dependencies."@checkly/pulumi" =$$v' examples/js/package.json > tmp.$$.json && mv tmp.$$.json examples/js/package.json
jq --arg v "${CURRENT_VERSION}" '.dependencies."@checkly/pulumi" =$$v' examples/ts/package.json > tmp.$$.json && mv tmp.$$.json examples/ts/package.json
cd examples/js && npm i && cd -
cd examples/ts && npm i && cd -
dev::
make sync
cp bin/pulumi-resource-checkly ${GOPATH}/bin
make install_nodejs_sdk
cd examples/js && yarn link @checkly/pulumi && cd -
cd examples/ts && yarn link @checkly/pulumi && cd -
cp README.md sdk/nodejs/README.md