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

Emit schema.Package.Version when possible #7938

Merged
merged 7 commits into from
Sep 18, 2021

Conversation

iwahbe
Copy link
Member

@iwahbe iwahbe commented Sep 9, 2021

Description

We currently offload adding the Package.Version information to makefiles in our SDKs. This means that package information which is specified in a schema.json is ignored in favor of another process. This PR has version information emitted if and only if Package.Version is supplied. This means

  • version.txt for dotnet
  • setup.py accurately contains a version for python
  • package.json accurately reports it's version for nodejs.

If Package.Version is not supplied, no behavior is changed.

This has 2 major motivations:

  1. Using the schema version field should populate to the project as expected. Having the version set to "0.0.0" is not expected behavior.
  2. We should attempt to emit valid SDKs when possible. Running dotnet build requires version.txt to exist. This prevents special cases from developing SDKs and testing our SDK codegen.

Pending Questions

  • How to handle the distinction python makes between VERSION and PLUGIN_VERSION

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
  • Decide if we should use npm or yarn for testing (discussed for Codegen testing upgrades #7989).

@iwahbe iwahbe self-assigned this Sep 9, 2021
@iwahbe iwahbe marked this pull request as draft September 9, 2021 21:22
@iwahbe iwahbe added the area/codegen SDK-gen, program-gen, convert label Sep 9, 2021
@github-actions
Copy link

github-actions bot commented Sep 9, 2021

Diff for pulumi-random with merge commit 5fe49eb

@github-actions
Copy link

github-actions bot commented Sep 9, 2021

Diff for pulumi-azuread with merge commit 5fe49eb

@github-actions
Copy link

github-actions bot commented Sep 9, 2021

Diff for pulumi-kubernetes with merge commit 5fe49eb

@github-actions
Copy link

github-actions bot commented Sep 9, 2021

Diff for pulumi-random with merge commit b316eca

@github-actions
Copy link

github-actions bot commented Sep 9, 2021

Diff for pulumi-azuread with merge commit b316eca

@github-actions
Copy link

github-actions bot commented Sep 9, 2021

Diff for pulumi-kubernetes with merge commit b316eca

@github-actions
Copy link

github-actions bot commented Sep 9, 2021

Diff for pulumi-gcp with merge commit 5fe49eb

@github-actions
Copy link

github-actions bot commented Sep 9, 2021

Diff for pulumi-aws with merge commit 5fe49eb

@github-actions
Copy link

github-actions bot commented Sep 9, 2021

Diff for pulumi-gcp with merge commit b316eca

@github-actions
Copy link

github-actions bot commented Sep 9, 2021

Diff for pulumi-aws with merge commit b316eca

@github-actions
Copy link

github-actions bot commented Sep 9, 2021

Diff for pulumi-azure with merge commit 5fe49eb

@github-actions
Copy link

github-actions bot commented Sep 9, 2021

Diff for pulumi-azure with merge commit b316eca

@iwahbe iwahbe marked this pull request as ready for review September 10, 2021 16:31
pkg/codegen/dotnet/gen.go Show resolved Hide resolved
Comment on lines 1906 to 1908
// TODO: puipyVersion is the pythonic version of pkgVersion. The code to
// transform it is in pulumi/pulumictl. Should that be extracted to
// somewhere like pulumi/pulumi/sdk/python.go?
Copy link
Member

Choose a reason for hiding this comment

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

Yes, it does seem like we should extract that code and put it somewhere common. Not sure if pulumi/pulumi/sdk is the right place for that, but I also don't have a better suggestion offhand :) @komalali @t0yv0 ?

Copy link
Member

Choose a reason for hiding this comment

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

No strong opinions.. looks like pulumictl depends on pkg https://github.com/pulumi/pulumictl/blob/master/go.mod#L11 so if the least common ancestor is pkg we can put it there; alternatively factor into its own little dedicated GH repo and package. The barriers to that are pleasantly low. If it's really small then "a little dulication is better than a little dependency" applies here too so we can inline a copy.

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 just duplicated the code.
Taking a closer look, most of the code dealt with the current git tree being dirty, and generating a semver version. Since we are provided a semver version already, I just help with the pythonic parts. It's not long. I located it in pulumi/pkg/codegen/python/utilities.go.

@t0yv0
Copy link
Member

t0yv0 commented Sep 13, 2021

SO I dug around how these versions are used and filed #7955 with questions. The fact Python (and Node?) auto-install Go plugins binaries in their setup.py strikes me as a bit of an unfortunate choice.

Presumably this is the distinction:

How to handle the distinction python makes between VERSION and PLUGIN_VERSION

The PLUGIN_VERSION determines which Go plugin to auto-install.

@t0yv0 t0yv0 self-requested a review September 13, 2021 14:53
@t0yv0
Copy link
Member

t0yv0 commented Sep 13, 2021

I like where this is going since Makefile-based manipulations of VERSION were giving me some headache. Before we ship this it would be good for @mikhailshilkov to make sure this causes no extra problems for provider builds.

@mikhailshilkov
Copy link
Member

The reason we put this version placeholder initially was to avoid version-related diffs on every commit. Has this been mitigated somehow? Adding @stack72 to chime in too.

@iwahbe
Copy link
Member Author

iwahbe commented Sep 13, 2021

The reason we put this version placeholder initially was to avoid version-related diffs on every commit. Has this been mitigated somehow? Adding @stack72 to chime in too.

@mikhailshilkov The mitigation is that if you don't specify version in schema.json, we will still generate a placeholder "version": "${VERSION}" in package.json. This change has no effect unless a version is supplied at generation time.

@mikhailshilkov
Copy link
Member

@iwahbe Thank you for the clarification! Do I understand correctly that this is mostly to clean up the tests but likely won't affect the providers?

@iwahbe
Copy link
Member Author

iwahbe commented Sep 13, 2021

@iwahbe Thank you for the clarification! Do I understand correctly that this is mostly to clean up the tests but likely won't affect the providers?

It is primarily about cleaning up tests and internal consistency. It should also help decrease the amount of makefile necessary for multi-lang.

@infin8x
Copy link
Contributor

infin8x commented Sep 14, 2021

This looks great! We'd talked about doing something similar in #7589 - am I understanding correctly that this PR achieves the "set the version in a single location" part of that issue?

@iwahbe
Copy link
Member Author

iwahbe commented Sep 14, 2021

This looks great! We'd talked about doing something similar in #7589 - am I understanding correctly that this PR achieves the "set the version in a single location" part of that issue?

@infin8x Yes. This has you set the version in the schema, and it propagates it everywhere.

@github-actions
Copy link

Diff for pulumi-kubernetes with merge commit fc7ccce

@github-actions
Copy link

Diff for pulumi-gcp with merge commit fc7ccce

@github-actions
Copy link

Diff for pulumi-aws with merge commit fc7ccce

@github-actions
Copy link

Diff for pulumi-azure with merge commit fc7ccce

@pgavlin
Copy link
Member

pgavlin commented Sep 15, 2021

This doesn't work well for testing, since version.Version changes with each commit. I can think of several solutions, none of which I love.

Note that this is only the case for workflows that do this explicitly by using ldflags to set version.Version. These workflows are likely to be similar to our own gitops-style workflow where the schema version will be unset. It feels like if the schema version is set, then it should align with version.Version and we should be able to emit a real value for PLUGIN_VERSION.

@t0yv0
Copy link
Member

t0yv0 commented Sep 15, 2021

@iwahbe I'm not really super sure, how does our system do it in practice?

I peeked at https://github.com/pulumi/pulumi-aws/blob/master/sdk/python/setup.py#L11 and I see 0.0.0. That seems to work?

Also in my investigation #7955 it turns out that Node JS packages are the other kind of packages that auto-install the plugin, yet they have no PULUMI_VERSION distinction? How do they do it? I can't seem to find the mechanism of how we hook into npm install.

@iwahbe
Copy link
Member Author

iwahbe commented Sep 16, 2021

I peeked at https://github.com/pulumi/pulumi-aws/blob/master/sdk/python/setup.py#L11 and I see 0.0.0. That seems to work?

Taking a look around pulumi-aws I saw what you did, but when ran make build in the aws repo, a setup.py file was generated with VERSION = "4.20.0" and PLUGIN_VERSION = "4.20.0". That gets setup here.

@iwahbe
Copy link
Member Author

iwahbe commented Sep 16, 2021

At this point I'm fairly convinced that the correct behavior (when not testing) is to create a pythonic version of version.Version and stick it in PLUGIN_VERSION. This accommodates our current setup, where we mirror the package version with the pypi release version, only changing it to accommodate the idiosyncrasies of pypi. This is what the current commit does.

When testing, we emit "0.0.0", because we don't want to see diffs on our commit hashes in codegen/internal/tests. Also, version.Version == "" under test.

@iwahbe iwahbe requested a review from pgavlin September 16, 2021 01:34
Comment on lines 1906 to 1910
pluginVersion := "0.0.0"
if version.Version != "" {
// This happens in test builds
pluginVersion = version.Version
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that we want to use version.Version here: "github.com/pulumi/pulumi/pkg/v3/version" is the version of the Pulumi SDK itself, and is unrelated to the schema version. Should this be

Suggested change
pluginVersion := "0.0.0"
if version.Version != "" {
// This happens in test builds
pluginVersion = version.Version
}
pluginVersion := "0.0.0"
if pkg.Version != nil {
pluginVersion = pkg.Version.String()
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Your right. I got the version of the pulumi-resource-* confused with the version of pulumi itself.

@t0yv0 t0yv0 mentioned this pull request Sep 17, 2021
8 tasks
@iwahbe
Copy link
Member Author

iwahbe commented Sep 17, 2021

@t0yv0 I want to make sure the tests pass, then I'll merge.

@github-actions
Copy link

Diff for pulumi-azuread with merge commit b716553

@github-actions
Copy link

Diff for pulumi-aws with merge commit b716553

@github-actions
Copy link

Diff for pulumi-azure with merge commit b716553

@github-actions
Copy link

Diff for pulumi-gcp with merge commit b716553

@github-actions
Copy link

Diff for pulumi-random with merge commit b716553

@github-actions
Copy link

Diff for pulumi-kubernetes with merge commit b716553

@iwahbe iwahbe merged commit 906dce7 into master Sep 18, 2021
@pulumi-bot pulumi-bot deleted the iwahbe/add-version-on-package-generation branch September 18, 2021 06:11
@emiliza emiliza added kind/engineering Work that is not visible to an external user size/S Estimated effort to complete (1-2 days). labels Sep 21, 2021
@emiliza emiliza added this to the 0.62 milestone Sep 21, 2021
iwahbe added a commit that referenced this pull request Sep 23, 2021
iwahbe added a commit that referenced this pull request Sep 23, 2021
* Revert "Emit schema.Package.Version when possible (#7938)"

This reverts commit 906dce7.

* Remove dotnet SDK compile checks

* Add to changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codegen SDK-gen, program-gen, convert kind/engineering Work that is not visible to an external user size/S Estimated effort to complete (1-2 days).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants