|
1 | 1 | package runner
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "archive/tar" |
4 | 5 | "context"
|
5 | 6 | "errors"
|
6 | 7 | "fmt"
|
@@ -28,6 +29,8 @@ type stepActionRemote struct {
|
28 | 29 | action *model.Action
|
29 | 30 | env map[string]string
|
30 | 31 | remoteAction *remoteAction
|
| 32 | + cacheDir string |
| 33 | + resolvedSha string |
31 | 34 | }
|
32 | 35 |
|
33 | 36 | var (
|
@@ -60,6 +63,46 @@ func (sar *stepActionRemote) prepareActionExecutor() common.Executor {
|
60 | 63 | github.Token = sar.RunContext.Config.ReplaceGheActionTokenWithGithubCom
|
61 | 64 | }
|
62 | 65 | }
|
| 66 | + if sar.RunContext.Config.ActionCache != nil { |
| 67 | + cache := sar.RunContext.Config.ActionCache |
| 68 | + |
| 69 | + var err error |
| 70 | + sar.cacheDir = fmt.Sprintf("%s/%s", sar.remoteAction.Org, sar.remoteAction.Repo) |
| 71 | + sar.resolvedSha, err = cache.Fetch(ctx, sar.cacheDir, sar.remoteAction.URL+"/"+sar.cacheDir, sar.remoteAction.Ref, github.Token) |
| 72 | + if err != nil { |
| 73 | + return err |
| 74 | + } |
| 75 | + |
| 76 | + remoteReader := func(ctx context.Context) actionYamlReader { |
| 77 | + return func(filename string) (io.Reader, io.Closer, error) { |
| 78 | + spath := filename |
| 79 | + for i := 0; i < maxSymlinkDepth; i++ { |
| 80 | + tars, err := cache.GetTarArchive(ctx, sar.cacheDir, sar.resolvedSha, spath) |
| 81 | + if err != nil { |
| 82 | + return nil, nil, os.ErrNotExist |
| 83 | + } |
| 84 | + treader := tar.NewReader(tars) |
| 85 | + header, err := treader.Next() |
| 86 | + if err != nil { |
| 87 | + return nil, nil, os.ErrNotExist |
| 88 | + } |
| 89 | + if header.FileInfo().Mode()&os.ModeSymlink == os.ModeSymlink { |
| 90 | + spath, err = symlinkJoin(spath, header.Linkname, ".") |
| 91 | + if err != nil { |
| 92 | + return nil, nil, err |
| 93 | + } |
| 94 | + } else { |
| 95 | + return treader, tars, nil |
| 96 | + } |
| 97 | + } |
| 98 | + return nil, nil, fmt.Errorf("max depth %d of symlinks exceeded while reading %s", maxSymlinkDepth, spath) |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + actionModel, err := sar.readAction(ctx, sar.Step, sar.resolvedSha, sar.remoteAction.Path, remoteReader(ctx), os.WriteFile) |
| 103 | + sar.action = actionModel |
| 104 | + return err |
| 105 | + } |
63 | 106 |
|
64 | 107 | actionDir := fmt.Sprintf("%s/%s", sar.RunContext.ActionCacheDir(), safeFilename(sar.Step.Uses))
|
65 | 108 | gitClone := stepActionRemoteNewCloneExecutor(git.NewGitCloneExecutorInput{
|
|
0 commit comments