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

Ensures deprecation notice for buildpacks.yml picks the next major #134

Merged
merged 2 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Build(

// Parse the BuildConfiguration from the environment again since a prior
// step may have augmented the configuration.
configuration, err := parser.Parse(context.WorkingDir)
configuration, err := parser.Parse(context.BuildpackInfo.Version, context.WorkingDir)
if err != nil {
return packit.BuildResult{}, packit.Fail.WithMessage("failed to parse build configuration: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions build_configuration_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type TargetManager interface {

//go:generate faux --interface BuildpackYMLParser --output fakes/buildpack_yml_parser.go
type BuildpackYMLParser interface {
Parse(workingDir string) (BuildConfiguration, error)
Parse(buildpackVersion, workingDir string) (BuildConfiguration, error)
}

type BuildConfiguration struct {
Expand All @@ -37,7 +37,7 @@ func NewBuildConfigurationParser(targetManager TargetManager, buildpackYMLParser
}
}

func (p BuildConfigurationParser) Parse(workingDir string) (BuildConfiguration, error) {
func (p BuildConfigurationParser) Parse(buildpackVersion, workingDir string) (BuildConfiguration, error) {
var buildConfiguration BuildConfiguration

_, err := os.Stat(filepath.Join(workingDir, "buildpack.yml"))
Expand All @@ -46,7 +46,7 @@ func (p BuildConfigurationParser) Parse(workingDir string) (BuildConfiguration,
return BuildConfiguration{}, err
}
} else {
buildConfiguration, err = p.buildpackYMLParser.Parse(workingDir)
buildConfiguration, err = p.buildpackYMLParser.Parse(buildpackVersion, workingDir)
if err != nil {
return BuildConfiguration{}, err
}
Expand Down
20 changes: 10 additions & 10 deletions build_configuration_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
})

it("uses the values in the env var", func() {
configuration, err := parser.Parse(workingDir)
configuration, err := parser.Parse("1.2.3", workingDir)
Expect(err).NotTo(HaveOccurred())
Expect(configuration).To(Equal(gobuild.BuildConfiguration{
Targets: []string{"./some/target1", "./some/target2"},
Expand All @@ -86,7 +86,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
})

it("uses the values in the env var", func() {
configuration, err := parser.Parse(workingDir)
configuration, err := parser.Parse("1.2.3", workingDir)
Expect(err).NotTo(HaveOccurred())
Expect(configuration).To(Equal(gobuild.BuildConfiguration{
Targets: []string{"."},
Expand All @@ -113,7 +113,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
})

it("uses the values in the env var", func() {
configuration, err := parser.Parse(workingDir)
configuration, err := parser.Parse("1.2.3", workingDir)
Expect(err).NotTo(HaveOccurred())
Expect(configuration).To(Equal(gobuild.BuildConfiguration{
Targets: []string{"."},
Expand All @@ -133,7 +133,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
})

it("parses the targets and flags from a buildpack.yml", func() {
configuration, err := parser.Parse(workingDir)
configuration, err := parser.Parse("1.2.3", workingDir)
Expect(err).NotTo(HaveOccurred())
Expect(configuration).To(Equal(gobuild.BuildConfiguration{
Targets: []string{"./first", "./second"},
Expand Down Expand Up @@ -169,7 +169,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
})

it("parses the targets and flags from a buildpack.yml but uses the values from the environment variables", func() {
configuration, err := parser.Parse(workingDir)
configuration, err := parser.Parse("1.2.3", workingDir)
Expect(err).NotTo(HaveOccurred())
Expect(configuration).To(Equal(gobuild.BuildConfiguration{
Targets: []string{"./some/target1", "./some/target2"},
Expand All @@ -196,7 +196,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
})

it("returns an error", func() {
_, err := parser.Parse(workingDir)
_, err := parser.Parse("1.2.3", workingDir)
Expect(err).To(MatchError(ContainSubstring("permission denied")))
})
})
Expand All @@ -210,7 +210,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
})

it("returns an error", func() {
_, err := parser.Parse(workingDir)
_, err := parser.Parse("1.2.3", workingDir)
Expect(err).To(MatchError("failed to parse buildpack.yml"))
})
})
Expand All @@ -228,7 +228,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
})

it("returns an error", func() {
_, err := parser.Parse(workingDir)
_, err := parser.Parse("1.2.3", workingDir)
Expect(err).To(MatchError("failed to clean and validate targets"))
})
}, spec.Sequential())
Expand All @@ -239,7 +239,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
})

it("returns an error", func() {
_, err := parser.Parse(workingDir)
_, err := parser.Parse("1.2.3", workingDir)
Expect(err).To(MatchError("failed to default target found"))
})
})
Expand All @@ -254,7 +254,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) {
})

it("returns an error", func() {
_, err := parser.Parse(workingDir)
_, err := parser.Parse("1.2.3", workingDir)
Expect(err).To(MatchError(ContainSubstring("invalid command line string")))
})
}, spec.Sequential())
Expand Down
3 changes: 3 additions & 0 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
},
}))

