func main()

in scripts/lint_prowjobs/main.go [259:326]


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

	pullBaseSha := os.Getenv(PULL_BASE_SHA_ENV)
	pullPullSha := os.Getenv(PULL_PULL_SHA_ENV)
	constantsConfigFile := os.Getenv(CONSTANTS_CONFIG_FILE_ENV)

	if _, err := os.Stat(constantsConfigFile); os.IsNotExist(err) {
		log.Fatalf("Job Constants yaml file does not exist in the env var %s!", CONSTANTS_CONFIG_FILE_ENV)
	}

	var presubmitConstants JobConstants
	unmarshalYamlFile(constantsConfigFile, &presubmitConstants)

	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]

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

	presubmitCheckFunctions := []presubmitCheck{
		AlwaysRunCheck(),
		EnvVarsCheck(&presubmitConstants),
		ClusterCheck(&presubmitConstants),
		SkipReportCheck(),
		BucketCheck(&presubmitConstants),
		ServiceAccountCheck(&presubmitConstants),
		MakeTargetCheck(&presubmitConstants),
	}

	for _, presubmitFile := range presubmitFiles {
		unmarshaledJobConfig := unmarshalJobFile(presubmitFile, &jobConfig)
		// Skip linting if file is not found
		if unmarshaledJobConfig == nil {
			continue
		}

		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)
			}
		}
	}

	presubmitErrorsExist := displayConfigErrors(presubmitErrors)

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