Skip to content

Commit

Permalink
Merge pull request #3001 from crazy-max/fix-gha-cache-v2
Browse files Browse the repository at this point in the history
cache: enable gha cache backend if cache service v2 detected
  • Loading branch information
crazy-max authored Feb 18, 2025
2 parents 52f503e + f799203 commit b04d394
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions util/buildflags/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func addGithubToken(ci *controllerapi.CacheOptionsEntry) {
}
version, ok := ci.Attrs["version"]
if !ok {
// https://github.com/actions/toolkit/blob/2b08dc18f261b9fdd978b70279b85cbef81af8bc/packages/cache/src/internal/config.ts#L19
if v, ok := os.LookupEnv("ACTIONS_CACHE_SERVICE_V2"); ok {
if b, err := strconv.ParseBool(v); err == nil && b {
version = "2"
Expand All @@ -218,15 +219,18 @@ func addGithubToken(ci *controllerapi.CacheOptionsEntry) {
ci.Attrs["token"] = v
}
}
if _, ok := ci.Attrs["url_v2"]; !ok && version == "2" {
// https://github.com/actions/toolkit/blob/2b08dc18f261b9fdd978b70279b85cbef81af8bc/packages/cache/src/internal/config.ts#L34-L35
if v, ok := os.LookupEnv("ACTIONS_RESULTS_URL"); ok {
ci.Attrs["url_v2"] = v
}
}
if _, ok := ci.Attrs["url"]; !ok {
if version == "2" {
if v, ok := os.LookupEnv("ACTIONS_RESULTS_URL"); ok {
ci.Attrs["url_v2"] = v
}
} else {
if v, ok := os.LookupEnv("ACTIONS_CACHE_URL"); ok {
ci.Attrs["url"] = v
}
// https://github.com/actions/toolkit/blob/2b08dc18f261b9fdd978b70279b85cbef81af8bc/packages/cache/src/internal/config.ts#L28-L33
if v, ok := os.LookupEnv("ACTIONS_CACHE_URL"); ok {
ci.Attrs["url"] = v
} else if v, ok := os.LookupEnv("ACTIONS_RESULTS_URL"); ok {
ci.Attrs["url"] = v
}
}
}
Expand Down Expand Up @@ -266,5 +270,5 @@ func isActive(pb *controllerapi.CacheOptionsEntry) bool {
if pb.Type != "gha" {
return true
}
return pb.Attrs["token"] != "" && pb.Attrs["url"] != ""
return pb.Attrs["token"] != "" && (pb.Attrs["url"] != "" || pb.Attrs["url_v2"] != "")
}

0 comments on commit b04d394

Please sign in to comment.