Skip to content

Commit

Permalink
Add success vs. failure etc for jobs into summary
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Apr 6, 2023
1 parent 04b43f2 commit 4dda81b
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@ func main() {
totalPublic int
longestBuild time.Duration
actors map[string]bool
conclusion map[string]int
)

actors = make(map[string]bool)
conclusion = map[string]int{
"success": 0,
"failure": 0,
"cancelled": 0,
"skipped": 0,
}

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

Expand Down Expand Up @@ -177,6 +184,12 @@ func main() {
if dur > longestBuild {
longestBuild = dur
}

if _, ok := conclusion[job.GetConclusion()]; !ok {
conclusion[job.GetConclusion()] = 0
}

conclusion[job.GetConclusion()]++
}

workflowJobs = append(workflowJobs, jobs.Jobs...)
Expand Down Expand Up @@ -207,7 +220,12 @@ func main() {
}
}

fmt.Println("\nUsage report generated by self-actuated/actions-usage.\n")
entity := orgName
if len(orgName) == 0 {
entity = userName
}

fmt.Printf("\nGenerated by: https://github.com/self-actuated/actions-usage\nReport for %s - last: %d days.\n\n", entity, since)
fmt.Printf("Total repos: %d\n", len(allRepos))
fmt.Printf("Total private repos: %d\n", totalPrivate)
fmt.Printf("Total public repos: %d\n", totalPublic)
Expand All @@ -216,11 +234,24 @@ func main() {
fmt.Printf("Total workflow jobs: %d\n", totalJobs)
fmt.Println()
fmt.Printf("Total users: %d\n", len(actors))
fmt.Printf("Longest build: %s\n", longestBuild.Round(time.Second))
fmt.Printf("Average build time: %s\n", (allUsage / time.Duration(totalJobs)).Round(time.Second))

if totalJobs > 0 {
fmt.Println()
fmt.Printf("Success: %d/%d\n", conclusion["success"], totalJobs)
fmt.Printf("Failure: %d/%d\n", conclusion["failure"], totalJobs)
fmt.Printf("Cancelled: %d/%d\n", conclusion["cancelled"], totalJobs)
if conclusion["skipped"] > 0 {
fmt.Printf("Skipped: %d/%d\n", conclusion["skipped"], totalJobs)
}
fmt.Println()
fmt.Printf("Longest build: %s\n", longestBuild.Round(time.Second))
fmt.Printf("Average build time: %s\n", (allUsage / time.Duration(totalJobs)).Round(time.Second))
}
fmt.Println()

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

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

0 comments on commit 4dda81b

Please sign in to comment.