func main()

in linter/main.go [324:439]


func main() {
	var jobConfig config.JobConfig
	presubmitErrors := make(map[string][]string)
	postsubmitErrors := make(map[string][]string)

	presubmitConstants := new(JobConstants)
	presubmitConstants.Init("presubmit")
	postsubmitConstants := new(JobConstants)
	postsubmitConstants.Init("postsubmit")

	pullBaseSha := os.Getenv("PULL_BASE_SHA")
	pullPullSha := os.Getenv("PULL_PULL_SHA")

	gitRootOutput, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
	if err != nil {
		log.Fatalf("There was an error running the git command: %v", err)
	}
	gitRoot := strings.Fields(string(gitRootOutput))[0]

	jobNamesCount, err := getJobNamesMap(gitRoot)
	if err != nil {
		log.Fatalf("There was an error getting the job names count: %v", err)
	}

	presubmitFiles, postsubmitFiles, err := getFilesChanged(gitRoot, pullBaseSha, pullPullSha)
	if err != nil {
		log.Fatalf("There was an error running the git command: %v", err)
	}

	presubmitCheckFunctions := []presubmitCheck{
		AlwaysRunCheck(),
		PresubmitClusterCheck(presubmitConstants),
		SkipReportCheck(),
		PresubmitBucketCheck(presubmitConstants),
		PresubmitServiceAccountCheck(presubmitConstants),
		PresubmitMakeTargetCheck(presubmitConstants),
		PresubmitNameDuplicationCheck(jobNamesCount),
	}

	postsubmitCheckFunctions := []postsubmitCheck{
		PostsubmitClusterCheck(postsubmitConstants),
		PostsubmitBucketCheck(postsubmitConstants),
		PostsubmitMakeTargetCheck(postsubmitConstants),
		PostsubmitNameDuplicationCheck(jobNamesCount),
	}

	for _, presubmitFile := range presubmitFiles {
		unmarshaledJobConfig, fileReadError, fileUnmarshalError := unmarshalJobFile(gitRoot, presubmitFile, &jobConfig)

		// Skip linting if file is not found
		if unmarshaledJobConfig == nil {
			continue
		}
		if fileReadError != nil {
			log.Fatalf("Error reading contents of %s: %v", presubmitFile, fileReadError)
		}
		if fileUnmarshalError != nil {
			log.Fatalf("Error unmarshaling contents of %s: %v", presubmitFile, fileUnmarshalError)
		}

		presubmitConfigs, ok := unmarshaledJobConfig.ProwjobConfig.PresubmitsStatic[unmarshaledJobConfig.GithubRepo]
		if !ok {
			log.Fatalf("Key %s does not exist in Presubmit configuration map", unmarshaledJobConfig.GithubRepo)
		}
		if len(presubmitConfigs) < 1 {
			log.Fatalf("Presubmit configuration for the %s repo is empty", unmarshaledJobConfig.GithubRepo)
		}
		presubmitConfig := presubmitConfigs[0]
		for _, check := range presubmitCheckFunctions {
			passed, lineNum, errMessage := check(presubmitConfig, unmarshaledJobConfig.FileContents)
			if !passed {
				errorString := fmt.Sprintf("%d\t%s", lineNum, errMessage)
				presubmitErrors[unmarshaledJobConfig.FileName] = append(presubmitErrors[unmarshaledJobConfig.FileName], errorString)
			}
		}
	}

	for _, postsubmitFile := range postsubmitFiles {
		unmarshaledJobConfig, fileReadError, fileUnmarshalError := unmarshalJobFile(gitRoot, postsubmitFile, &jobConfig)
		// Skip linting if file is not found
		if unmarshaledJobConfig == nil {
			continue
		}
		if fileReadError != nil {
			log.Fatalf("Error reading contents of %s: %v", postsubmitFile, fileReadError)
		}
		if fileUnmarshalError != nil {
			log.Fatalf("Error unmarshaling contents of %s: %v", postsubmitFile, fileUnmarshalError)
		}

		postsubmitConfigs, ok := unmarshaledJobConfig.ProwjobConfig.PostsubmitsStatic[unmarshaledJobConfig.GithubRepo]
		if !ok {
			log.Fatalf("Key %s does not exist in Postsubmit configuration map", unmarshaledJobConfig.GithubRepo)
		}
		if len(postsubmitConfigs) < 1 {
			log.Fatalf("Postsubmit configuration for the %s repo is empty", unmarshaledJobConfig.GithubRepo)
		}
		postsubmitConfig := postsubmitConfigs[0]
		for _, check := range postsubmitCheckFunctions {
			passed, lineNum, errMessage := check(postsubmitConfig, unmarshaledJobConfig.FileContents)
			if !passed {
				errorString := fmt.Sprintf("%d\t%s", lineNum, errMessage)
				postsubmitErrors[unmarshaledJobConfig.FileName] = append(postsubmitErrors[unmarshaledJobConfig.FileName], errorString)
			}
		}
	}

	presubmitErrorsExist := displayConfigErrors(presubmitErrors)
	postsubmitErrorsExist := displayConfigErrors(postsubmitErrors)

	if presubmitErrorsExist || postsubmitErrorsExist {
		fmt.Println("❌ Validations failed!")
		os.Exit(1)
	}
	fmt.Println("✅ Validations passed!")
}