Expect(parser.ParseCall.Receives.BuildpackVersion).To(Equal("some-version"))
Expect(parser.ParseCall.Receives.WorkingDir).To(Equal(workingDir))

Expect(pathManager.SetupCall.Receives.Workspace).To(Equal(workingDir))
Expect(pathManager.SetupCall.Receives.ImportPath).To(Equal("some-import-path"))

Expand Down
4 changes: 2 additions & 2 deletions detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (

//go:generate faux --interface ConfigurationParser --output fakes/configuration_parser.go
type ConfigurationParser interface {
Parse(workingDir string) (BuildConfiguration, error)
Parse(buildpackVersion, workingDir string) (BuildConfiguration, error)
}

func Detect(parser ConfigurationParser) packit.DetectFunc {
return func(context packit.DetectContext) (packit.DetectResult, error) {
if _, err := parser.Parse(context.WorkingDir); err != nil {
if _, err := parser.Parse(context.BuildpackInfo.Version, context.WorkingDir); err != nil {
return packit.DetectResult{}, packit.Fail.WithMessage("failed to parse build configuration: %w", err)
}

Expand Down
10 changes: 4 additions & 6 deletions detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
it("detects", func() {
result, err := detect(packit.DetectContext{
WorkingDir: workingDir,
BuildpackInfo: packit.BuildpackInfo{
Version: "some-buildpack-version",
},
})
Expect(err).NotTo(HaveOccurred())
Expect(result.Plan).To(Equal(packit.BuildPlan{
Expand All @@ -46,6 +49,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
}},
}))

Expect(parser.ParseCall.Receives.BuildpackVersion).To(Equal("some-buildpack-version"))
Expect(parser.ParseCall.Receives.WorkingDir).To(Equal(workingDir))
})

Expand All @@ -67,8 +71,6 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
},
}},
}))

Expect(parser.ParseCall.Receives.WorkingDir).To(Equal(workingDir))
})
})

Expand All @@ -90,8 +92,6 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
},
}},
}))

Expect(parser.ParseCall.Receives.WorkingDir).To(Equal(workingDir))
})
})

Expand All @@ -116,8 +116,6 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
},
}},
}))

Expect(parser.ParseCall.Receives.WorkingDir).To(Equal(workingDir))
})
})

Expand Down
12 changes: 7 additions & 5 deletions fakes/buildpack_yml_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@ type BuildpackYMLParser struct {
sync.Mutex
CallCount int
Receives struct {
WorkingDir string
BuildpackVersion string
WorkingDir string
}
Returns struct {
BuildConfiguration gobuild.BuildConfiguration
Error error
}
Stub func(string) (gobuild.BuildConfiguration, error)
Stub func(string, string) (gobuild.BuildConfiguration, error)
}
}

