Skip to content

Commit

Permalink
feat: Adds a prepare target to makefile
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zbuchheit committed May 9, 2024
1 parent f04eef4 commit d3e1c8e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
28 changes: 26 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ PROJECT_NAME := Pulumi Xyz Resource Provider
PACK := xyz
PACKDIR := sdk
PROJECT := github.com/pulumi/pulumi-xyz
NODE_MODULE_NAME := @pulumi/xyz
NUGET_PKG_NAME := Pulumi.Xyz
NODE_MODULE_NAME := @abc/xyz
NUGET_PKG_NAME := Abc.Xyz

PROVIDER := pulumi-resource-${PACK}
VERSION ?= $(shell pulumictl get version)
Expand All @@ -17,6 +17,30 @@ WORKING_DIR := $(shell pwd)
EXAMPLES_DIR := ${WORKING_DIR}/examples/yaml
TESTPARALLELISM := 4

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 -z "${ORG}"; then echo "ORG not set"; exit 1; fi
@if test ! -d "provider/cmd/pulumi-resource-x${EMPTY_TO_AVOID_SED}yz"; then "Project already prepared"; exit 1; fi

mv "provider/cmd/pulumi-resource-x${EMPTY_TO_AVOID_SED}yz" provider/cmd/pulumi-resource-${NAME}

if [[ "${OS}" != "Darwin" ]]; then \
find . \( -path './.git' -o -path './sdk' -o -path './examples' \) -prune -o -not -name 'go.sum' -type f -exec sed -i 's,github.com/pulumi/pulumi-[x]yz,${REPOSITORY},g' {} \; &> /dev/null; \
find . \( -path './.git' -o -path './sdk' -o -path './examples' \) -prune -o -not -name 'go.sum' -type f -exec sed -i 's/[xX]yz/${NAME}/g' {} \; &> /dev/null; \
find . \( -path './.git' -o -path './sdk' -o -path './examples' \) -prune -o -not -name 'go.sum' -type f -exec sed -i 's/[aA]bc/${ORG}/g' {} \; &> /dev/null; \
fi

# In MacOS the -i parameter needs an empty string to execute in place.
if [[ "${OS}" == "Darwin" ]]; then \
find . \( -path './.git' -o -path './sdk' -o -path './examples' \) -prune -o -not -name 'go.sum' -type f -exec sed -i '' 's,github.com/pulumi/pulumi-[x]yz,${REPOSITORY},g' {} \; &> /dev/null; \
find . \( -path './.git' -o -path './sdk' -o -path './examples' \) -prune -o -not -name 'go.sum' -type f -exec sed -i '' 's/[xX]yz/${NAME}/g' {} \; &> /dev/null; \
find . \( -path './.git' -o -path './sdk' -o -path './examples' \) -prune -o -not -name 'go.sum' -type f -exec sed -i '' 's/[aA]bc/${ORG}/g' {} \; &> /dev/null; \
fi

ensure::
cd provider && go mod tidy
cd sdk && go mod tidy
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,18 @@ Pulumi offers this repository as a [GitHub template repository](https://docs.git

From the templated repository:

1. Search-replace `xyz` with the name of your desired provider.
1. Run the following command to update files to use the name of your provider (third-party: use your GitHub organization/username):

```bash
make prepare NAME=foo REPOSITORY=github.com/pulumi/pulumi-foo ORG=myorg
```

This will do the following:
- rename folders in `provider/cmd` to `pulumi-resource-{NAME}`
- replace dependencies in `provider/go.mod` to reflect your repository name
- find and replace all instances of the boilerplate `xyz` with the `NAME` of your provider.
- find and replace all instances of the boilerplate `abc` with the `ORG` of your provider.
- replace all instances of the `github.com/pulumi/pulumi-xyz` repository with the `REPOSITORY` location

#### Build the provider and install the plugin

Expand Down

0 comments on commit d3e1c8e

Please sign in to comment.