-
Notifications
You must be signed in to change notification settings - Fork 199
/
output_file.go
51 lines (40 loc) · 1.04 KB
/
output_file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package builder
import (
"fmt"
"get.porter.sh/porter/pkg/portercontext"
"github.com/pkg/errors"
)
type OutputFile interface {
Output
GetFilePath() string
}
// ProcessFileOutputs makes the contents of a file specified by any OutputFile interface available as an output.
func ProcessFileOutputs(cxt *portercontext.Context, step StepWithOutputs) error {
outputs := step.GetOutputs()
if len(outputs) == 0 {
return nil
}
for _, o := range outputs {
output, ok := o.(OutputFile)
if !ok {
continue
}
outputName := output.GetName()
outputPath := output.GetFilePath()
if outputPath == "" {
continue
}
if cxt.Debug {
fmt.Fprintf(cxt.Err, "Processing file output %s...", outputName)
}
valueB, err := cxt.FileSystem.ReadFile(outputPath)
if err != nil {
return errors.Wrapf(err, "error evaluating filepath %q for output %q", outputPath, outputName)
}
err = cxt.WriteMixinOutputToFile(outputName, valueB)
if err != nil {
return errors.Wrapf(err, "error writing mixin output for %q", outputName)
}
}
return nil
}