func (f *BuildpackYMLParser) Parse(param1 string) (gobuild.BuildConfiguration, error) {
func (f *BuildpackYMLParser) Parse(param1 string, param2 string) (gobuild.BuildConfiguration, error) {
f.ParseCall.Lock()
defer f.ParseCall.Unlock()
f.ParseCall.CallCount++
f.ParseCall.Receives.WorkingDir = param1
f.ParseCall.Receives.BuildpackVersion = param1
f.ParseCall.Receives.WorkingDir = param2
if f.ParseCall.Stub != nil {
return f.ParseCall.Stub(param1)
return f.ParseCall.Stub(param1, param2)
}
return f.ParseCall.Returns.BuildConfiguration, f.ParseCall.Returns.Error
}
12 changes: 7 additions & 5 deletions fakes/configuration_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@ type ConfigurationParser struct {
sync.Mutex
CallCount int
Receives struct {
WorkingDir string
BuildpackVersion string
WorkingDir string
}
Returns struct {
BuildConfiguration gobuild.BuildConfiguration
Error error
}
Stub func(string) (gobuild.BuildConfiguration, error)
Stub func(string, string) (gobuild.BuildConfiguration, error)
}
}

func (f *ConfigurationParser) Parse(param1 string) (gobuild.BuildConfiguration, error) {
func (f *ConfigurationParser) Parse(param1 string, param2 string) (gobuild.BuildConfiguration, error) {
f.ParseCall.Lock()
defer f.ParseCall.Unlock()
f.ParseCall.CallCount++
f.ParseCall.Receives.WorkingDir = param1
f.ParseCall.Receives.BuildpackVersion = param1
f.ParseCall.Receives.WorkingDir = param2
if f.ParseCall.Stub != nil {
return f.ParseCall.Stub(param1)
return f.ParseCall.Stub(param1, param2)
}
return f.ParseCall.Returns.BuildConfiguration, f.ParseCall.Returns.Error
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.14

require (
github.com/BurntSushi/toml v0.3.1
github.com/Masterminds/semver v1.5.0
github.com/buildkite/interpolate v0.0.0-20200526001904-07f35b4ae251
github.com/mattn/go-shellwords v1.0.11-0.20201201010856-2c8720de5e83
github.com/onsi/gomega v1.10.5
Expand Down
6 changes: 4 additions & 2 deletions go_buildpack_yml_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/buildkite/interpolate"
"gopkg.in/yaml.v2"
"github.com/Masterminds/semver"
)

type GoBuildpackYMLParser struct {
Expand All @@ -20,7 +21,7 @@ func NewGoBuildpackYMLParser(logger LogEmitter) GoBuildpackYMLParser {
}
}

func (p GoBuildpackYMLParser) Parse(workingDir string) (BuildConfiguration, error) {
func (p GoBuildpackYMLParser) Parse(buildpackVersion, workingDir string) (BuildConfiguration, error) {
file, err := os.Open(filepath.Join(workingDir, "buildpack.yml"))
if err != nil {
return BuildConfiguration{}, fmt.Errorf("failed to read buildpack.yml: %w", err)
Expand Down Expand Up @@ -60,7 +61,8 @@ func (p GoBuildpackYMLParser) Parse(workingDir string) (BuildConfiguration, erro
}

if buildConfiguration.Targets != nil || buildConfiguration.Flags != nil || buildConfiguration.ImportPath != "" {
p.logger.Process("WARNING: Setting the Go Build configurations such as targets, build flags, and import path through buildpack.yml will be deprecated soon in Go Build Buildpack v1.0.0.")
nextMajorVersion := semver.MustParse(buildpackVersion).IncMajor()
p.logger.Process("WARNING: Setting the Go Build configurations such as targets, build flags, and import path through buildpack.yml will be deprecated soon in Go Build Buildpack v%s.", nextMajorVersion.String())
p.logger.Process("Please specify these configuration options through environment variables instead. See README.md or the documentation on paketo.io for more information.")
p.logger.Break()
}
Expand Down
14 changes: 7 additions & 7 deletions go_buildpack_yml_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ go:

context("Parse", func() {
it("parses the buildpack and returns a build configuration", func() {
config, err := goBuildpackYMLParser.Parse(workingDir)
config, err := goBuildpackYMLParser.Parse("1.2.3", workingDir)
Expect(err).NotTo(HaveOccurred())

Expect(config).To(Equal(gobuild.BuildConfiguration{
Expand All @@ -64,7 +64,7 @@ go:
},
ImportPath: "some-import-path",
}))
Expect(logs.String()).To(ContainSubstring("WARNING: Setting the Go Build configurations such as targets, build flags, and import path through buildpack.yml will be deprecated soon in Go Build Buildpack v1.0.0."))
Expect(logs.String()).To(ContainSubstring("WARNING: Setting the Go Build configurations such as targets, build flags, and import path through buildpack.yml will be deprecated soon in Go Build Buildpack v2.0.0."))
Expect(logs.String()).To(ContainSubstring("Please specify these configuration options through environment variables instead. See README.md or the documentation on paketo.io for more information."))
})

Expand All @@ -88,7 +88,7 @@ go:
})

it("interpolates the env vars those into the flags", func() {
config, err := goBuildpackYMLParser.Parse(workingDir)
config, err := goBuildpackYMLParser.Parse("1.2.3", workingDir)
Expect(err).NotTo(HaveOccurred())

Expect(config).To(Equal(gobuild.BuildConfiguration{
Expand All @@ -113,7 +113,7 @@ not-go:
})

it("does not return a deprecation message", func() {
config, err := goBuildpackYMLParser.Parse(workingDir)
config, err := goBuildpackYMLParser.Parse("1.2.3", workingDir)
Expect(err).NotTo(HaveOccurred())

Expect(config).To(Equal(gobuild.BuildConfiguration{}))
Expand All @@ -128,7 +128,7 @@ not-go:
})

it("returns an error", func() {
_, err := goBuildpackYMLParser.Parse(workingDir)
_, err := goBuildpackYMLParser.Parse("1.2.3", workingDir)
Expect(err).To(MatchError(ContainSubstring("failed to read buildpack.yml")))
Expect(err).To(MatchError(ContainSubstring("permission denied")))
})
Expand All @@ -140,7 +140,7 @@ not-go:
})

it("returns an error", func() {
_, err := goBuildpackYMLParser.Parse(workingDir)
_, err := goBuildpackYMLParser.Parse("1.2.3", workingDir)
Expect(err).To(MatchError(ContainSubstring("failed to decode buildpack.yml")))
Expect(err).To(MatchError(ContainSubstring("could not find expected directive name")))
})
Expand All @@ -157,7 +157,7 @@ go:
})

it("returns an error", func() {
_, err := goBuildpackYMLParser.Parse(workingDir)
_, err := goBuildpackYMLParser.Parse("1.2.3", workingDir)
Expect(err).To(MatchError(ContainSubstring("environment variable expansion failed:")))
})
})
Expand Down
4 changes: 2 additions & 2 deletions integration/buildpack_yml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ go:

Expect(logs).To(ContainLines(
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)),
" WARNING: Setting the Go Build configurations such as targets, build flags, and import path through buildpack.yml will be deprecated soon in Go Build Buildpack v1.0.0.",
" WARNING: Setting the Go Build configurations such as targets, build flags, and import path through buildpack.yml will be deprecated soon in Go Build Buildpack v2.0.0.",
" Please specify these configuration options through environment variables instead. See README.md or the documentation on paketo.io for more information.",
"",
" Executing build process",
Expand Down Expand Up @@ -138,7 +138,7 @@ go:

Expect(logs).To(ContainLines(
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)),
" WARNING: Setting the Go Build configurations such as targets, build flags, and import path through buildpack.yml will be deprecated soon in Go Build Buildpack v1.0.0.",
" WARNING: Setting the Go Build configurations such as targets, build flags, and import path through buildpack.yml will be deprecated soon in Go Build Buildpack v2.0.0.",
" Please specify these configuration options through environment variables instead. See README.md or the documentation on paketo.io for more information.",
"",
" Executing build process",
Expand Down