1
1
package gha
2
2
3
3
import (
4
+ "maps"
4
5
"os"
5
6
"path/filepath"
7
+ "strconv"
6
8
"strings"
7
9
"testing"
8
10
"time"
@@ -57,10 +59,25 @@ func testBasicGhaCacheImportExportExtraTimeout(t *testing.T, sb integration.Sand
57
59
58
60
destDir := t .TempDir ()
59
61
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" )
64
81
}
65
82
66
83
scope := "buildkit-" + t .Name ()
@@ -74,6 +91,12 @@ func testBasicGhaCacheImportExportExtraTimeout(t *testing.T, sb integration.Sand
74
91
}
75
92
}
76
93
94
+ cacheExportAttrs := map [string ]string {
95
+ "scope" : scope ,
96
+ "mode" : "max" ,
97
+ }
98
+ maps .Copy (cacheExportAttrs , cacheAttrs )
99
+
77
100
_ , err = c .Solve (sb .Context (), def , client.SolveOpt {
78
101
Exports : []client.ExportEntry {
79
102
{
@@ -82,13 +105,8 @@ func testBasicGhaCacheImportExportExtraTimeout(t *testing.T, sb integration.Sand
82
105
},
83
106
},
84
107
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 ,
92
110
}},
93
111
}, nil )
94
112
require .NoError (t , err )
@@ -104,6 +122,11 @@ func testBasicGhaCacheImportExportExtraTimeout(t *testing.T, sb integration.Sand
104
122
105
123
destDir = t .TempDir ()
106
124
125
+ cacheImportAttrs := map [string ]string {
126
+ "scope" : scope ,
127
+ }
128
+ maps .Copy (cacheImportAttrs , cacheAttrs )
129
+
107
130
_ , err = c .Solve (sb .Context (), def , client.SolveOpt {
108
131
Exports : []client.ExportEntry {
109
132
{
@@ -112,12 +135,8 @@ func testBasicGhaCacheImportExportExtraTimeout(t *testing.T, sb integration.Sand
112
135
},
113
136
},
114
137
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 ,
121
140
}},
122
141
}, nil )
123
142
require .NoError (t , err )
0 commit comments