From 1476c76287c34bfc0df0b5b41c593c9f76f5a167 Mon Sep 17 00:00:00 2001 From: paketo-bot Date: Wed, 4 Sep 2024 13:35:57 +0000 Subject: [PATCH 1/6] Updating github-config --- .github/workflows/test-pull-request.yml | 2 ++ scripts/unit.sh | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index 6574ff7c..f1b3dc06 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -26,6 +26,8 @@ jobs: uses: actions/checkout@v3 - name: Run Unit Tests + env: + GO_TEST_PARAMS: -count=5 run: ./scripts/unit.sh - name: Get builders from integration.json diff --git a/scripts/unit.sh b/scripts/unit.sh index 8e193c79..dd130bf7 100755 --- a/scripts/unit.sh +++ b/scripts/unit.sh @@ -6,6 +6,8 @@ set -o pipefail readonly PROGDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly BUILDPACKDIR="$(cd "${PROGDIR}/.." && pwd)" +GO_TEST_PARAMS="${GO_TEST_PARAMS:-}" + # shellcheck source=SCRIPTDIR/.util/tools.sh source "${PROGDIR}/.util/tools.sh" @@ -50,7 +52,7 @@ function unit::run() { testout=$(mktemp) pushd "${BUILDPACKDIR}" > /dev/null - if go test ./... -v -run Unit | tee "${testout}"; then + if go test ./... -v ${GO_TEST_PARAMS} -run Unit | tee "${testout}"; then util::tools::tests::checkfocus "${testout}" util::print::success "** GO Test Succeeded **" else From 1fb4cd2ac5f60378dc92e6d970083f398dac0f46 Mon Sep 17 00:00:00 2001 From: paketo-bot Date: Tue, 10 Sep 2024 13:35:15 +0000 Subject: [PATCH 2/6] Updating github-config --- scripts/.util/tools.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/.util/tools.json b/scripts/.util/tools.json index e2e977dd..6a5dbdbb 100644 --- a/scripts/.util/tools.json +++ b/scripts/.util/tools.json @@ -1,5 +1,5 @@ { - "createpackage": "v1.70.0", - "jam": "v2.8.0", - "pack": "v0.34.2" + "createpackage": "v1.71.0", + "jam": "v2.9.0", + "pack": "v0.35.1" } From 0a5b107cec956f3264aa0ccee342f146670cc995 Mon Sep 17 00:00:00 2001 From: Forest Eckhardt Date: Tue, 10 Sep 2024 15:35:48 +0000 Subject: [PATCH 3/6] Fix error printing --- integration/empty_cache_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/empty_cache_test.go b/integration/empty_cache_test.go index 157e2ab9..c396e609 100644 --- a/integration/empty_cache_test.go +++ b/integration/empty_cache_test.go @@ -70,7 +70,7 @@ func testEmptyCache(t *testing.T, context spec.G, it spec.S) { "", )) - Expect(logs).NotTo(ContainSubstring(fmt.Sprintf("%s:mod-cache", settings.Buildpack.ID)), logs.String) + Expect(logs).NotTo(ContainSubstring(fmt.Sprintf("%s:mod-cache", settings.Buildpack.ID)), logs.String()) }) }) } From 5e88df5787e8a6a59bff5181b88e3d1e41c55766 Mon Sep 17 00:00:00 2001 From: Forest Eckhardt Date: Tue, 10 Sep 2024 17:48:11 +0000 Subject: [PATCH 4/6] Disable GOTELEMTRY to allow for empty cache --- build.go | 4 +++- integration/empty_cache_test.go | 5 ++++- integration/testdata/default/go.mod | 2 +- integration/testdata/default/main.go | 2 ++ integration/testdata/no_modules/go.mod | 2 +- integration/testdata/no_modules/main.go | 6 +++++- integration/testdata/vendored/go.mod | 2 +- 7 files changed, 17 insertions(+), 6 deletions(-) diff --git a/build.go b/build.go index 61435096..e1b559ce 100644 --- a/build.go +++ b/build.go @@ -88,7 +88,9 @@ func Build(buildProcess BuildProcess, logs scribe.Emitter, clock chronos.Clock, } if exists { - layers = append(layers, modCacheLayer) + if !fs.IsEmptyDir(modCacheLayer.Path) { + layers = append(layers, modCacheLayer) + } } return packit.BuildResult{ diff --git a/integration/empty_cache_test.go b/integration/empty_cache_test.go index c396e609..04d9860f 100644 --- a/integration/empty_cache_test.go +++ b/integration/empty_cache_test.go @@ -58,6 +58,9 @@ func testEmptyCache(t *testing.T, context spec.G, it spec.S) { settings.Buildpacks.GoDist.Online, settings.Buildpacks.GoModVendor.Online, ). + WithEnv(map[string]string{ + "GOTELEMETRY": "off", + }). Execute(name, source) Expect(err).NotTo(HaveOccurred(), logs.String) @@ -70,7 +73,7 @@ func testEmptyCache(t *testing.T, context spec.G, it spec.S) { "", )) - Expect(logs).NotTo(ContainSubstring(fmt.Sprintf("%s:mod-cache", settings.Buildpack.ID)), logs.String()) + Expect(logs).NotTo(ContainSubstring(fmt.Sprintf("%s:mod-cache", settings.Buildpack.ID)), logs.String) }) }) } diff --git a/integration/testdata/default/go.mod b/integration/testdata/default/go.mod index 2d2910e4..d5585206 100644 --- a/integration/testdata/default/go.mod +++ b/integration/testdata/default/go.mod @@ -1,6 +1,6 @@ module default -go 1.14 +go 1.23 require ( github.com/BurntSushi/toml v0.3.1 diff --git a/integration/testdata/default/main.go b/integration/testdata/default/main.go index 8e1ebf5c..33aed2a1 100644 --- a/integration/testdata/default/main.go +++ b/integration/testdata/default/main.go @@ -1,6 +1,7 @@ package main import ( + _ "embed" "fmt" "log" "net/http" @@ -14,6 +15,7 @@ type Config struct { Age int } +//go:embed .occam-key func main() { var conf Config if _, err := toml.Decode("whatever", &conf); err != nil { diff --git a/integration/testdata/no_modules/go.mod b/integration/testdata/no_modules/go.mod index 613a436b..2c70bc73 100644 --- a/integration/testdata/no_modules/go.mod +++ b/integration/testdata/no_modules/go.mod @@ -1,3 +1,3 @@ module no_modules -go 1.14 +go 1.23 diff --git a/integration/testdata/no_modules/main.go b/integration/testdata/no_modules/main.go index b1b14d0c..0862d468 100644 --- a/integration/testdata/no_modules/main.go +++ b/integration/testdata/no_modules/main.go @@ -1,7 +1,11 @@ package main -import "fmt" +import ( + _ "embed" + "fmt" +) +//go:embed .occam-key func main() { fmt.Println("Hello World!") } diff --git a/integration/testdata/vendored/go.mod b/integration/testdata/vendored/go.mod index 2d2910e4..d5585206 100644 --- a/integration/testdata/vendored/go.mod +++ b/integration/testdata/vendored/go.mod @@ -1,6 +1,6 @@ module default -go 1.14 +go 1.23 require ( github.com/BurntSushi/toml v0.3.1 From a2b2010f064a6576f9879a2b46a22e6364c6caba Mon Sep 17 00:00:00 2001 From: Forest Eckhardt Date: Tue, 10 Sep 2024 18:25:40 +0000 Subject: [PATCH 5/6] Adds file to be detected --- build_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build_test.go b/build_test.go index 11bed317..9451f2c3 100644 --- a/build_test.go +++ b/build_test.go @@ -54,6 +54,9 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { err = os.MkdirAll(filepath.Join(layersDir, "mod-cache"), os.ModePerm) Expect(err).NotTo(HaveOccurred()) + _, err = os.CreateTemp(filepath.Join(layersDir, "mod-cache"), "example") + Expect(err).NotTo(HaveOccurred()) + now := time.Now() clock = chronos.NewClock(func() time.Time { return now From bee9c4b2553a7f0738413f2fe24363e0df200654 Mon Sep 17 00:00:00 2001 From: Forest Eckhardt Date: Tue, 10 Sep 2024 18:41:20 +0000 Subject: [PATCH 6/6] Remove integration test in favor of unit test that excerises the same code path --- build_test.go | 24 +++++++- integration/empty_cache_test.go | 79 ------------------------- integration/init_test.go | 1 - integration/testdata/no_modules/go.mod | 3 - integration/testdata/no_modules/main.go | 11 ---- 5 files changed, 22 insertions(+), 96 deletions(-) delete mode 100644 integration/empty_cache_test.go delete mode 100644 integration/testdata/no_modules/go.mod delete mode 100644 integration/testdata/no_modules/main.go diff --git a/build_test.go b/build_test.go index 9451f2c3..27abe2ab 100644 --- a/build_test.go +++ b/build_test.go @@ -54,8 +54,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { err = os.MkdirAll(filepath.Join(layersDir, "mod-cache"), os.ModePerm) Expect(err).NotTo(HaveOccurred()) - _, err = os.CreateTemp(filepath.Join(layersDir, "mod-cache"), "example") - Expect(err).NotTo(HaveOccurred()) + Expect(os.WriteFile(filepath.Join(filepath.Join(layersDir, "mod-cache"), "cache"), nil, os.ModePerm)) now := time.Now() clock = chronos.NewClock(func() time.Time { @@ -177,6 +176,27 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { }) }) + context("when the mod cache layer is empty", func() { + it.Before(func() { + err := os.RemoveAll(filepath.Join(layersDir, "mod-cache", "cache")) + Expect(err).NotTo(HaveOccurred()) + }) + + it("does not include the module cache layer in the build result", func() { + result, err := build(packit.BuildContext{ + Layers: packit.Layers{Path: layersDir}, + WorkingDir: workingDir, + BuildpackInfo: packit.BuildpackInfo{ + Name: "Some Buildpack", + Version: "some-version", + }, + }) + Expect(err).NotTo(HaveOccurred()) + + Expect(result.Layers).To(BeEmpty()) + }) + }) + context("failure cases", func() { context("build process fails to check if it should run", func() { it.Before(func() { diff --git a/integration/empty_cache_test.go b/integration/empty_cache_test.go deleted file mode 100644 index 04d9860f..00000000 --- a/integration/empty_cache_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package integration_test - -import ( - "fmt" - "os" - "path/filepath" - "testing" - - "github.com/paketo-buildpacks/occam" - "github.com/sclevine/spec" - - . "github.com/onsi/gomega" - . "github.com/paketo-buildpacks/occam/matchers" -) - -func testEmptyCache(t *testing.T, context spec.G, it spec.S) { - var ( - Expect = NewWithT(t).Expect - - pack occam.Pack - docker occam.Docker - ) - - it.Before(func() { - pack = occam.NewPack().WithVerbose().WithNoColor() - docker = occam.NewDocker() - }) - - context("when building a simple go mod app", func() { - var ( - image occam.Image - - name string - source string - ) - - it.Before(func() { - var err error - name, err = occam.RandomName() - Expect(err).NotTo(HaveOccurred()) - }) - - it.After(func() { - Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed()) - Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed()) - Expect(os.RemoveAll(source)).To(Succeed()) - }) - - it("builds successfully", func() { - var err error - source, err = occam.Source(filepath.Join("testdata", "no_modules")) - Expect(err).NotTo(HaveOccurred()) - - var logs fmt.Stringer - image, logs, err = pack.Build. - WithPullPolicy("never"). - WithBuildpacks( - settings.Buildpacks.GoDist.Online, - settings.Buildpacks.GoModVendor.Online, - ). - WithEnv(map[string]string{ - "GOTELEMETRY": "off", - }). - Execute(name, source) - Expect(err).NotTo(HaveOccurred(), logs.String) - - Expect(logs).To(ContainLines( - MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)), - " Executing build process", - " Running 'go mod vendor'", - " go: no dependencies to vendor", - MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`), - "", - )) - - Expect(logs).NotTo(ContainSubstring(fmt.Sprintf("%s:mod-cache", settings.Buildpack.ID)), logs.String) - }) - }) -} diff --git a/integration/init_test.go b/integration/init_test.go index 874db9ab..96d16945 100644 --- a/integration/init_test.go +++ b/integration/init_test.go @@ -82,7 +82,6 @@ func TestIntegration(t *testing.T) { suite := spec.New("Integration", spec.Report(report.Terminal{}), spec.Parallel()) suite("Default", testDefault) - suite("EmptyCache", testEmptyCache) suite("Vendored", testVendored) suite.Run(t) } diff --git a/integration/testdata/no_modules/go.mod b/integration/testdata/no_modules/go.mod deleted file mode 100644 index 2c70bc73..00000000 --- a/integration/testdata/no_modules/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module no_modules - -go 1.23 diff --git a/integration/testdata/no_modules/main.go b/integration/testdata/no_modules/main.go deleted file mode 100644 index 0862d468..00000000 --- a/integration/testdata/no_modules/main.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - _ "embed" - "fmt" -) - -//go:embed .occam-key -func main() { - fmt.Println("Hello World!") -}