Skip to content

Commit c24c88d

Browse files
committed
Update cmd
1 parent f1c42a4 commit c24c88d

File tree

1 file changed

+16
-48
lines changed

1 file changed

+16
-48
lines changed

tools/flakeguard/cmd/generate_github_report.go

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8-
"time"
98

10-
"github.com/briandowns/spinner"
119
"github.com/rs/zerolog/log"
1210
"github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/reports"
1311
"github.com/spf13/cobra"
@@ -21,41 +19,27 @@ var GenerateReportCmd = &cobra.Command{
2119

2220
// Get flag values
2321
flakeguardReportPath, _ := cmd.Flags().GetString("flakeguard-report")
24-
outputDir, _ := cmd.Flags().GetString("output-path")
22+
outputDir, _ := cmd.Flags().GetString("output-dir")
2523
maxPassRatio, _ := cmd.Flags().GetFloat64("max-pass-ratio")
2624
generatePRComment, _ := cmd.Flags().GetBool("generate-pr-comment")
2725
failedLogsURL, _ := cmd.Flags().GetString("failed-logs-url")
2826

2927
failedLogsArtifactName := "failed-test-results-with-logs.json"
3028

31-
initialDirSize, err := getDirSize(outputDir)
32-
if err != nil {
33-
log.Error().Err(err).Str("path", outputDir).Msg("Error getting initial directory size")
34-
// intentionally don't exit here, as we can still proceed with the generation
35-
}
36-
37-
// Load the aggregated report
38-
s := spinner.New(spinner.CharSets[11], 100*time.Millisecond)
39-
s.Suffix = " Loading flakeguard test report..."
40-
s.Start()
41-
42-
testReport := reports.TestReport{}
29+
testReport := &reports.TestReport{}
4330
reportFile, err := os.Open(flakeguardReportPath)
4431
if err != nil {
45-
s.Stop()
4632
fmt.Println()
4733
log.Error().Err(err).Msg("Error opening aggregated test report")
4834
os.Exit(ErrorExitCode)
4935
}
5036
defer reportFile.Close()
5137

5238
if err := json.NewDecoder(reportFile).Decode(testReport); err != nil {
53-
s.Stop()
5439
fmt.Println()
5540
log.Error().Err(err).Msg("Error decoding aggregated test report")
5641
os.Exit(ErrorExitCode)
5742
}
58-
s.Stop()
5943
fmt.Println()
6044
log.Info().Msg("Successfully loaded aggregated test report")
6145

@@ -66,20 +50,18 @@ var GenerateReportCmd = &cobra.Command{
6650
}
6751

6852
// Generate GitHub summary markdown
69-
s = spinner.New(spinner.CharSets[11], 100*time.Millisecond)
70-
s.Suffix = " Generating GitHub summary markdown..."
71-
s.Start()
7253

73-
err = generateGitHubSummaryMarkdown(testReport, filepath.Join(outputDir, "all-test"), failedLogsURL, failedLogsArtifactName)
54+
summaryPath := filepath.Join(outputDir, "all-tests-summary.md")
55+
err = generateGitHubSummaryMarkdown(*testReport, summaryPath, failedLogsURL, failedLogsArtifactName)
7456
if err != nil {
75-
s.Stop()
7657
fmt.Println()
7758
log.Error().Err(err).Msg("Error generating GitHub summary markdown")
7859
os.Exit(ErrorExitCode)
7960
}
80-
s.Stop()
8161
fmt.Println()
82-
log.Info().Msg("GitHub summary markdown generated successfully")
62+
log.Info().
63+
Str("path", summaryPath).
64+
Msg("GitHub summary markdown generated successfully")
8365

8466
if generatePRComment {
8567
// Retrieve required flags
@@ -108,14 +90,10 @@ var GenerateReportCmd = &cobra.Command{
10890
os.Exit(ErrorExitCode)
10991
}
11092

111-
// Generate PR comment markdown
112-
s = spinner.New(spinner.CharSets[11], 100*time.Millisecond)
113-
s.Suffix = " Generating PR comment markdown..."
114-
s.Start()
115-
93+
prCommentPath := filepath.Join(outputDir, "all-tests-pr-comment.md")
11694
err = generatePRCommentMarkdown(
117-
testReport,
118-
filepath.Join(outputDir, "all-test"),
95+
*testReport,
96+
filepath.Join(outputDir, prCommentPath),
11997
baseBranch,
12098
currentBranch,
12199
currentCommitSHA,
@@ -126,29 +104,21 @@ var GenerateReportCmd = &cobra.Command{
126104
maxPassRatio,
127105
)
128106
if err != nil {
129-
s.Stop()
130107
fmt.Println()
131108
log.Error().Err(err).Msg("Error generating PR comment markdown")
132109
os.Exit(ErrorExitCode)
133110
}
134-
s.Stop()
135111
fmt.Println()
136-
log.Info().Msg("PR comment markdown generated successfully")
137-
}
138-
139-
finalDirSize, err := getDirSize(outputDir)
140-
if err != nil {
141-
log.Error().Err(err).Str("path", outputDir).Msg("Error getting initial directory size")
142-
// intentionally don't exit here, as we can still proceed with the generation
112+
log.Info().
113+
Str("path", prCommentPath).
114+
Msg("PR comment markdown generated successfully")
143115
}
144-
diskSpaceUsed := byteCountSI(finalDirSize - initialDirSize)
145-
log.Info().Str("disk space used", diskSpaceUsed).Str("output", outputDir).Msg("Reports generated successfully")
146116
},
147117
}
148118

149119
func init() {
150120
GenerateReportCmd.Flags().StringP("flakeguard-report", "i", "", "Path to the flakeguard test report JSON file (required)")
151-
GenerateReportCmd.Flags().StringP("output-path", "o", "./report", "Path to output the generated report files")
121+
GenerateReportCmd.Flags().StringP("output-dir", "o", "./report", "Path to output the generated report files")
152122
GenerateReportCmd.Flags().Float64P("max-pass-ratio", "", 1.0, "The maximum pass ratio threshold for a test to be considered flaky")
153123
GenerateReportCmd.Flags().Bool("generate-pr-comment", false, "Set to true to generate PR comment markdown")
154124
GenerateReportCmd.Flags().String("base-branch", "develop", "The base branch to compare against (used in PR comment)")
@@ -168,8 +138,7 @@ func init() {
168138

169139
func generateGitHubSummaryMarkdown(report reports.TestReport, outputPath, artifactLink, artifactName string) error {
170140
fs := reports.OSFileSystem{}
171-
mdFileName := outputPath + "-summary.md"
172-
mdFile, err := fs.Create(mdFileName)
141+
mdFile, err := fs.Create(outputPath)
173142
if err != nil {
174143
return fmt.Errorf("error creating GitHub summary markdown file: %w", err)
175144
}
@@ -194,8 +163,7 @@ func generatePRCommentMarkdown(
194163
maxPassRatio float64,
195164
) error {
196165
fs := reports.OSFileSystem{}
197-
mdFileName := outputPath + "-pr-comment.md"
198-
mdFile, err := fs.Create(mdFileName)
166+
mdFile, err := fs.Create(outputPath)
199167
if err != nil {
200168
return fmt.Errorf("error creating PR comment markdown file: %w", err)
201169
}

0 commit comments

Comments
 (0)