Skip to content

Commit

Permalink
Add additional report data
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 Mar 17, 2023
1 parent afdf7ab commit 2654b91
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ func main() {
totalJobs int
totalPrivate int
totalPublic int
longestBuild time.Duration
actors map[string]bool
)

actors = make(map[string]bool)

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

var repos, allRepos []*github.Repository
Expand Down Expand Up @@ -154,6 +158,9 @@ func main() {
log.Printf("Fetching jobs for: run ID: %d, startedAt: %s, conclusion: %s", run.GetID(), run.GetRunStartedAt().Format("2006-01-02 15:04:05"), run.GetConclusion())
workflowJobs := []*github.WorkflowJob{}

if a := run.GetActor(); a != nil {
actors[a.GetLogin()] = true
}
page := 0
for {
log.Printf("Fetching jobs for: %d, page %d", run.GetID(), page)
Expand All @@ -165,6 +172,13 @@ func main() {
log.Fatal(err)
}

for _, job := range jobs.Jobs {
dur := job.GetCompletedAt().Time.Sub(job.GetStartedAt().Time)
if dur > longestBuild {
longestBuild = dur
}
}

workflowJobs = append(workflowJobs, jobs.Jobs...)

if len(jobs.Jobs) == 0 {
Expand Down Expand Up @@ -193,12 +207,18 @@ func main() {
}
}

fmt.Println("\nUsage report generated by self-actuated/actions-usage.\n")
fmt.Printf("Total repos: %d\n", len(allRepos))
fmt.Printf("Total private repos: %d\n", totalPrivate)
fmt.Printf("Total public repos: %d\n", totalPublic)
fmt.Println()
fmt.Printf("Total workflow runs: %d\n", totalRuns)
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))

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

0 comments on commit 2654b91

Please sign in to comment.