Skip to content

Commit

Permalink
Extend the rule set that matches a package to be a Pulumi package (#1367
Browse files Browse the repository at this point in the history
)

<!--- 
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

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

<!--- 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 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. -->
  • Loading branch information
mikhailshilkov authored Jun 6, 2024
1 parent 0f614b6 commit 3dfcde4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pkg/codegen/java/templates_gradle.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bytes"
_ "embed"
"fmt"
"net/url"
"strings"

"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
Expand Down Expand Up @@ -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"
Expand All @@ -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("[email protected]/%s.git",
Expand Down
30 changes: 30 additions & 0 deletions pkg/codegen/java/templates_gradle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 3dfcde4

Please sign in to comment.