Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support inline scripts #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/preparer/preparer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,8 @@ func Test_UpdateOrderToml(t *testing.T) {

[[order.group]]
id = "hello-comet"
[order.group.script]
api = "0.5"
inline = " echo \"Comet!\"\n "
`))
}
9 changes: 6 additions & 3 deletions pkg/order/order.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package order

import "github.com/jromero/cnb-prepare/pkg/project/types"

type Order struct {
Groups []Group `toml:"order"`
}
Expand All @@ -9,7 +11,8 @@ type Group struct {
}

type BuildpackEntry struct {
ID string `toml:"id,omitempty"`
Version string `toml:"version,omitempty"`
Optional bool `toml:"optional,omitempty"`
ID string `toml:"id,omitempty"`
Version string `toml:"version,omitempty"`
Optional bool `toml:"optional,omitempty"`
Script *types.Script `toml:"script,omitempty"`
}
9 changes: 9 additions & 0 deletions pkg/preparer/preparer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,18 @@ func processDescriptor(options Options, descriptor types.Descriptor) error {
options.logger.Info("Buildpacks specified, overwriting order.toml")
group := order.Group{}
for _, b := range descriptor.Build.Buildpacks {
var script *types.Script
if b.Script.API == "" && b.Script.Inline == "" && b.Script.Shell == "" {
script = nil
} else {
script_one := b.Script
script = &script_one
}

group.Buildpacks = append(group.Buildpacks, order.BuildpackEntry{
ID: b.ID,
Version: b.Version,
Script: script,
Optional: false,
})
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/project/types/types.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package types

type Script struct {
API string `toml:"api"`
Inline string `toml:"inline"`
Shell string `toml:"shell"`
API string `toml:"api,omitempty"`
Inline string `toml:"inline,omitempty"`
Shell string `toml:"shell,omitempty"`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can also create a different type in the order.go file instead with the omitempty options if here it's not the place.

}

type Buildpack struct {
Expand Down