MCPcopy
hub / github.com/nektos/act / getHashFilesFunction

Function getHashFilesFunction

pkg/runner/expression.go:170–229  ·  view source on GitHub ↗
(ctx context.Context, rc *RunContext)

Source from the content-addressed store, hash-verified

168}
169
170func getHashFilesFunction(ctx context.Context, rc *RunContext) func(v []reflect.Value) (interface{}, error) {
171 hashFiles := func(v []reflect.Value) (interface{}, error) {
172 if rc.JobContainer != nil {
173 timeed, cancel := context.WithTimeout(ctx, time.Minute)
174 defer cancel()
175 name := "workflow/hashfiles/index.js"
176 hout := &bytes.Buffer{}
177 herr := &bytes.Buffer{}
178 patterns := []string{}
179 followSymlink := false
180
181 for i, p := range v {
182 s := p.String()
183 if i == 0 {
184 if strings.HasPrefix(s, "--") {
185 if strings.EqualFold(s, "--follow-symbolic-links") {
186 followSymlink = true
187 continue
188 }
189 return "", fmt.Errorf("Invalid glob option %s, available option: '--follow-symbolic-links'", s)
190 }
191 }
192 patterns = append(patterns, s)
193 }
194 env := map[string]string{}
195 for k, v := range rc.Env {
196 env[k] = v
197 }
198 env["patterns"] = strings.Join(patterns, "\n")
199 if followSymlink {
200 env["followSymbolicLinks"] = "true"
201 }
202
203 stdout, stderr := rc.JobContainer.ReplaceLogWriter(hout, herr)
204 _ = rc.JobContainer.Copy(rc.JobContainer.GetActPath(), &container.FileEntry{
205 Name: name,
206 Mode: 0o644,
207 Body: hashfiles,
208 }).
209 Then(rc.execJobContainer([]string{rc.GetNodeToolFullPath(ctx), path.Join(rc.JobContainer.GetActPath(), name)},
210 env, "", "")).
211 Finally(func(context.Context) error {
212 rc.JobContainer.ReplaceLogWriter(stdout, stderr)
213 return nil
214 })(timeed)
215 output := hout.String() + "\n" + herr.String()
216 guard := "__OUTPUT__"
217 outstart := strings.Index(output, guard)
218 if outstart != -1 {
219 outstart += len(guard)
220 outend := strings.Index(output[outstart:], guard)
221 if outend != -1 {
222 return output[outstart : outstart+outend], nil
223 }
224 }
225 }
226 return "", nil
227 }

Callers 2

Calls 8

FinallyMethod · 0.80
ThenMethod · 0.80
execJobContainerMethod · 0.80
GetNodeToolFullPathMethod · 0.80
ReplaceLogWriterMethod · 0.65
CopyMethod · 0.65
GetActPathMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…