Emit schema.Package.Version when possible (#7938)

* Emit schema.Package.Version when possible

* Update CHANGELOG_PENDING.md

* Correctly interpret python versions (I hope)

* Update PLUGIN_VERSION to the package version

* Modify tests to conform with master merge
This commit is contained in:
Ian Wahbe 2021-09-17 23:11:54 -07:00 committed by GitHub
parent df50c4492e
commit 906dce73a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
58 changed files with 176 additions and 58 deletions

View file

@ -9,6 +9,9 @@
- [sdk/go] - Add `RegisterInputType` and register built-in types.
[#7928](https://github.com/pulumi/pulumi/pull/7928)
- [codegen] - Packages include `Package.Version` when provided.
[#7938](https://github.com/pulumi/pulumi/pull/7938)
### Bug Fixes
- [codegen/schema] - Correct validation for Package

View file

@ -1979,6 +1979,13 @@ func genPackageMetadata(pkg *schema.Package, assemblyName string, packageReferen
files.add(assemblyName+".csproj", projectFile)
files.add("logo.png", logo)
// Generate version.txt
versionFile := "version.txt"
if _, exists := files[versionFile]; !exists && pkg.Version != nil {
files[versionFile] = []byte(pkg.Version.String())
}
return nil
}
@ -2229,8 +2236,8 @@ func GeneratePackage(tool string, pkg *schema.Package, extraFiles map[string][]b
files := fs{}
for p, f := range extraFiles {
files.add(p, f)
}
for _, mod := range modules {
if err := mod.gen(files); err != nil {
return nil, err

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/foo-bar",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/example",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/example",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/foo-bar",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/foo",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -338,5 +338,7 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
pgregory.net/rapid v0.4.7 h1:MTNRktPuv5FNqOO151TM9mDTa+XHcX6ypYeISDVD14g=
pgregory.net/rapid v0.4.7/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0 h1:ucqkfpjg9WzSUubAO62csmucvxl4/JeW3F4I4909XkM=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/xyz",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/configstation",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/example",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/example",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/example",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/plant",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/example",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/example",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/example",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/example",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/example",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -0,0 +1 @@
0.0.1

View file

@ -1,6 +1,6 @@
{
"name": "@pulumi/example",
"version": "${VERSION}",
"version": "0.0.1",
"scripts": {
"build": "tsc"
},

View file

@ -8,8 +8,8 @@ from setuptools.command.install import install
from subprocess import check_call
VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"
VERSION = "0.0.1"
PLUGIN_VERSION = "0.0.1"
class InstallPluginCommand(install):
def run(self):

View file

@ -1791,10 +1791,15 @@ func genNPMPackageMetadata(pkg *schema.Package, info NodePackageInfo) string {
devDependencies["typescript"] = "^4.3.5"
}
packageVersion := "${VERSION}"
if pkg.Version != nil {
packageVersion = pkg.Version.String()
}
// Create info that will get serialized into an NPM package.json.
npminfo := npmPackage{
Name: packageName,
Version: "${VERSION}",
Version: packageVersion,
Description: info.PackageDescription,
Keywords: pkg.Keywords,
Homepage: pkg.Homepage,

View file

@ -1896,9 +1896,20 @@ func genPackageMetadata(
fmt.Fprintf(w, "from subprocess import check_call\n")
fmt.Fprintf(w, "\n\n")
// Create a constant for the version number to replace during build
fmt.Fprintf(w, "VERSION = \"0.0.0\"\n")
fmt.Fprintf(w, "PLUGIN_VERSION = \"0.0.0\"\n\n")
// If `pkg` supplies a version, use that. Otherwise, create a constant for
// the version number to replace during build.
packageVersion := "0.0.0"
if pkg.Version != nil {
packageVersion = pythonVersion(pkg.Version)
}
pluginVersion := "0.0.0"
if pkg.Version != nil {
// This happens in test builds
pluginVersion = pkg.Version.String()
}
fmt.Fprintf(w, "VERSION = %q\n", packageVersion)
fmt.Fprintf(w, "PLUGIN_VERSION = %q\n\n", pluginVersion)
// Create a command that will install the Pulumi plugin for this resource provider.
fmt.Fprintf(w, "class InstallPluginCommand(install):\n")

View file

@ -1,12 +1,30 @@
// Copyright 2016-2021, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package python
import (
"github.com/pkg/errors"
"github.com/pulumi/pulumi/pkg/v3/codegen"
"fmt"
"io"
"regexp"
"strings"
"unicode"
"github.com/blang/semver"
"github.com/pkg/errors"
"github.com/pulumi/pulumi/pkg/v3/codegen"
)
// isLegalIdentifierStart returns true if it is legal for c to be the first character of a Python identifier as per
@ -87,3 +105,21 @@ func makeSafeEnumName(name, typeName string) (string, error) {
return safeName, nil
}
func pythonVersion(ver *semver.Version) string {
pythonPreVersion := ""
if len(ver.Pre) > 0 {
switch ver.Pre[0].VersionStr {
case "dev":
pythonPreVersion = "dev"
case "alpha":
pythonPreVersion = "a"
case "beta":
pythonPreVersion = "b"
case "rc":
pythonPreVersion = "rc"
}
}
baseVersion := fmt.Sprintf("%d.%d.%d", ver.Major, ver.Minor, ver.Patch)
return fmt.Sprintf("%s%s", baseVersion, pythonPreVersion)
}

View file

@ -1,10 +1,26 @@
// Copyright 2016-2021, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package python
import (
"strings"
"testing"
"github.com/blang/semver"
"github.com/hashicorp/hcl/v2"
"github.com/pulumi/pulumi/pkg/v3/codegen/hcl2"
"github.com/pulumi/pulumi/pkg/v3/codegen/hcl2/syntax"
"github.com/pulumi/pulumi/pkg/v3/codegen/internal/utils"
@ -65,3 +81,24 @@ func TestMakeSafeEnumName(t *testing.T) {
})
}
}
func TestVersionConversion(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"0.0.1", "0.0.1"},
{"0.0.1-alpha", "0.0.1a"},
{"2.3.4-dev", "2.3.4dev"},
{"2.3.4-beta", "2.3.4b"},
{"2.3.4-rc", "2.3.4rc"},
{"3.13.0-alpha.1631222709+d49fd02f.dirty", "3.13.0a"},
}
for _, tt := range tests {
ver := semver.MustParse(tt.input)
got := pythonVersion(&ver)
if got != tt.expected {
t.Errorf("Unexpected version number: got = %q, want %q", got, tt.expected)
}
}
}