Skip to content

Commit 3c20a7c

Browse files
authored
Merge pull request moby#5735 from tonistiigi/gha-url-v2
gha: allow url_v2 input attribute
2 parents 280ebbf + dea6c49 commit 3c20a7c

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

cache/remotecache/gha/gha.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const (
3939
attrTimeout = "timeout"
4040
attrToken = "token"
4141
attrURL = "url"
42+
attrURLV2 = "url_v2"
4243
attrRepository = "repository"
4344
attrGHToken = "ghtoken"
4445
attrAPIVersion = "version"
@@ -79,6 +80,12 @@ func getConfig(attrs map[string]string) (*Config, error) {
7980
}
8081
apiVersionInt = int(i)
8182
}
83+
if apiVersionInt != 1 {
84+
if v, ok := attrs[attrURLV2]; ok {
85+
url = v
86+
apiVersionInt = 2
87+
}
88+
}
8289
// best effort on old clients
8390
if apiVersionInt == 0 {
8491
if strings.Contains(url, "results-receiver.actions.githubusercontent.com") {

cmd/buildctl/build/util.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,23 @@ func loadGithubEnv(cache client.CacheOptionsEntry) (client.CacheOptionsEntry, er
2121
if v, ok := os.LookupEnv("ACTIONS_CACHE_SERVICE_V2"); ok {
2222
if b, err := strconv.ParseBool(v); err == nil && b {
2323
version = "2"
24-
cache.Attrs["version"] = version
2524
}
2625
}
2726
}
2827

28+
if _, ok := cache.Attrs["url_v2"]; !ok && version == "2" {
29+
url, ok := os.LookupEnv("ACTIONS_RESULTS_URL")
30+
if !ok {
31+
return cache, errors.New("cache with type gha requires url parameter or $ACTIONS_RESULTS_URL")
32+
}
33+
cache.Attrs["url_v2"] = url
34+
}
2935
if _, ok := cache.Attrs["url"]; !ok {
30-
if version == "2" {
31-
url, ok := os.LookupEnv("ACTIONS_RESULTS_URL")
32-
if !ok {
33-
return cache, errors.New("cache with type gha requires url parameter or $ACTIONS_RESULTS_URL")
34-
}
35-
cache.Attrs["url"] = url
36-
} else {
37-
url, ok := os.LookupEnv("ACTIONS_CACHE_URL")
38-
if !ok {
39-
return cache, errors.New("cache with type gha requires url parameter or $ACTIONS_CACHE_URL")
40-
}
41-
cache.Attrs["url"] = url
36+
url, ok := os.LookupEnv("ACTIONS_CACHE_URL")
37+
if !ok {
38+
return cache, errors.New("cache with type gha requires url parameter or $ACTIONS_CACHE_URL")
4239
}
40+
cache.Attrs["url"] = url
4341
}
4442

4543
if _, ok := cache.Attrs["token"]; !ok {

0 commit comments

Comments
 (0)