Skip to content

Commit

Permalink
Merge pull request #1873 from buildpacks/fix/version-project-toml
Browse files Browse the repository at this point in the history
When additional buildpack is missing version, try to use the latest one
  • Loading branch information
jkutner authored Aug 26, 2023
2 parents e03ab0b + b5ef5de commit cdd0757
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions internal/commands/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ version = "1.0"
h.AssertNil(t, command.Execute())
})
})

when("file has a builder specified", func() {
var projectTomlPath string

Expand Down Expand Up @@ -608,6 +609,7 @@ builder = "my-builder"
})
})
})

when("file is invalid", func() {
var projectTomlPath string

Expand Down
4 changes: 3 additions & 1 deletion pkg/client/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,10 @@ func getBuildpackLocator(bp projectTypes.Buildpack, stackID string) (string, err
return bp.URI, nil
case bp.ID != "" && bp.Version != "":
return fmt.Sprintf("%s@%s", bp.ID, bp.Version), nil
case bp.ID != "" && bp.Version == "":
return bp.ID, nil
default:
return "", errors.New("Invalid buildpack defined in project descriptor")
return "", errors.New("Invalid buildpack definition")
}
}

Expand Down
27 changes: 26 additions & 1 deletion pkg/client/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,29 @@ api = "0.2"
)
})

when("from project descriptor", func() {
when("id - no version is provided", func() {
it("resolves version", func() {
h.AssertNil(t, subject.Build(context.TODO(), BuildOptions{
Image: "some/app",
Builder: defaultBuilderName,
ClearCache: true,
ProjectDescriptor: projectTypes.Descriptor{
Build: projectTypes.Build{Buildpacks: []projectTypes.Buildpack{{ID: "buildpack.1.id"}}},
},
}))
h.AssertEq(t, fakeLifecycle.Opts.Builder.Name(), defaultBuilderImage.Name())

assertOrderEquals(`[[order]]
[[order.group]]
id = "buildpack.1.id"
version = "buildpack.1.version"
`)
})
})
})

when("buildpacks include URIs", func() {
var buildpackTgz string

Expand Down Expand Up @@ -1405,6 +1428,7 @@ api = "0.2"
{ID: "some-other-buildpack-id", Version: "some-other-buildpack-version"},
})
})

it("adds the pre buildpack from the project descriptor", func() {
err := subject.Build(context.TODO(), BuildOptions{
Image: "some/app",
Expand Down Expand Up @@ -1519,6 +1543,7 @@ api = "0.2"
{ID: "buildpack.2.id", Version: "buildpack.2.version"},
})
})

it("not added from the project descriptor", func() {
err := subject.Build(context.TODO(), BuildOptions{
Image: "some/app",
Expand Down Expand Up @@ -1716,7 +1741,7 @@ api = "0.2"
ProjectDescriptorBaseDir: tmpDir,
})

h.AssertEq(t, "Invalid buildpack defined in project descriptor", err.Error())
h.AssertEq(t, "Invalid buildpack definition", err.Error())
})

it("ignores script if there is a URI", func() {
Expand Down

0 comments on commit cdd0757

Please sign in to comment.