diff --git a/distzip/build.go b/distzip/build.go index e82f4bd..17fa1f4 100644 --- a/distzip/build.go +++ b/distzip/build.go @@ -22,6 +22,7 @@ import ( "os" "path/filepath" + "github.com/heroku/color" "github.com/paketo-buildpacks/libpak/effect" "github.com/paketo-buildpacks/libpak/sbom" @@ -67,6 +68,11 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) { return libcnb.BuildResult{}, fmt.Errorf("unable to create configuration resolver\n%w", err) } + err = os.Chmod(s, 0755) + if err != nil { + b.Logger.Bodyf("%s Unable to make script executable\n%w", color.YellowString("WARNING:"), err.Error()) + } + result.Processes = append(result.Processes, libcnb.Process{Type: "dist-zip", Command: s}, libcnb.Process{Type: "task", Command: s}, diff --git a/distzip/build_test.go b/distzip/build_test.go index 40abc2f..fa7cc7f 100644 --- a/distzip/build_test.go +++ b/distzip/build_test.go @@ -128,6 +128,32 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { }) }) + context("DistZip exists but isn't executable", func() { + var scriptPath string + + it.Before(func() { + scriptPath = filepath.Join(ctx.Application.Path, "app", "bin", "test-script") + Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "app", "bin"), 0755)).To(Succeed()) + Expect(os.WriteFile(scriptPath, []byte{}, 0644)) + }) + + it("contributes processes and marks the script executable", func() { + result, err := distzip.Build{SBOMScanner: &sbomScanner}.Build(ctx) + Expect(err).NotTo(HaveOccurred()) + + Expect(result.Processes).To(ContainElements( + libcnb.Process{Type: "dist-zip", Command: scriptPath}, + libcnb.Process{Type: "task", Command: scriptPath}, + libcnb.Process{Type: "web", Command: scriptPath, Default: true}, + )) + sbomScanner.AssertCalled(t, "ScanLaunch", ctx.Application.Path, libcnb.SyftJSON, libcnb.CycloneDXJSON) + + info, err := os.Stat(scriptPath) + Expect(err).NotTo(HaveOccurred()) + Expect(info.Mode().Perm().String()).To(Equal("-rwxr-xr-x")) + }) + }) + context("DistZip does not exists", func() { it("passes plan entries to subsequent buildpacks", func() { result, err := distzip.Build{}.Build(ctx) diff --git a/go.mod b/go.mod index 1940040..3857364 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.20 require ( github.com/buildpacks/libcnb v1.30.1 + github.com/heroku/color v0.0.6 github.com/onsi/gomega v1.31.1 github.com/paketo-buildpacks/libpak v1.68.1 github.com/sclevine/spec v1.4.0 @@ -15,7 +16,6 @@ require ( github.com/creack/pty v1.1.21 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/heroku/color v0.0.6 // indirect github.com/imdario/mergo v0.3.16 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect