Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pulumi package with subcommands gen-sdk and get-schema #10711

Merged
merged 10 commits into from Sep 17, 2022

Conversation

iwahbe
Copy link
Member

@iwahbe iwahbe commented Sep 14, 2022

Description

Fixes #10693

This PR adds two commands that are vital to developing Pulumi packages without intermediary artifact and boilerplate.

  • gen-sdk: Takes either a package name, plugin path, or schema file and generates the associated SDK.
  • get-schema: Takes the same input as gen-sdk. It prints the schema out to stdout.

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

@iwahbe iwahbe self-assigned this Sep 14, 2022
@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@pulumi-bot
Copy link
Contributor

pulumi-bot commented Sep 14, 2022

Changelog

[uncommitted] (2022-09-15)

Features

  • [cli] Add a package author focused subcommand: pulumi package with subcommands pulumi package gen-sdk and pulumi package get-schema.
    #10711

@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

pkg/cmd/pulumi/package.go Outdated Show resolved Hide resolved

func newExtractSchemaCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "get-schema <schema_source>",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't there a proposal to offer CLI commands for invoking other plugin gRPC methods? If we're considering that, where would this command fit-in? cc: @Frassle

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That proposal, AFAIK, was to directly call the provider commands, and print the output. This command (while very similar) does a little more than that. It verifies the schema is valid, round tripping it through our parsed representation, then formatting the output.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with Ian, those commands are more intended for provider debugging, not for general user usage and while we would probably have a get-schema command under there as well for completeness it would just be a raw echo of the string sent back over grpc.

func genSDK(language, out string, pkg *schema.Package) error {
var f func(string, *schema.Package, map[string][]byte) (map[string][]byte, error)
switch language {
case "csharp", "c#", "dotnet":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we accepting these additional names like "csharp" and "c#"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a set of names for the folders we generate our SDKs into (nodejs, dotnet, python go, java) and a set of names we accept for pulumi convert (csharp, c#, go typescript, python, java). I'm accepting the union to avoid being confusing, but we will only emit our standard folders (dotnet correction, nodejs correction).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason I asked is because we'll have to accommodate these various names when trying to select the right plugin when we move to a plugin model.

But if we're already doing it in pulumi convert, we'll have to be able to support these additional "aliases" there anyway, so no concern doing it here as well.


func genSDK(language, out string, pkg *schema.Package) error {
var f func(string, *schema.Package, map[string][]byte) (map[string][]byte, error)
switch language {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this functionality should live in the language plugins. Then we wouldn't need to hard code this switch, we'd just load up the requested language plugin and call it over gRPC to do the SDK codegen, similar in spirit to #9294. The benefit being that if we add more languages in the future, we wouldn't necessarily have to touch this code again.

Not sure what that means for all, though, other than enumerating all available language plugins and invoking the appropriate gRPC method for each one.

Though, I can also understand possible pushback to this suggestion: that the codegen functionality doesn't really belong in the language plugins because their purpose (right now) is only about running Pulumi programs in the given language -- not about codegen. If others share this concern, we could consider another kind of plugin, maybe "codegen" (e.g. pulumi-codegen-nodejs, pulumi-codegen-python, etc.) that would be exclusively meant to handle codegen tasks (perhaps both sdkgen and programgen).

Of course, we could always hard code in a switch for now for expediency, and move to language plugin in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codegen can and should be pluginafied, but that is out of scope of this PR. Were hardcoding for now, but that is not the desired end goal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this functionality should live in the language plugins.

It should! We have discussed this multiple times, we will do this but it's probably tricky so keeps being put off.

var language string
var out string
cmd := &cobra.Command{
Use: "gen-sdk <schema_source>",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gen-sdk is probably the best verb I do wonder, though, if there are any other names we should consider like just generate or gen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered generate, but it wasn't clear what was being generated (sdk, schema, binary, ...). I'm open to other suggestions though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generate-sdk? I'd rather be clear here it's not like this is a command where terseness is really needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with gen-sdk. Looking over existing commands, we already have gen-markdown and gen-completion so there is precedent with just gen- (though, these are hidden).

@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@iwahbe
Copy link
Member Author

iwahbe commented Sep 15, 2022

I'm adding a no-changelog tag because the current CI system doesn't recognize the new changelog system.

@iwahbe iwahbe added the impact/no-changelog-required This issue doesn't require a CHANGELOG update label Sep 15, 2022
@iwahbe iwahbe mentioned this pull request Sep 15, 2022
3 tasks
Copy link
Member

@justinvp justinvp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@iwahbe
Copy link
Member Author

iwahbe commented Sep 16, 2022

bors r+

bors bot added a commit that referenced this pull request Sep 16, 2022
10711: Add `pulumi package` with subcommands `gen-sdk` and `get-schema` r=iwahbe a=iwahbe

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Fixes #10693 

This PR adds two commands that are vital to developing Pulumi packages without intermediary artifact and boilerplate. 
- `gen-sdk`: Takes either a package name, plugin path, or schema file and generates the associated SDK.
- `get-schema`: Takes the same input as `gen-sdk`. It prints the schema out to stdout.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have updated the [CHANGELOG-PENDING](https://github.com/pulumi/pulumi/blob/master/CHANGELOG_PENDING.md) file with my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


10763: ci: Fix make brew r=AaronFriel a=AaronFriel

This enables `make brew` to run as before, accounting for directory changes. The prep-for-goreleaser script places artifacts in `./bin/` now.

`make brew` now succeeds.

Fixes #10735 

10767: [yaml] Update Pulumi YAML to 0.5.7 r=AaronFriel a=AaronFriel



Co-authored-by: Ian Wahbe <ian@wahbe.com>
Co-authored-by: Aaron Friel <mayreply@aaronfriel.com>
@bors
Copy link
Contributor

bors bot commented Sep 16, 2022

Build failed (retrying...):

bors bot added a commit that referenced this pull request Sep 16, 2022
10711: Add `pulumi package` with subcommands `gen-sdk` and `get-schema` r=iwahbe a=iwahbe

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Fixes #10693 

This PR adds two commands that are vital to developing Pulumi packages without intermediary artifact and boilerplate. 
- `gen-sdk`: Takes either a package name, plugin path, or schema file and generates the associated SDK.
- `get-schema`: Takes the same input as `gen-sdk`. It prints the schema out to stdout.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have updated the [CHANGELOG-PENDING](https://github.com/pulumi/pulumi/blob/master/CHANGELOG_PENDING.md) file with my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


10772: Freeze `3.40.1` draft release. r=dixler a=dixler

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

Bumping `.version` freezes the draft release.

Fixes # (issue)

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Ian Wahbe <ian@wahbe.com>
Co-authored-by: Kyle Dixler <kyle@pulumi.com>
@bors
Copy link
Contributor

bors bot commented Sep 16, 2022

Build failed (retrying...):

@bors
Copy link
Contributor

bors bot commented Sep 17, 2022

Build succeeded:

@bors bors bot merged commit 23212c9 into master Sep 17, 2022
@bors bors bot deleted the iwahbe/10693/expose-sdkgen-from-cli branch September 17, 2022 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/no-changelog-required This issue doesn't require a CHANGELOG update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add pulumi schema gen-sdk
4 participants