Skip to content

Commit

Permalink
Adds extra buildpack descriptors to BuildpackInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Moran authored and sophiewigmore committed Oct 25, 2021
1 parent 89312d1 commit 6fab3bb
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 31 deletions.
39 changes: 32 additions & 7 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ api = "0.6"
id = "some-id"
name = "some-name"
version = "some-version"
homepage = "some-homepage"
description = "some-description"
keywords = ["some-keyword"]
clear-env = false
[[buildpack.licenses]]
type = "some-license-type"
uri = "some-license-uri"
`)
Expect(os.WriteFile(filepath.Join(cnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed())
Expect(os.WriteFile(filepath.Join(envCnbDir, "buildpack.toml"), bpTOML, 0600)).To(Succeed())
Expand Down Expand Up @@ -129,15 +136,24 @@ api = "0.6"
Path: layersDir,
},
BuildpackInfo: packit.BuildpackInfo{
ID: "some-id",
Name: "some-name",
Version: "some-version",
ID: "some-id",
Name: "some-name",
Version: "some-version",
Homepage: "some-homepage",
Description: "some-description",
Keywords: []string{"some-keyword"},
Licenses: []packit.BuildpackInfoLicense{
{
Type: "some-license-type",
URI: "some-license-uri",
},
},
},
}))
})

context("when there are updates to the build plan", func() {
context("when the api version is less than 0.5", func() {

it.Before(func() {
bpTOML := []byte(`
api = "0.4"
Expand Down Expand Up @@ -291,9 +307,18 @@ cache = true
Path: layersDir,
},
BuildpackInfo: packit.BuildpackInfo{
ID: "some-id",
Name: "some-name",
Version: "some-version",
ID: "some-id",
Name: "some-name",
Version: "some-version",
Homepage: "some-homepage",
Description: "some-description",
Keywords: []string{"some-keyword"},
Licenses: []packit.BuildpackInfoLicense{
{
Type: "some-license-type",
URI: "some-license-uri",
},
},
},
}))
})
Expand Down
38 changes: 35 additions & 3 deletions buildpack_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,44 @@ package packit
// provided in its buildpack.toml file as described in the specification:
// https://github.com/buildpacks/spec/blob/main/buildpack.md#buildpacktoml-toml.
type BuildpackInfo struct {
// ID is the identifier specified in the `buildpack.id` field of the buildpack.toml.
// ID is the identifier specified in the `buildpack.id` field of the
// buildpack.toml.
ID string `toml:"id"`

// Name is the identifier specified in the `buildpack.name` field of the buildpack.toml.
// Name is the identifier specified in the `buildpack.name` field of the
// buildpack.toml.
Name string `toml:"name"`

// Version is the identifier specified in the `buildpack.version` field of the buildpack.toml.
// Version is the identifier specified in the `buildpack.version` field of
// the buildpack.toml.
Version string `toml:"version"`

// Homepage is the identifier specified in the `buildpack.homepage` field of
// the buildpack.toml.
Homepage string `toml:"homepage"`

// Description is the identifier specified in the `buildpack.description`
// field of the buildpack.toml.
Description string `toml:"description"`

// Keywords are the identifiers specified in the `buildpack.keywords` field
// of the buildpack.toml.
Keywords []string `toml:"keywords"`

// Licenses are the list of licenses specified in the `buildpack.licenses`
// fields of the buildpack.toml.
Licenses []BuildpackInfoLicense
}

// BuildpackInfoLicense is a representation of a license specified in the
// buildpack.toml as described in the specification:
// https://github.com/buildpacks/spec/blob/main/buildpack.md#buildpacktoml-toml.
type BuildpackInfoLicense struct {
// Type is the identifier specified in the `buildpack.licenses.type` field of
// the buildpack.toml.
Type string `toml:"type"`

// URI is the identifier specified in the `buildpack.licenses.uri` field of
// the buildpack.toml.
URI string `toml:"uri"`
}
13 changes: 8 additions & 5 deletions cargo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ type ConfigStack struct {
}

