Skip to content

Commit

Permalink
Add docs gen Makefile target for hybrid providers (#321)
Browse files Browse the repository at this point in the history
* Add logic to add a `docs` Makefile target

This addition supports Makefile changes introduced to pulumi-docker
in pulumi/pulumi-docker#479.

* generalize approach to denote a hybrid provider rather than docekr specifically

* Generate all providers. Updates major version for Fastly but does not add any extra targets to non-hybrid providers, as expected.
  • Loading branch information
guineveresaenger authored Feb 3, 2023
1 parent b9051b3 commit aa64da2
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 30 deletions.
2 changes: 2 additions & 0 deletions provider-ci/providers/docker/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ env:
PULUMI_GO_DEP_ROOT: /home/runner/work/pulumi-docker
upstream-provider-org: kreuzwerker
makeTemplate: bridged
docsCmd: "cd provider/pkg/docs-gen/examples/ && go run generate.go ./yaml ./"
hybrid: true
7 changes: 5 additions & 2 deletions provider-ci/providers/docker/repo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ cleanup:
rm -r $(WORKING_DIR)/bin
rm -f provider/cmd/$(PROVIDER)/schema.go

docs:
cd provider/pkg/docs-gen/examples/ && go run generate.go ./yaml ./

help:
@grep '^[^.#]\+:\s\+.*#' Makefile | \
sed "s/\(.\+\):\s*\(.*\) #\s*\(.*\)/`printf "\033[93m"`\1`printf "\033[0m"` \3 [\2]/" | \
Expand All @@ -102,12 +105,12 @@ provider: tfgen install_plugins
test:
cd examples && go test -v -tags=all -parallel $(TESTPARALLELISM) -timeout 2h

tfgen: install_plugins
tfgen: install_plugins docs
(cd provider && go build -p 1 -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)

bin/pulumi-java-gen:
$(shell pulumictl download-binary -n pulumi-language-java -v $(JAVA_GEN_VERSION) -r pulumi/pulumi-java)

.PHONY: development build build_sdks install_go_sdk install_java_sdk install_python_sdk install_sdks only_build build_dotnet build_go build_java build_nodejs build_python clean cleanup help install_dotnet_sdk install_nodejs_sdk install_plugins lint_provider provider test tfgen
.PHONY: development build build_sdks install_go_sdk install_java_sdk install_python_sdk install_sdks only_build build_dotnet build_go build_java build_nodejs build_python clean cleanup docs help install_dotnet_sdk install_nodejs_sdk install_plugins lint_provider provider test tfgen
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ builds:
- linux
ignore: []
ldflags:
- -X github.com/pulumi/pulumi-fastly/provider/v5/pkg/version.Version={{.Tag}}
- -X github.com/pulumi/pulumi-fastly/provider/v6/pkg/version.Version={{.Tag}}
main: ./cmd/pulumi-resource-fastly/
changelog:
skip: true
Expand Down
2 changes: 1 addition & 1 deletion provider-ci/providers/fastly/repo/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ builds:
- linux
ignore: []
ldflags:
- -X github.com/pulumi/pulumi-fastly/provider/v5/pkg/version.Version={{.Tag}}
- -X github.com/pulumi/pulumi-fastly/provider/v6/pkg/version.Version={{.Tag}}
main: ./cmd/pulumi-resource-fastly/
changelog:
filters:
Expand Down
2 changes: 1 addition & 1 deletion provider-ci/providers/fastly/repo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PACK := fastly
ORG := pulumi
PROJECT := github.com/$(ORG)/pulumi-$(PACK)
PROVIDER_PATH := provider/v5
PROVIDER_PATH := provider/v6
VERSION_PATH := $(PROVIDER_PATH)/pkg/version.Version
TFGEN := pulumi-tfgen-$(PACK)
PROVIDER := pulumi-resource-$(PACK)
Expand Down
2 changes: 2 additions & 0 deletions provider-ci/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const BridgedConfig = z
plugins: z
.array(z.object({ name: z.string(), version: z.string() }))
.optional(),
docsCmd: z.string().default(""),
hybrid: z.boolean().default(false)
})
.transform((input) => {
if (input["upstream-provider-repo"] !== "") {
Expand Down
71 changes: 46 additions & 25 deletions provider-ci/src/make-bridged-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export function bridgedProvider(config: BridgedConfig): Makefile {
WORKING_DIR,
} as const;


const docs: Target = {
name: "docs",
phony: true,
commands: [config.docsCmd]
}

const install_plugins: Target = {
name: "install_plugins",
phony: true,
Expand All @@ -43,6 +50,7 @@ export function bridgedProvider(config: BridgedConfig): Makefile {
) ?? []),
],
};

const tfgen: Target = {
name: "tfgen",
phony: true,
Expand All @@ -53,6 +61,11 @@ export function bridgedProvider(config: BridgedConfig): Makefile {
"(cd provider && VERSION=$(VERSION) go generate cmd/$(PROVIDER)/main.go)",
],
};

if (config.provider == "docker" ) {
tfgen.dependencies = [install_plugins, docs]
}

const ldFlagStatements = ["-X $(PROJECT)/$(VERSION_PATH)=$(VERSION)"];
if (config.providerVersion) {
ldFlagStatements.push(`-X ${config.providerVersion}=$(VERSION)`);
Expand Down Expand Up @@ -248,33 +261,41 @@ export function bridgedProvider(config: BridgedConfig): Makefile {
"cd examples && go test -v -tags=all -parallel $(TESTPARALLELISM) -timeout 2h",
],
};

const returnTargets = [
build,
only_build,
tfgen,
provider,
build_sdks,
build_nodejs,
build_python,
build_go,
build_dotnet,
build_java,
bin_pulumi_java_gen,
lint_provider,
cleanup,
help,
clean,
install_plugins,
install_dotnet_sdk,
install_python_sdk,
install_go_sdk,
install_java_sdk,
install_nodejs_sdk,
install_sdks,
test,
]


if (config.hybrid) {
returnTargets.push(docs)
}

return {
variables,
defaultTarget: development,
targets: [
build,
only_build,
tfgen,
provider,
build_sdks,
build_nodejs,
build_python,
build_go,
build_dotnet,
build_java,
bin_pulumi_java_gen,
lint_provider,
cleanup,
help,
clean,
install_plugins,
install_dotnet_sdk,
install_python_sdk,
install_go_sdk,
install_java_sdk,
install_nodejs_sdk,
install_sdks,
test,
],
targets: returnTargets,
};
}

0 comments on commit aa64da2

Please sign in to comment.