From 078fb1a9353b5b0d3d599d3cb99c1050bdeb4cc6 Mon Sep 17 00:00:00 2001 From: Madhav Jivrajani Date: Wed, 21 Jun 2023 18:58:35 +0530 Subject: [PATCH] generator: Refactor to make github API calls only when needed Currently, everytime the verify job is run, API calls are made to github to fetch kubernetes release information since verify calls generate first. The issue with this is that everytime this runs in the CI, eventhough we only generate annual reports when ANNUAL_REPORT env is set, the API calls are made and if they are rate limited (since we don't use a token here), the job will fail without a legitamate reason. Signed-off-by: Madhav Jivrajani --- generator/app.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/generator/app.go b/generator/app.go index 9ac82530c..462ddb69a 100644 --- a/generator/app.go +++ b/generator/app.go @@ -999,11 +999,11 @@ func getCategorizedWorkingGroups(dir string) (map[string][]string, error) { return workingGroupsMap, nil } -func main() { - // prep for automated listing of subprojects in the annual report +// prep for automated listing of subprojects in the annual report +func prepForAnnualReportGeneration() error { intLastYear, err := strconv.Atoi(lastYear()) if err != nil { - log.Fatal(err) + return err } annualReportYear = time.Date(intLastYear, time.January, 1, 0, 0, 0, 0, time.UTC) currentYear = time.Date(intLastYear+1, time.January, 1, 0, 0, 0, 0, time.UTC) @@ -1015,35 +1015,39 @@ func main() { URL: communityRepoURL, }) } else { - log.Fatal(err) + return err } } commitFromAnnualReportYear, err = getCommitByDate(repo, annualReportYear) if err != nil { - log.Fatal(err) + return err } commitFromCurrentYear, err = getCommitByDate(repo, currentYear) if err != nil { - log.Fatal(err) + return err } // fetch KEPs and cache them in the keps variable err = fetchKEPs() if err != nil { - log.Fatal(err) + return err } releases, err = getLastThreeK8sReleases() if err != nil { - log.Fatal(err) + return err } + return nil +} + +func main() { yamlPath := filepath.Join(baseGeneratorDir, sigsYamlFile) var ctx Context - err = readYaml(yamlPath, &ctx) + err := readYaml(yamlPath, &ctx) if err != nil { log.Fatal(err) } @@ -1076,6 +1080,9 @@ func main() { } if envVal, ok := os.LookupEnv("ANNUAL_REPORT"); ok && envVal == "true" { + if err := prepForAnnualReportGeneration(); err != nil { + log.Fatal(err) + } fmt.Println("Generating annual reports") for prefix, groups := range ctx.PrefixToGroupMap() { err = createAnnualReportIssue(groups, prefix)