MCPcopy Index your code
hub / github.com/coder/coder / run

Function run

scripts/gotestsummary/main.go:85–140  ·  view source on GitHub ↗
(ctx context.Context, cfg config, stdout, stderr io.Writer, getenv func(string) string)

Source from the content-addressed store, hash-verified

83}
84
85func run(ctx context.Context, cfg config, stdout, stderr io.Writer, getenv func(string) string) error {
86 if cfg.JSONFile == "" {
87 return xerrors.New("--jsonfile is required")
88 }
89 if cfg.MarkdownOut == "" {
90 cfg.MarkdownOut = "-"
91 }
92 if cfg.MaxOutputBytes < 0 {
93 return xerrors.New("--max-output-bytes must be non-negative")
94 }
95 if cfg.MaxFailures < 0 {
96 return xerrors.New("--max-failures must be non-negative")
97 }
98 if cfg.FailuresCapBytes <= 0 {
99 cfg.FailuresCapBytes = defaultFailuresCapBytes
100 }
101
102 stat, err := os.Stat(cfg.JSONFile)
103 if err != nil {
104 if errors.Is(err, os.ErrNotExist) {
105 return writeEmptyOutputs(cfg)
106 }
107 return xerrors.Errorf("stat json file: %w", err)
108 }
109 if stat.Size() == 0 {
110 return writeEmptyOutputs(cfg)
111 }
112
113 file, err := os.Open(cfg.JSONFile)
114 if err != nil {
115 return xerrors.Errorf("open json file: %w", err)
116 }
117 defer file.Close()
118
119 result, err := summarize(ctx, file, cfg.MaxOutputBytes, stderr)
120 if err != nil {
121 return err
122 }
123 if cfg.FailuresOut != "" {
124 if err := writeFailuresNDJSON(cfg.FailuresOut, result.Failures, cfg.FailuresCapBytes); err != nil {
125 return err
126 }
127 }
128 if len(result.Failures) == 0 {
129 if cfg.MarkdownOut != "-" {
130 return os.WriteFile(cfg.MarkdownOut, nil, 0o600)
131 }
132 return nil
133 }
134 markdown := renderMarkdown(result, cfg.MaxFailures, cfg.FailuresOut, getenv("GITHUB_JOB"))
135 if cfg.MarkdownOut == "-" {
136 _, err = io.WriteString(stdout, markdown)
137 return err
138 }
139 return os.WriteFile(cfg.MarkdownOut, []byte(markdown), 0o600)
140}
141
142func writeEmptyOutputs(cfg config) error {

Callers 4

runMarkdownFunction · 0.70
mainFunction · 0.70

Calls 12

writeEmptyOutputsFunction · 0.85
summarizeFunction · 0.85
writeFailuresNDJSONFunction · 0.85
renderMarkdownFunction · 0.85
SizeMethod · 0.80
WriteStringMethod · 0.80
NewMethod · 0.65
CloseMethod · 0.65
WriteFileMethod · 0.65
IsMethod · 0.45
ErrorfMethod · 0.45
OpenMethod · 0.45