github.com/nektos/act@v0.2.83/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 "github.com/nektos/act/pkg/common" 11 ) 12 13 type GoGitActionCacheOfflineMode struct { 14 Parent GoGitActionCache 15 } 16 17 func (c GoGitActionCacheOfflineMode) Fetch(ctx context.Context, cacheDir, url, ref, token string) (string, error) { 18 logger := common.Logger(ctx) 19 20 gitPath := path.Join(c.Parent.Path, safeFilename(cacheDir)+".git") 21 22 logger.Infof("GoGitActionCacheOfflineMode fetch content %s with ref %s at %s", url, ref, gitPath) 23 24 sha, fetchErr := c.Parent.Fetch(ctx, cacheDir, url, ref, token) 25 gogitrepo, err := git.PlainOpen(gitPath) 26 if err != nil { 27 return "", fetchErr 28 } 29 refName := plumbing.ReferenceName("refs/action-cache-offline/" + ref) 30 r, err := gogitrepo.Reference(refName, true) 31 if fetchErr == nil { 32 if err != nil || sha != r.Hash().String() { 33 if err == nil { 34 refName = r.Name() 35 } 36 ref := plumbing.NewHashReference(refName, plumbing.NewHash(sha)) 37 _ = gogitrepo.Storer.SetReference(ref) 38 } 39 } else if err == nil { 40 return r.Hash().String(), nil 41 } 42 return sha, fetchErr 43 } 44 45 func (c GoGitActionCacheOfflineMode) GetTarArchive(ctx context.Context, cacheDir, sha, includePrefix string) (io.ReadCloser, error) { 46 return c.Parent.GetTarArchive(ctx, cacheDir, sha, includePrefix) 47 }