From f1bb7a7ddde14f43a75bdfeed2c3d4c308036737 Mon Sep 17 00:00:00 2001 From: David Flanagan Date: Wed, 10 May 2023 22:00:25 +0100 Subject: [PATCH 1/2] fix: support tags with build info When briding a Terraform provider, it makes a lot of sense to match the Terraform provider version in the Pulumi provider. However, there needs to be a clean way to increment this build while keeping the Terraform version static, without abusing prerelease tags. This is supported by build metadata: https://semver.org/spec/v2.0.0.html --- pkg/gitversion/gitversion.go | 17 +++++++++++++++-- pkg/gitversion/gitversion_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/pkg/gitversion/gitversion.go b/pkg/gitversion/gitversion.go index dda5066..53e0b64 100644 --- a/pkg/gitversion/gitversion.go +++ b/pkg/gitversion/gitversion.go @@ -56,6 +56,8 @@ func GetLanguageVersionsWithOptions(opts LanguageVersionsOptions) (*LanguageVers genericVersion.Major = versionComponents.Semver.Major genericVersion.Minor = versionComponents.Semver.Minor genericVersion.Patch = versionComponents.Semver.Patch + genericVersion.Build = versionComponents.Semver.Build + if len(versionComponents.Semver.Pre) == 1 { genericVersion.Pre = []semver.PRVersion{ versionComponents.Semver.Pre[0], @@ -130,12 +132,23 @@ func GetLanguageVersionsWithOptions(opts LanguageVersionsOptions) (*LanguageVers preVersion = fmt.Sprintf("%s%sdirty", preVersion, separator) } + buildVersion := []byte{} + if len(genericVersion.Build) > 0 { + buildVersion = append(buildVersion, '+') + buildVersion = append(buildVersion, genericVersion.Build[0]...) + + for _, build := range genericVersion.Build[1:] { + buildVersion = append(buildVersion, '.') + buildVersion = append(buildVersion, build...) + } + } + // a base version with the pre release info baseVersion := fmt.Sprintf("%d.%d.%d", genericVersion.Major, genericVersion.Minor, genericVersion.Patch) // calculate versions for all languages - version := fmt.Sprintf("%s%s", baseVersion, preVersion) - pythonVersion := fmt.Sprintf("%s%s", baseVersion, pythonPreVersion) + version := fmt.Sprintf("%s%s%s", baseVersion, preVersion, buildVersion) + pythonVersion := fmt.Sprintf("%s%s%s", baseVersion, pythonPreVersion, buildVersion) jsVersion := fmt.Sprintf("v%s", version) dotnetVersion := version diff --git a/pkg/gitversion/gitversion_test.go b/pkg/gitversion/gitversion_test.go index d9302c8..2913a9c 100644 --- a/pkg/gitversion/gitversion_test.go +++ b/pkg/gitversion/gitversion_test.go @@ -508,4 +508,28 @@ func TestGetVersion(t *testing.T) { require.Equal(t, "v1.0.0-alpha.1", version.JavaScript) require.Equal(t, "1.0.0a1", version.Python) }) + + t.Run("Repo with build info tag", func(t *testing.T) { + repo, err := testRepoCreate() + require.NoError(t, err) + + tagSequence := []string{ + "v1.0.0+1", + } + + repo, err = testRepoWithTags(repo, tagSequence) + require.NoError(t, err) + + opts := LanguageVersionsOptions{ + Repo: repo, + Commitish: plumbing.Revision("HEAD"), + } + version, err := GetLanguageVersionsWithOptions(opts) + require.NoError(t, err) + + require.Equal(t, "1.0.0+1", version.SemVer) + require.Equal(t, "1.0.0+1", version.DotNet) + require.Equal(t, "v1.0.0+1", version.JavaScript) + require.Equal(t, "1.0.0+1", version.Python) + }) } From f265ebc5f8498ff62d05946bea7a918b4a23f886 Mon Sep 17 00:00:00 2001 From: David Flanagan Date: Thu, 11 May 2023 20:41:02 +0100 Subject: [PATCH 2/2] chore: expand test case for complex build info --- pkg/gitversion/gitversion_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkg/gitversion/gitversion_test.go b/pkg/gitversion/gitversion_test.go index 2913a9c..7c0aba3 100644 --- a/pkg/gitversion/gitversion_test.go +++ b/pkg/gitversion/gitversion_test.go @@ -532,4 +532,28 @@ func TestGetVersion(t *testing.T) { require.Equal(t, "v1.0.0+1", version.JavaScript) require.Equal(t, "1.0.0+1", version.Python) }) + + t.Run("Repo with complicated build info tag", func(t *testing.T) { + repo, err := testRepoCreate() + require.NoError(t, err) + + tagSequence := []string{ + "v1.0.0+1abc.345.whoop", + } + + repo, err = testRepoWithTags(repo, tagSequence) + require.NoError(t, err) + + opts := LanguageVersionsOptions{ + Repo: repo, + Commitish: plumbing.Revision("HEAD"), + } + version, err := GetLanguageVersionsWithOptions(opts) + require.NoError(t, err) + + require.Equal(t, "1.0.0+1abc.345.whoop", version.SemVer) + require.Equal(t, "1.0.0+1abc.345.whoop", version.DotNet) + require.Equal(t, "v1.0.0+1abc.345.whoop", version.JavaScript) + require.Equal(t, "1.0.0+1abc.345.whoop", version.Python) + }) }