Skip to content

Commit

Permalink
test: move gha cache to its own suite
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Jan 14, 2025
1 parent f3210ae commit 36c1c1d
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 45 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/buildkit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions client/build_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !ghacache

package client

import (
Expand Down
48 changes: 3 additions & 45 deletions client/client_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !ghacache

package client

import (
Expand Down Expand Up @@ -148,7 +150,6 @@ var allTests = []func(t *testing.T, sb integration.Sandbox){
testHostnameSpecifying,
testPushByDigest,
testBasicInlineCacheImportExport,
testBasicGhaCacheImportExportExtraTimeout,
testExportBusyboxLocal,
testBridgeNetworking,
testCacheMountNoCache,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
)
}

Expand Down
76 changes: 76 additions & 0 deletions client/ghacache_test.go
Original file line number Diff line number Diff line change
@@ -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})
}

0 comments on commit 36c1c1d

Please sign in to comment.