@@ -19,6 +19,7 @@ import (
19
19
"github.com/go-git/go-git/v5/plumbing/object"
20
20
"github.com/go-git/go-git/v5/plumbing/transport"
21
21
"github.com/go-git/go-git/v5/plumbing/transport/http"
22
+ "github.com/nektos/act/pkg/common"
22
23
)
23
24
24
25
type ActionCache interface {
@@ -31,17 +32,23 @@ type GoGitActionCache struct {
31
32
}
32
33
33
34
func (c GoGitActionCache ) Fetch (ctx context.Context , cacheDir , url , ref , token string ) (string , error ) {
35
+ logger := common .Logger (ctx )
36
+
34
37
gitPath := path .Join (c .Path , safeFilename (cacheDir )+ ".git" )
38
+
39
+ logger .Infof ("GoGitActionCache fetch %s with ref %s at %s" , url , ref , gitPath )
40
+
35
41
gogitrepo , err := git .PlainInit (gitPath , true )
36
42
if errors .Is (err , git .ErrRepositoryAlreadyExists ) {
43
+ logger .Debugf ("GoGitActionCache cache hit %s with ref %s at %s" , url , ref , gitPath )
37
44
gogitrepo , err = git .PlainOpen (gitPath )
38
45
}
39
46
if err != nil {
40
- return "" , err
47
+ return "" , fmt . Errorf ( "GoGitActionCache failed to open bare git %s with ref %s at %s: %w" , url , ref , gitPath , err )
41
48
}
42
49
tmpBranch := make ([]byte , 12 )
43
50
if _ , err := rand .Read (tmpBranch ); err != nil {
44
- return "" , err
51
+ return "" , fmt . Errorf ( "GoGitActionCache failed to generate random tmp branch %s with ref %s at %s: %w" , url , ref , gitPath , err )
45
52
}
46
53
branchName := hex .EncodeToString (tmpBranch )
47
54
@@ -59,7 +66,7 @@ func (c GoGitActionCache) Fetch(ctx context.Context, cacheDir, url, ref, token s
59
66
},
60
67
})
61
68
if err != nil {
62
- return "" , err
69
+ return "" , fmt . Errorf ( "GoGitActionCache failed to create remote %s with ref %s at %s: %w" , url , ref , gitPath , err )
63
70
}
64
71
defer func () {
65
72
_ = gogitrepo .DeleteBranch (branchName )
@@ -71,12 +78,13 @@ func (c GoGitActionCache) Fetch(ctx context.Context, cacheDir, url, ref, token s
71
78
Auth : auth ,
72
79
Force : true ,
73
80
}); err != nil {
74
- return "" , err
81
+ return "" , fmt . Errorf ( "GoGitActionCache failed to fetch %s with ref %s at %s: %w" , url , ref , gitPath , err )
75
82
}
76
83
hash , err := gogitrepo .ResolveRevision (plumbing .Revision (branchName ))
77
84
if err != nil {
78
- return "" , err
85
+ return "" , fmt . Errorf ( "GoGitActionCache failed to resolve sha %s with ref %s at %s: %w" , url , ref , gitPath , err )
79
86
}
87
+ logger .Infof ("GoGitActionCache fetch %s with ref %s at %s resolved to %s" , url , ref , gitPath , hash .String ())
80
88
return hash .String (), nil
81
89
}
82
90
@@ -119,22 +127,27 @@ func (g *GitFileInfo) Sys() any {
119
127
}
120
128
121
129
func (c GoGitActionCache ) GetTarArchive (ctx context.Context , cacheDir , sha , includePrefix string ) (io.ReadCloser , error ) {
130
+ logger := common .Logger (ctx )
131
+
122
132
gitPath := path .Join (c .Path , safeFilename (cacheDir )+ ".git" )
133
+
134
+ logger .Infof ("GoGitActionCache get content %s with sha %s subpath %s at %s" , cacheDir , sha , includePrefix , gitPath )
135
+
123
136
gogitrepo , err := git .PlainOpen (gitPath )
124
137
if err != nil {
125
- return nil , err
138
+ return nil , fmt . Errorf ( "GoGitActionCache failed to open bare git %s with sha %s subpath %s at %s: %w" , cacheDir , sha , includePrefix , gitPath , err )
126
139
}
127
140
commit , err := gogitrepo .CommitObject (plumbing .NewHash (sha ))
128
141
if err != nil {
129
- return nil , err
142
+ return nil , fmt . Errorf ( "GoGitActionCache failed to get commit %s with sha %s subpath %s at %s: %w" , cacheDir , sha , includePrefix , gitPath , err )
130
143
}
131
144
t , err := commit .Tree ()
132
145
if err != nil {
133
- return nil , err
146
+ return nil , fmt . Errorf ( "GoGitActionCache failed to open git tree %s with sha %s subpath %s at %s: %w" , cacheDir , sha , includePrefix , gitPath , err )
134
147
}
135
148
files , err := commit .Files ()
136
149
if err != nil {
137
- return nil , err
150
+ return nil , fmt . Errorf ( "GoGitActionCache failed to list files %s with sha %s subpath %s at %s: %w" , cacheDir , sha , includePrefix , gitPath , err )
138
151
}
139
152
rpipe , wpipe := io .Pipe ()
140
153
// Interrupt io.Copy using ctx
0 commit comments