Skip to content

Commit

Permalink
Sort information for draft release output
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Mikusa <dmikusa@vmware.com>
  • Loading branch information
Daniel Mikusa committed Apr 18, 2022
1 parent 27680df commit 7b4a4a2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 30 deletions.
6 changes: 3 additions & 3 deletions actions/draft-release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions drafts/drafts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os"
"path/filepath"
"regexp"
"sort"
"strings"
"text/template"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
24 changes: 14 additions & 10 deletions drafts/drafts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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))
})

Expand Down Expand Up @@ -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"))
})

Expand Down
34 changes: 17 additions & 17 deletions drafts/testdata/component/buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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", "*"]
Expand All @@ -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 = "*"
25 changes: 25 additions & 0 deletions integration/drafts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package integration_test

import (
"net/http"
"sort"
"strings"
"testing"

"github.com/google/go-github/v43/github"
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 7b4a4a2

Please sign in to comment.