From 3dfcde4377f77ebcd40786fad8f9c892b357ff3d Mon Sep 17 00:00:00 2001 From: Mikhail Shilkov Date: Thu, 6 Jun 2024 10:57:30 +0200 Subject: [PATCH] Extend the rule set that matches a package to be a Pulumi package (#1367) # Description Extend the rule set that matches a package to be a first-party Pulumi package to allow any case of `publisher` or any URL on `pulumi.com` website. We had a few packages use a different combination and then the Java publishing process would fail to get it to Maven Central properly. Fixes #1366 ## Checklist - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have updated the [CHANGELOG-PENDING](https://github.com/pulumi/pulumi/blob/master/CHANGELOG_PENDING.md) file with my change - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version --- pkg/codegen/java/templates_gradle.go | 21 +++++++++++++--- pkg/codegen/java/templates_gradle_test.go | 30 +++++++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/pkg/codegen/java/templates_gradle.go b/pkg/codegen/java/templates_gradle.go index ee248f34837..01d3c96b983 100644 --- a/pkg/codegen/java/templates_gradle.go +++ b/pkg/codegen/java/templates_gradle.go @@ -6,6 +6,7 @@ import ( "bytes" _ "embed" "fmt" + "net/url" "strings" "github.com/pulumi/pulumi/pkg/v3/codegen/schema" @@ -123,10 +124,7 @@ func newGradleTemplateContext( ctx.GroupID = "com.pulumi" } - if pkg.Publisher == "Pulumi" || - pkg.Homepage == "https://pulumi.com" || - pkg.Homepage == "https://pulumi.io" { - + if isPublishedByPulumi(pkg) { ctx.GroupID = "com.pulumi" ctx.DeveloperID = "pulumi" ctx.DeveloperName = "Pulumi" @@ -142,6 +140,21 @@ func newGradleTemplateContext( return ctx } +func isPublishedByPulumi(pkg *schema.Package) bool { + if strings.EqualFold(pkg.Publisher, "pulumi") { + return true + } + + u, err := url.Parse(pkg.Homepage) + if err == nil { + if strings.HasSuffix(u.Host, "pulumi.com") || u.Host == "pulumi.io" { + return true + } + } + + return false +} + func formatGitURL(url string) string { if strings.HasPrefix(url, "https://github.com/") { return fmt.Sprintf("git@github.com/%s.git", diff --git a/pkg/codegen/java/templates_gradle_test.go b/pkg/codegen/java/templates_gradle_test.go index 03b0b8bc9cf..48d9da0b76c 100644 --- a/pkg/codegen/java/templates_gradle_test.go +++ b/pkg/codegen/java/templates_gradle_test.go @@ -57,3 +57,33 @@ func eksExample() (*schema.Package, *PackageInfo) { info := &PackageInfo{Dependencies: deps} return pkg, info } + +func TestIsPublishedByPulumi(t *testing.T) { + type testCase struct { + publisher string + homepage string + expected bool + } + + testCases := []testCase{ + {"Pulumi", "", true}, + {"pulumi", "", true}, + {"", "https://pulumi.com", true}, + {"", "https://www.pulumi.com", true}, + {"", "http://www.pulumi.com", true}, + {"", "https://www.pulumi.com/registry/packages/xyz/", true}, + {"", "https://pulumi.io", true}, + {"Pulumiverse", "https://example.com", false}, + {"Pulumi fan", "https://pulumi.co", false}, + {"Acmecorp", "invalid url!", false}, + } + + for _, tc := range testCases { + pkg := &schema.Package{ + Publisher: tc.publisher, + Homepage: tc.homepage, + } + result := isPublishedByPulumi(pkg) + assert.Equal(t, tc.expected, result) + } +}