github.com/nektos/act@v0.2.63/pkg/runner/action_cache_offline_mode.go (about) 1 package runner 2 3 import ( 4 "context" 5 "io" 6 "path" 7 8 git "github.com/go-git/go-git/v5" 9 "github.com/go-git/go-git/v5/plumbing" 10 ) 11 12 type GoGitActionCacheOfflineMode struct { 13 Parent GoGitActionCache 14 } 15 16 func (c GoGitActionCacheOfflineMode) Fetch(ctx context.Context, cacheDir, url, ref, token string) (string, error) { 17 sha, fetchErr := c.Parent.Fetch(ctx, cacheDir, url, ref, token) 18 gitPath := path.Join(c.Parent.Path, safeFilename(cacheDir)+".git") 19 gogitrepo, err := git.PlainOpen(gitPath) 20 if err != nil { 21 return "", fetchErr 22 } 23 refName := plumbing.ReferenceName("refs/action-cache-offline/" + ref) 24 r, err := gogitrepo.Reference(refName, true) 25 if fetchErr == nil { 26 if err != nil || sha != r.Hash().String() { 27 if err == nil { 28 refName = r.Name() 29 } 30 ref := plumbing.NewHashReference(refName, plumbing.NewHash(sha)) 31 _ = gogitrepo.Storer.SetReference(ref) 32 } 33 } else if err == nil { 34 return r.Hash().String(), nil 35 } 36 return sha, fetchErr 37 } 38 39 func (c GoGitActionCacheOfflineMode) GetTarArchive(ctx context.Context, cacheDir, sha, includePrefix string) (io.ReadCloser, error) { 40 return c.Parent.GetTarArchive(ctx, cacheDir, sha, includePrefix) 41 }