Skip to content

Commit

Permalink
test: move gha cache in 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 6aebf1f
Show file tree
Hide file tree
Showing 3 changed files with 66 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
61 changes: 61 additions & 0 deletions client/client_ghacache_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//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() {
allTests = []func(t *testing.T, sb integration.Sandbox){
testBasicGhaCacheImportExportExtraTimeout,
}
}

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})
}
46 changes: 1 addition & 45 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ var allTests = []func(t *testing.T, sb integration.Sandbox){
testHostnameSpecifying,
testPushByDigest,
testBasicInlineCacheImportExport,
testBasicGhaCacheImportExportExtraTimeout,
testExportBusyboxLocal,
testBridgeNetworking,
testCacheMountNoCache,
Expand Down Expand Up @@ -6176,49 +6175,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 +7436,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

0 comments on commit 6aebf1f

Please sign in to comment.