type ConfigBuildpack struct {
ID string `toml:"id" json:"id,omitempty"`
Name string `toml:"name" json:"name,omitempty"`
Version string `toml:"version" json:"version,omitempty"`
Homepage string `toml:"homepage,omitempty" json:"homepage,omitempty"`
Licenses []ConfigBuildpackLicense `toml:"licenses,omitempty" json:"licenses,omitempty"`
ID string `toml:"id" json:"id,omitempty"`
Name string `toml:"name" json:"name,omitempty"`
Version string `toml:"version" json:"version,omitempty"`
Homepage string `toml:"homepage,omitempty" json:"homepage,omitempty"`
ClearEnv bool `toml:"clear-env,omitempty" json:"clear-env,omitempty"`
Description string `toml:"description,omitempty" json:"description,omitempty"`
Keywords []string `toml:"keywords,omitempty" json:"keywords,omitempty"`
Licenses []ConfigBuildpackLicense `toml:"licenses,omitempty" json:"licenses,omitempty"`

// Deprecated: This field is not part of the official buildpack.toml spec and
// will therefore be removed in the next major release
Expand Down
44 changes: 28 additions & 16 deletions cargo/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ func testConfig(t *testing.T, context spec.G, it spec.S) {
Expect(err).NotTo(HaveOccurred())

err = cargo.EncodeConfig(buffer, cargo.Config{
API: "0.2",
API: "0.6",
Buildpack: cargo.ConfigBuildpack{
ID: "some-buildpack-id",
Name: "some-buildpack-name",
Version: "some-buildpack-version",
Homepage: "some-homepage-link",
ID: "some-buildpack-id",
Name: "some-buildpack-name",
Version: "some-buildpack-version",
Homepage: "some-buildpack-homepage",
ClearEnv: true,
Description: "some-buildpack-description",
Keywords: []string{"some-buildpack-keyword"},
Licenses: []cargo.ConfigBuildpackLicense{
{
Type: "some-license-type",
Expand Down Expand Up @@ -104,13 +107,16 @@ func testConfig(t *testing.T, context spec.G, it spec.S) {
})
Expect(err).NotTo(HaveOccurred())
Expect(buffer.String()).To(MatchTOML(`
api = "0.2"
api = "0.6"
[buildpack]
id = "some-buildpack-id"
name = "some-buildpack-name"
version = "some-buildpack-version"
homepage = "some-homepage-link"
homepage = "some-buildpack-homepage"
clear-env = true
description = "some-buildpack-description"
keywords = [ "some-buildpack-keyword" ]
[[buildpack.licenses]]
type = "some-license-type"
Expand Down Expand Up @@ -170,7 +176,7 @@ api = "0.2"
Expect(err).NotTo(HaveOccurred())

err = cargo.EncodeConfig(buffer, cargo.Config{
API: "0.2",
API: "0.6",
Buildpack: cargo.ConfigBuildpack{
ID: "some-buildpack-id",
Name: "some-buildpack-name",
Expand Down Expand Up @@ -252,7 +258,7 @@ api = "0.2"
})
Expect(err).NotTo(HaveOccurred())
Expect(buffer.String()).To(MatchTOML(`
api = "0.2"
api = "0.6"
[buildpack]
id = "some-buildpack-id"
Expand Down Expand Up @@ -358,13 +364,16 @@ api = "0.2"
context("DecodeConfig", func() {
it("decodes TOML to config", func() {
tomlBuffer := strings.NewReader(`
api = "0.2"
api = "0.6"
[buildpack]
id = "some-buildpack-id"
name = "some-buildpack-name"
version = "some-buildpack-version"
homepage = "some-homepage-link"
homepage = "some-buildpack-homepage"
clear-env = true
description = "some-buildpack-description"
keywords = [ "some-buildpack-keyword" ]
[[buildpack.licenses]]
type = "some-license-type"
Expand Down Expand Up @@ -419,12 +428,15 @@ api = "0.2"
var config cargo.Config
Expect(cargo.DecodeConfig(tomlBuffer, &config)).To(Succeed())
Expect(config).To(Equal(cargo.Config{
API: "0.2",
API: "0.6",
Buildpack: cargo.ConfigBuildpack{
ID: "some-buildpack-id",
Name: "some-buildpack-name",
Version: "some-buildpack-version",
Homepage: "some-homepage-link",
ID: "some-buildpack-id",
Name: "some-buildpack-name",
Version: "some-buildpack-version",
Homepage: "some-buildpack-homepage",
ClearEnv: true,
Description: "some-buildpack-description",
Keywords: []string{"some-buildpack-keyword"},
Licenses: []cargo.ConfigBuildpackLicense{
{
Type: "some-license-type",
Expand Down

0 comments on commit 6fab3bb

Please sign in to comment.