From 36c1c1d2dc76dc652777ac23305af7f316b90e6f Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:50:40 +0100 Subject: [PATCH] test: move gha cache to its own suite Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- .github/workflows/buildkit.yml | 4 ++ client/build_test.go | 2 + client/client_test.go | 48 ++------------------- client/ghacache_test.go | 76 ++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 45 deletions(-) create mode 100644 client/ghacache_test.go diff --git a/.github/workflows/buildkit.yml b/.github/workflows/buildkit.yml index b4f56b3b6007..65794971f418 100644 --- a/.github/workflows/buildkit.yml +++ b/.github/workflows/buildkit.yml @@ -143,6 +143,10 @@ jobs: tags: nydus skip-integration-tests: 1 typ: integration + - pkg: ./client + worker: oci + tags: ghacache + typ: integration govulncheck: runs-on: ubuntu-24.04 diff --git a/client/build_test.go b/client/build_test.go index 10e746109432..db50c10d3a9b 100644 --- a/client/build_test.go +++ b/client/build_test.go @@ -1,3 +1,5 @@ +//go:build !ghacache + package client import ( diff --git a/client/client_test.go b/client/client_test.go index ace0060aa142..af0d4d0b0932 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -1,3 +1,5 @@ +//go:build !ghacache + package client import ( @@ -148,7 +150,6 @@ var allTests = []func(t *testing.T, sb integration.Sandbox){ testHostnameSpecifying, testPushByDigest, testBasicInlineCacheImportExport, - testBasicGhaCacheImportExportExtraTimeout, testExportBusyboxLocal, testBridgeNetworking, testCacheMountNoCache, @@ -6176,49 +6177,6 @@ func testBasicInlineCacheImportExport(t *testing.T, sb integration.Sandbox) { require.EqualValues(t, unique, unique3) } -func testBasicGhaCacheImportExportExtraTimeout(t *testing.T, sb integration.Sandbox) { - workers.CheckFeatureCompat(t, sb, - workers.FeatureCacheExport, - workers.FeatureCacheImport, - workers.FeatureCacheBackendGha, - ) - runtimeToken := os.Getenv("ACTIONS_RUNTIME_TOKEN") - cacheURL := os.Getenv("ACTIONS_CACHE_URL") - if runtimeToken == "" || cacheURL == "" { - t.Skip("ACTIONS_RUNTIME_TOKEN and ACTIONS_CACHE_URL must be set") - } - - scope := "buildkit-" + t.Name() - if ref := os.Getenv("GITHUB_REF"); ref != "" { - if strings.HasPrefix(ref, "refs/heads/") { - scope += "-" + strings.TrimPrefix(ref, "refs/heads/") - } else if strings.HasPrefix(ref, "refs/tags/") { - scope += "-" + strings.TrimPrefix(ref, "refs/tags/") - } else if strings.HasPrefix(ref, "refs/pull/") { - scope += "-pr" + strings.TrimPrefix(strings.TrimSuffix(strings.TrimSuffix(ref, "/head"), "/merge"), "refs/pull/") - } - } - - im := CacheOptionsEntry{ - Type: "gha", - Attrs: map[string]string{ - "url": cacheURL, - "token": runtimeToken, - "scope": scope, - }, - } - ex := CacheOptionsEntry{ - Type: "gha", - Attrs: map[string]string{ - "url": cacheURL, - "token": runtimeToken, - "scope": scope, - "mode": "max", - }, - } - testBasicCacheImportExport(t, sb, []CacheOptionsEntry{im}, []CacheOptionsEntry{ex}) -} - func testRegistryEmptyCacheExport(t *testing.T, sb integration.Sandbox) { workers.CheckFeatureCompat(t, sb, workers.FeatureCacheExport, @@ -7480,7 +7438,7 @@ func testMergeOp(t *testing.T, sb integration.Sandbox) { File(llb.Mkfile("bar/D", 0644, []byte("D"))). File(llb.Mkfile("bar/E", 0755, nil)). File(llb.Mkfile("qaz", 0644, nil)), - // /foo from stateE is not here because it is deleted in stateB, which is part of a submerge of mergeD + // /foo from stateE is not here because it is deleted in stateB, which is part of a submerge of mergeD ) } diff --git a/client/ghacache_test.go b/client/ghacache_test.go new file mode 100644 index 000000000000..3f07ead14f37 --- /dev/null +++ b/client/ghacache_test.go @@ -0,0 +1,76 @@ +//go:build ghacache + +package client + +import ( + "os" + "strings" + "testing" + + "github.com/moby/buildkit/util/testutil/integration" + "github.com/moby/buildkit/util/testutil/workers" +) + +func init() { + if workers.IsTestDockerd() { + workers.InitDockerdWorker() + } else { + workers.InitOCIWorker() + workers.InitContainerdWorker() + } +} + +func TestGhaCacheIntegration(t *testing.T) { + testIntegration(t, testBasicGhaCacheImportExportExtraTimeout) +} + +func testIntegration(t *testing.T, funcs ...func(t *testing.T, sb integration.Sandbox)) { + mirroredImagesUnix := integration.OfficialImages("busybox:latest", "alpine:latest") + mirroredImagesWin := integration.OfficialImages("nanoserver:latest", "nanoserver:plus") + mirroredImages := integration.UnixOrWindows(mirroredImagesUnix, mirroredImagesWin) + mirrors := integration.WithMirroredImages(mirroredImages) + integration.Run(t, integration.TestFuncs(funcs...), mirrors) +} + +func testBasicGhaCacheImportExportExtraTimeout(t *testing.T, sb integration.Sandbox) { + workers.CheckFeatureCompat(t, sb, + workers.FeatureCacheExport, + workers.FeatureCacheImport, + workers.FeatureCacheBackendGha, + ) + runtimeToken := os.Getenv("ACTIONS_RUNTIME_TOKEN") + cacheURL := os.Getenv("ACTIONS_CACHE_URL") + if runtimeToken == "" || cacheURL == "" { + t.Skip("ACTIONS_RUNTIME_TOKEN and ACTIONS_CACHE_URL must be set") + } + + scope := "buildkit-" + t.Name() + if ref := os.Getenv("GITHUB_REF"); ref != "" { + if strings.HasPrefix(ref, "refs/heads/") { + scope += "-" + strings.TrimPrefix(ref, "refs/heads/") + } else if strings.HasPrefix(ref, "refs/tags/") { + scope += "-" + strings.TrimPrefix(ref, "refs/tags/") + } else if strings.HasPrefix(ref, "refs/pull/") { + scope += "-pr" + strings.TrimPrefix(strings.TrimSuffix(strings.TrimSuffix(ref, "/head"), "/merge"), "refs/pull/") + } + } + + im := CacheOptionsEntry{ + Type: "gha", + Attrs: map[string]string{ + "url": cacheURL, + "token": runtimeToken, + "scope": scope, + }, + } + ex := CacheOptionsEntry{ + Type: "gha", + Attrs: map[string]string{ + "url": cacheURL, + "token": runtimeToken, + "scope": scope, + "mode": "max", + }, + } + testBasicCacheImportExport(t, sb, []CacheOptionsEntry{im}, []CacheOptionsEntry{ex}) +}