Skip to content

Commit 4dda81b

Browse files
committed
Add success vs. failure etc for jobs into summary
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent 04b43f2 commit 4dda81b

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

main.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,16 @@ func main() {
5151
totalPublic int
5252
longestBuild time.Duration
5353
actors map[string]bool
54+
conclusion map[string]int
5455
)
5556

5657
actors = make(map[string]bool)
58+
conclusion = map[string]int{
59+
"success": 0,
60+
"failure": 0,
61+
"cancelled": 0,
62+
"skipped": 0,
63+
}
5764

5865
fmt.Printf("Fetching last %d days of data (created>=%s)\n", since, created.Format("2006-01-02"))
5966

@@ -177,6 +184,12 @@ func main() {
177184
if dur > longestBuild {
178185
longestBuild = dur
179186
}
187+
188+
if _, ok := conclusion[job.GetConclusion()]; !ok {
189+
conclusion[job.GetConclusion()] = 0
190+
}
191+
192+
conclusion[job.GetConclusion()]++
180193
}
181194

182195
workflowJobs = append(workflowJobs, jobs.Jobs...)
@@ -207,7 +220,12 @@ func main() {
207220
}
208221
}
209222

210-
fmt.Println("\nUsage report generated by self-actuated/actions-usage.\n")
223+
entity := orgName
224+
if len(orgName) == 0 {
225+
entity = userName
226+
}
227+
228+
fmt.Printf("\nGenerated by: https://github.com/self-actuated/actions-usage\nReport for %s - last: %d days.\n\n", entity, since)
211229
fmt.Printf("Total repos: %d\n", len(allRepos))
212230
fmt.Printf("Total private repos: %d\n", totalPrivate)
213231
fmt.Printf("Total public repos: %d\n", totalPublic)
@@ -216,11 +234,24 @@ func main() {
216234
fmt.Printf("Total workflow jobs: %d\n", totalJobs)
217235
fmt.Println()
218236
fmt.Printf("Total users: %d\n", len(actors))
219-
fmt.Printf("Longest build: %s\n", longestBuild.Round(time.Second))
220-
fmt.Printf("Average build time: %s\n", (allUsage / time.Duration(totalJobs)).Round(time.Second))
237+
238+
if totalJobs > 0 {
239+
fmt.Println()
240+
fmt.Printf("Success: %d/%d\n", conclusion["success"], totalJobs)
241+
fmt.Printf("Failure: %d/%d\n", conclusion["failure"], totalJobs)
242+
fmt.Printf("Cancelled: %d/%d\n", conclusion["cancelled"], totalJobs)
243+
if conclusion["skipped"] > 0 {
244+
fmt.Printf("Skipped: %d/%d\n", conclusion["skipped"], totalJobs)
245+
}
246+
fmt.Println()
247+
fmt.Printf("Longest build: %s\n", longestBuild.Round(time.Second))
248+
fmt.Printf("Average build time: %s\n", (allUsage / time.Duration(totalJobs)).Round(time.Second))
249+
}
250+
fmt.Println()
221251

222252
mins := fmt.Sprintf("%.0f mins", allUsage.Minutes())
223253
fmt.Printf("Total usage: %s (%s)\n", allUsage.String(), mins)
254+
fmt.Println()
224255
}
225256

226257
// types.HumanDuration fixes a long string for a value < 1s

0 commit comments

Comments
 (0)