Skip to content

Commit 976f010

Browse files
authored
feat: Adds a prepare target to makefile (#95)
* feat: Adds a prepare target to makefile Adds a prepare target to makefile to globally replace instances of `xyz` and `abc`. This should make it easier for users to get started. This is similar to what is done in pulumi-tf-provider-boilerplate. It skips the sdk and examples directory to illustrate what needs to be changed initially. * fix: Make prepare now skips lines containing SED_SKIP Add the ability for make prepare to skip certain lines where we don't want to replace values. We use 'abc' and 'xyz' in our provider/provider.go file in our random number function. We do not actually want to do that. * remove ./examples from the exceptions because the yaml file actually needs the replace
1 parent f04eef4 commit 976f010

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

Makefile

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ PROJECT_NAME := Pulumi Xyz Resource Provider
33
PACK := xyz
44
PACKDIR := sdk
55
PROJECT := github.com/pulumi/pulumi-xyz
6-
NODE_MODULE_NAME := @pulumi/xyz
7-
NUGET_PKG_NAME := Pulumi.Xyz
6+
NODE_MODULE_NAME := @abc/xyz
7+
NUGET_PKG_NAME := Abc.Xyz
88

99
PROVIDER := pulumi-resource-${PACK}
1010
VERSION ?= $(shell pulumictl get version)
@@ -17,6 +17,29 @@ WORKING_DIR := $(shell pwd)
1717
EXAMPLES_DIR := ${WORKING_DIR}/examples/yaml
1818
TESTPARALLELISM := 4
1919

20+
OS := $(shell uname)
21+
22+
prepare::
23+
@if test -z "${NAME}"; then echo "NAME not set"; exit 1; fi
24+
@if test -z "${REPOSITORY}"; then echo "REPOSITORY not set"; exit 1; fi
25+
@if test -z "${ORG}"; then echo "ORG not set"; exit 1; fi
26+
@if test ! -d "provider/cmd/pulumi-resource-xyz"; then "Project already prepared"; exit 1; fi # SED_SKIP
27+
28+
mv "provider/cmd/pulumi-resource-xyz" provider/cmd/pulumi-resource-${NAME} # SED_SKIP
29+
30+
if [[ "${OS}" != "Darwin" ]]; then \
31+
find . \( -path './.git' -o -path './sdk' \) -prune -o -not -name 'go.sum' -type f -exec sed -i '/SED_SKIP/!s,github.com/pulumi/pulumi-[x]yz,${REPOSITORY},g' {} \; &> /dev/null; \
32+
find . \( -path './.git' -o -path './sdk' \) -prune -o -not -name 'go.sum' -type f -exec sed -i '/SED_SKIP/!s/[xX]yz/${NAME}/g' {} \; &> /dev/null; \
33+
find . \( -path './.git' -o -path './sdk' \) -prune -o -not -name 'go.sum' -type f -exec sed -i '/SED_SKIP/!s/[aA]bc/${ORG}/g' {} \; &> /dev/null; \
34+
fi
35+
36+
# In MacOS the -i parameter needs an empty string to execute in place.
37+
if [[ "${OS}" == "Darwin" ]]; then \
38+
find . \( -path './.git' -o -path './sdk' \) -prune -o -not -name 'go.sum' -type f -exec sed -i '' '/SED_SKIP/!s,github.com/pulumi/pulumi-[x]yz,${REPOSITORY},g' {} \; &> /dev/null; \
39+
find . \( -path './.git' -o -path './sdk' \) -prune -o -not -name 'go.sum' -type f -exec sed -i '' '/SED_SKIP/!s/[xX]yz/${NAME}/g' {} \; &> /dev/null; \
40+
find . \( -path './.git' -o -path './sdk' \) -prune -o -not -name 'go.sum' -type f -exec sed -i '' '/SED_SKIP/!s/[aA]bc/${ORG}/g' {} \; &> /dev/null; \
41+
fi
42+
2043
ensure::
2144
cd provider && go mod tidy
2245
cd sdk && go mod tidy

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,18 @@ Pulumi offers this repository as a [GitHub template repository](https://docs.git
4646

4747
From the templated repository:
4848

49-
1. Search-replace `xyz` with the name of your desired provider.
49+
1. Run the following command to update files to use the name of your provider (third-party: use your GitHub organization/username):
50+
51+
```bash
52+
make prepare NAME=foo REPOSITORY=github.com/pulumi/pulumi-foo ORG=myorg
53+
```
54+
55+
This will do the following:
56+
- rename folders in `provider/cmd` to `pulumi-resource-{NAME}`
57+
- replace dependencies in `provider/go.mod` to reflect your repository name
58+
- find and replace all instances of the boilerplate `xyz` with the `NAME` of your provider.
59+
- find and replace all instances of the boilerplate `abc` with the `ORG` of your provider.
60+
- replace all instances of the `github.com/pulumi/pulumi-xyz` repository with the `REPOSITORY` location
5061

5162
#### Build the provider and install the plugin
5263

provider/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (Random) Create(ctx p.Context, name string, input RandomArgs, preview bool)
8181

8282
func makeRandom(length int) string {
8383
seededRand := rand.New(rand.NewSource(time.Now().UnixNano()))
84-
charset := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
84+
charset := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") // SED_SKIP
8585

8686
result := make([]rune, length)
8787
for i := range result {

0 commit comments

Comments
 (0)