Skip to content

Commit

Permalink
allow exporting to github cache backend
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Feb 6, 2021
1 parent 42b7e7b commit 74f47e8
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions build/cache.go
Expand Up @@ -2,6 +2,7 @@ package build

import (
"encoding/csv"
"os"
"strings"

"github.com/moby/buildkit/client"
Expand Down Expand Up @@ -45,6 +46,9 @@ func ParseCacheEntry(in []string) ([]client.CacheOptionsEntry, error) {
if im.Type == "" {
return nil, errors.Errorf("type required form> %q", in)
}
if !addGithubToken(&im) {
continue
}
imports = append(imports, im)
}
return imports, nil
Expand All @@ -58,3 +62,20 @@ func isRefOnlyFormat(in []string) bool {
}
return true
}

func addGithubToken(ci *client.CacheOptionsEntry) bool {
if ci.Type != "gha" {
return true
}
if _, ok := ci.Attrs["token"]; !ok {
if v, ok := os.LookupEnv("ACTIONS_RUNTIME_TOKEN"); ok {
ci.Attrs["token"] = v
}
}
if _, ok := ci.Attrs["url"]; !ok {
if v, ok := os.LookupEnv("ACTIONS_CACHE_URL"); ok {
ci.Attrs["url"] = v
}
}
return ci.Attrs["token"] != "" && ci.Attrs["url"] != ""
}

0 comments on commit 74f47e8

Please sign in to comment.