diff --git a/actions/draft-release/main.go b/actions/draft-release/main.go index 6ac406ac..72ff551f 100644 --- a/actions/draft-release/main.go +++ b/actions/draft-release/main.go @@ -87,9 +87,9 @@ func main() { } if _, dryRun := inputs["dry_run"]; dryRun { - fmt.Println("Title: ", name) - fmt.Println("Body: ", body) - fmt.Println("Would execute EditRelease with: ") + fmt.Println("Title:", name) + fmt.Println("Body:", body) + fmt.Println("Would execute EditRelease with:") fmt.Println(" ", owner) fmt.Println(" ", repo) fmt.Println(" ", releaseId) diff --git a/drafts/drafts.go b/drafts/drafts.go index d2d013fa..7574d041 100644 --- a/drafts/drafts.go +++ b/drafts/drafts.go @@ -26,6 +26,7 @@ import ( "os" "path/filepath" "regexp" + "sort" "strings" "text/template" @@ -212,6 +213,9 @@ func loadBuildpackTOML(TOML []byte) (*Buildpack, error) { if err := toml.Unmarshal(TOML, bp); err != nil { return nil, fmt.Errorf("unable to parse buildpack TOML\n%w", err) } + sort.Slice(bp.Stacks, func(i, j int) bool { + return strings.ToLower(bp.Stacks[i].ID) < strings.ToLower(bp.Stacks[j].ID) + }) if deps, found := bp.Metadata["dependencies"]; found { if depList, ok := deps.([]map[string]interface{}); ok { @@ -255,6 +259,10 @@ func loadBuildpackTOML(TOML []byte) (*Buildpack, error) { } else { return nil, fmt.Errorf("unable to read dependencies from %v", bp.Metadata) } + + sort.Slice(bp.Dependencies, func(i, j int) bool { + return strings.ToLower(bp.Dependencies[i].Name) < strings.ToLower(bp.Dependencies[j].Name) + }) } return bp, nil @@ -316,6 +324,10 @@ func (g GithubBuildpackLoader) LoadBuildpacks(uris []string) ([]Buildpack, error buildpacks = append(buildpacks, bp) } + sort.Slice(buildpacks, func(i, j int) bool { + return strings.ToLower(buildpacks[i].Info.Name) < strings.ToLower(buildpacks[j].Info.Name) + }) + return buildpacks, nil } diff --git a/drafts/drafts_test.go b/drafts/drafts_test.go index b5b722ef..0031816c 100644 --- a/drafts/drafts_test.go +++ b/drafts/drafts_test.go @@ -78,10 +78,12 @@ func testDrafts(t *testing.T, context spec.G, it spec.S) { Expect(p.PrimaryBuildpack.Info.ID).To(Equal("example/component")) Expect(p.PrimaryBuildpack.Info.Version).To(Equal("2.1.1")) Expect(p.PrimaryBuildpack.Info.Name).To(Equal("Example Component Buildpack")) - Expect(p.PrimaryBuildpack.Stacks).To(ContainElements( - libcnb.BuildpackStack{ID: "stack1"}, - libcnb.BuildpackStack{ID: "stack2"}, - libcnb.BuildpackStack{ID: "*"})) + Expect(p.PrimaryBuildpack.Stacks).To(Equal( + []libcnb.BuildpackStack{ + {ID: "*"}, + {ID: "stack1"}, + {ID: "stack2"}, + })) Expect(p.PrimaryBuildpack.Dependencies).To(HaveLen(2)) Expect(p.PrimaryBuildpack.Dependencies[0].ID).To(Equal("dep")) Expect(p.PrimaryBuildpack.Dependencies[0].Version).To(Equal("8.5.78")) @@ -119,10 +121,12 @@ func testDrafts(t *testing.T, context spec.G, it spec.S) { Expect(p.PrimaryBuildpack.Info.ID).To(Equal("example/component")) Expect(p.PrimaryBuildpack.Info.Version).To(Equal("2.1.1")) Expect(p.PrimaryBuildpack.Info.Name).To(Equal("Example Component Buildpack")) - Expect(p.PrimaryBuildpack.Stacks).To(ContainElements( - libcnb.BuildpackStack{ID: "stack1"}, - libcnb.BuildpackStack{ID: "stack2"}, - libcnb.BuildpackStack{ID: "*"})) + Expect(p.PrimaryBuildpack.Stacks).To(Equal( + []libcnb.BuildpackStack{ + {ID: "*"}, + {ID: "stack1"}, + {ID: "stack2"}, + })) Expect(p.PrimaryBuildpack.Dependencies).To(HaveLen(0)) }) @@ -271,8 +275,8 @@ func testDrafts(t *testing.T, context spec.G, it spec.S) { Expect(body).To(ContainSubstring("- `stack2`")) Expect(body).To(ContainSubstring("- `*`")) Expect(body).To(ContainSubstring("#### Dependencies:")) - Expect(body).To(ContainSubstring("Example Dep | `8.5.78` | `84c7707db0ce495473df2efdc93da21b6d47bf25cd0a79de52e5472ff9e5f094`")) - Expect(body).To(ContainSubstring("Example Dep | `9.0.62` | `03157728a832cf9c83048cdc28d09600cbb3e4fa087f8b97d74c8b4f34cd89bb`")) + Expect(body).To(ContainSubstring("Example Dep 8 | `8.5.78` | `84c7707db0ce495473df2efdc93da21b6d47bf25cd0a79de52e5472ff9e5f094`")) + Expect(body).To(ContainSubstring("Example Dep 9 | `9.0.62` | `03157728a832cf9c83048cdc28d09600cbb3e4fa087f8b97d74c8b4f34cd89bb`")) Expect(body).To(ContainSubstring("foo-body")) }) diff --git a/drafts/testdata/component/buildpack.toml b/drafts/testdata/component/buildpack.toml index f9c22da7..b1a28ae6 100644 --- a/drafts/testdata/component/buildpack.toml +++ b/drafts/testdata/component/buildpack.toml @@ -27,13 +27,27 @@ api = "0.7" type = "Apache-2.0" uri = "https://example.com/example/component/blob/main/LICENSE" +[[metadata.dependencies]] + cpes = ["cpe:2.3:a:example:dep:9.0.62:*:*:*:*:*:*:*"] + id = "dep" + name = "Example Dep 9" + purl = "pkg:generic/example-dep@9.0.62" + sha256 = "03157728a832cf9c83048cdc28d09600cbb3e4fa087f8b97d74c8b4f34cd89bb" + stacks = ["stack1", "stack2", "*"] + uri = "https://archive.example.org/dist/dep/dep-9/v9.0.62/bin/example-dep-9.0.62.tar.gz" + version = "9.0.62" + + [[metadata.dependencies.licenses]] + type = "Apache-2.0" + uri = "https://www.apache.org/licenses/" + [metadata] include-files = ["LICENSE", "NOTICE", "README.md", "bin/build", "bin/detect", "bin/helper", "bin/main", "buildpack.toml", "resources/context.xml", "resources/logging.properties", "resources/server.xml", "resources/web.xml"] pre-package = "scripts/build.sh" [[metadata.dependencies]] id = "dep" - name = "Example Dep" + name = "Example Dep 8" purl = "pkg:generic/example-dep@8.5.78" sha256 = "84c7707db0ce495473df2efdc93da21b6d47bf25cd0a79de52e5472ff9e5f094" stacks = ["stack1", "stack2", "*"] @@ -44,25 +58,11 @@ api = "0.7" type = "Apache-2.0" uri = "https://www.apache.org/licenses/" - [[metadata.dependencies]] - cpes = ["cpe:2.3:a:example:dep:9.0.62:*:*:*:*:*:*:*"] - id = "dep" - name = "Example Dep" - purl = "pkg:generic/example-dep@9.0.62" - sha256 = "03157728a832cf9c83048cdc28d09600cbb3e4fa087f8b97d74c8b4f34cd89bb" - stacks = ["stack1", "stack2", "*"] - uri = "https://archive.example.org/dist/dep/dep-9/v9.0.62/bin/example-dep-9.0.62.tar.gz" - version = "9.0.62" - - [[metadata.dependencies.licenses]] - type = "Apache-2.0" - uri = "https://www.apache.org/licenses/" - [[stacks]] - id = "stack1" + id = "stack2" [[stacks]] - id = "stack2" + id = "stack1" [[stacks]] id = "*" \ No newline at end of file diff --git a/integration/drafts_test.go b/integration/drafts_test.go index e18d7a47..6741d5f6 100644 --- a/integration/drafts_test.go +++ b/integration/drafts_test.go @@ -2,6 +2,8 @@ package integration_test import ( "net/http" + "sort" + "strings" "testing" "github.com/google/go-github/v43/github" @@ -66,6 +68,29 @@ func testDrafts(t *testing.T, context spec.G, it spec.S) { Expect(bp.Stacks).ToNot(BeEmpty()) }) + it("fetches buildpack.toml from a multiple remote buildpack", func() { + bpList := []string{ + "gcr.io/paketo-buildpacks/upx:main", + "gcr.io/paketo-buildpacks/azul-zulu:main", + "gcr.io/paketo-buildpacks/watchexec:main", + "gcr.io/paketo-buildpacks/bellsoft-liberica:main", + } + + bps, err := drafts.GithubBuildpackLoader{ + GithubClient: github.NewClient(http.DefaultClient), + }.LoadBuildpacks(bpList) + Expect(err).ToNot(HaveOccurred()) + + sort.Strings(bpList) + for i := range bpList { + Expect(bps[i].Info.ID).To(Equal(strings.TrimSuffix(strings.TrimPrefix(bpList[i], "gcr.io/"), ":main"))) + Expect(bps[i].Info.Version).ToNot(ContainSubstring("{{.version}}")) + Expect(bps[i].Dependencies).ToNot(BeEmpty()) + Expect(bps[i].OrderGroups).To(BeEmpty()) + Expect(bps[i].Stacks).ToNot(BeEmpty()) + } + }) + it("fails fetching an image that does not exist", func() { _, err := drafts.GithubBuildpackLoader{ GithubClient: github.NewClient(http.DefaultClient),