11package gha
22
33import (
4+ "maps"
45 "os"
56 "path/filepath"
7+ "strconv"
68 "strings"
79 "testing"
810 "time"
@@ -57,10 +59,25 @@ func testBasicGhaCacheImportExportExtraTimeout(t *testing.T, sb integration.Sand
5759
5860 destDir := t .TempDir ()
5961
60- runtimeToken := os .Getenv ("ACTIONS_RUNTIME_TOKEN" )
61- cacheURL := os .Getenv ("ACTIONS_CACHE_URL" )
62- if runtimeToken == "" || cacheURL == "" {
63- t .Skip ("ACTIONS_RUNTIME_TOKEN and ACTIONS_CACHE_URL must be set" )
62+ var cacheVersion string
63+ if v , ok := os .LookupEnv ("ACTIONS_CACHE_SERVICE_V2" ); ok {
64+ if b , err := strconv .ParseBool (v ); err == nil && b {
65+ cacheVersion = "2"
66+ }
67+ }
68+
69+ cacheAttrs := map [string ]string {}
70+ if cacheVersion == "2" {
71+ cacheAttrs ["url_v2" ] = os .Getenv ("ACTIONS_RESULTS_URL" )
72+ }
73+ cacheAttrs ["url" ] = os .Getenv ("ACTIONS_CACHE_URL" )
74+ if cacheAttrs ["url" ] == "" {
75+ cacheAttrs ["url" ] = os .Getenv ("ACTIONS_RESULTS_URL" )
76+ }
77+ cacheAttrs ["token" ] = os .Getenv ("ACTIONS_RUNTIME_TOKEN" )
78+
79+ if cacheAttrs ["token" ] == "" || (cacheAttrs ["url" ] == "" && cacheAttrs ["url_v2" ] == "" ) {
80+ t .Skip ("actions runtime token and cache url must be set" )
6481 }
6582
6683 scope := "buildkit-" + t .Name ()
@@ -74,6 +91,12 @@ func testBasicGhaCacheImportExportExtraTimeout(t *testing.T, sb integration.Sand
7491 }
7592 }
7693
94+ cacheExportAttrs := map [string ]string {
95+ "scope" : scope ,
96+ "mode" : "max" ,
97+ }
98+ maps .Copy (cacheExportAttrs , cacheAttrs )
99+
77100 _ , err = c .Solve (sb .Context (), def , client.SolveOpt {
78101 Exports : []client.ExportEntry {
79102 {
@@ -82,13 +105,8 @@ func testBasicGhaCacheImportExportExtraTimeout(t *testing.T, sb integration.Sand
82105 },
83106 },
84107 CacheExports : []client.CacheOptionsEntry {{
85- Type : "gha" ,
86- Attrs : map [string ]string {
87- "url" : cacheURL ,
88- "token" : runtimeToken ,
89- "scope" : scope ,
90- "mode" : "max" ,
91- },
108+ Type : "gha" ,
109+ Attrs : cacheExportAttrs ,
92110 }},
93111 }, nil )
94112 require .NoError (t , err )
@@ -104,6 +122,11 @@ func testBasicGhaCacheImportExportExtraTimeout(t *testing.T, sb integration.Sand
104122
105123 destDir = t .TempDir ()
106124
125+ cacheImportAttrs := map [string ]string {
126+ "scope" : scope ,
127+ }
128+ maps .Copy (cacheImportAttrs , cacheAttrs )
129+
107130 _ , err = c .Solve (sb .Context (), def , client.SolveOpt {
108131 Exports : []client.ExportEntry {
109132 {
@@ -112,12 +135,8 @@ func testBasicGhaCacheImportExportExtraTimeout(t *testing.T, sb integration.Sand
112135 },
113136 },
114137 CacheImports : []client.CacheOptionsEntry {{
115- Type : "gha" ,
116- Attrs : map [string ]string {
117- "url" : cacheURL ,
118- "token" : runtimeToken ,
119- "scope" : scope ,
120- },
138+ Type : "gha" ,
139+ Attrs : cacheImportAttrs ,
121140 }},
122141 }, nil )
123142 require .NoError (t , err )
0 commit comments