Run reads the job config, generates forked jobs, and writes the output YAML.
(ctx context.Context, opts Options)
| 108 | |
| 109 | // Run reads the job config, generates forked jobs, and writes the output YAML. |
| 110 | func Run(ctx context.Context, opts Options) error { |
| 111 | if err := opts.Validate(); err != nil { |
| 112 | return err |
| 113 | } |
| 114 | |
| 115 | jobConfig, err := config.ReadJobConfig(opts.JobConfig) |
| 116 | if err != nil { |
| 117 | return fmt.Errorf("reading job config: %w", err) |
| 118 | } |
| 119 | |
| 120 | vars := templateVars{ |
| 121 | Version: opts.Version, |
| 122 | GoVersion: opts.GoVersion, |
| 123 | } |
| 124 | |
| 125 | newPresubmits, err := generatePresubmits(ctx, jobConfig, vars, opts.ImageResolver) |
| 126 | if err != nil { |
| 127 | return fmt.Errorf("generating presubmits: %w", err) |
| 128 | } |
| 129 | |
| 130 | newPeriodics, err := generatePeriodics(ctx, jobConfig, vars, opts.ImageResolver) |
| 131 | if err != nil { |
| 132 | return fmt.Errorf("generating periodics: %w", err) |
| 133 | } |
| 134 | |
| 135 | newPostsubmits, err := generatePostsubmits(ctx, jobConfig, vars, opts.ImageResolver) |
| 136 | if err != nil { |
| 137 | return fmt.Errorf("generating postsubmits: %w", err) |
| 138 | } |
| 139 | |
| 140 | gyaml.FutureLineWrap() |
| 141 | |
| 142 | output, err := yaml.Marshal(map[string]any{ |
| 143 | "periodics": newPeriodics, |
| 144 | "presubmits": newPresubmits, |
| 145 | "postsubmits": newPostsubmits, |
| 146 | }) |
| 147 | if err != nil { |
| 148 | return fmt.Errorf("marshaling output: %w", err) |
| 149 | } |
| 150 | |
| 151 | if opts.OutputPath != "" { |
| 152 | if err := os.WriteFile( |
| 153 | opts.OutputPath, output, filePermissions, |
| 154 | ); err != nil { |
| 155 | return fmt.Errorf("writing output: %w", err) |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | return nil |
| 160 | } |
| 161 | |
| 162 | const ( |
| 163 | forkAnnotation = "fork-per-release" |
nothing calls this directly
no test coverage detected