Skip to content

Commit 152219d

Browse files
(fix) (alpha update) runMakeTargets: run all targets only with --force, fail fast otherwise
1 parent 4448e20 commit 152219d

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

pkg/cli/alpha/internal/update/update.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,25 @@ func cleanupBranch() error {
210210
return nil
211211
}
212212

213-
// runMakeTargets is a helper function to run make with the targets necessary
214-
// to ensure all the necessary components are generated, formatted and linted.
215-
func runMakeTargets() {
213+
// runMakeTargets runs the specified make targets to ensure the project is in a good state.
214+
// If force is true, do not run target with || true to move forward when failures are faced.
215+
func runMakeTargets(force bool) {
216216
targets := []string{"manifests", "generate", "fmt", "vet", "lint-fix"}
217+
217218
for _, target := range targets {
218-
err := util.RunCmd(fmt.Sprintf("Running make %s", target), "make", target)
219-
if err != nil {
219+
var cmd []string
220+
var msg string
221+
222+
if force {
223+
msg = fmt.Sprintf("Running make %s (with --force)", target)
224+
shellCmd := fmt.Sprintf("make %s || true", target)
225+
cmd = []string{"sh", "-c", shellCmd}
226+
} else {
227+
msg = fmt.Sprintf("Running make %s", target)
228+
cmd = []string{"make", target}
229+
}
230+
231+
if err := util.RunCmd(msg, cmd[0], cmd[1:]...); err != nil {
220232
log.Warn("make target failed", "target", target, "error", err)
221233
}
222234
}
@@ -258,8 +270,8 @@ func runAlphaGenerate(tempDir, version string) error {
258270
// It was added because the alpha generate command in versions prior to v4.7.0 does
259271
// not run those commands automatically which will not allow we properly ensure
260272
// that all manifests, code generation, formatting, and linting are applied to
261-
// properly do the 3-way merge.
262-
runMakeTargets()
273+
// properly do the 3-way merge. We use true to ignore errors and do our best effort
274+
runMakeTargets(false)
263275
return nil
264276
}
265277

@@ -355,8 +367,8 @@ func (opts *Update) mergeOriginalToUpgrade() error {
355367
log.Info("Merge happened without conflicts.")
356368
}
357369

358-
// Best effort to run make targets to ensure the project is in a good state
359-
runMakeTargets()
370+
// When the --force flag is used has the best effort to run the make targets
371+
runMakeTargets(opts.Force)
360372

361373
// Step 4: Stage and commit
362374
if err := exec.Command("git", "add", "--all").Run(); err != nil {

pkg/cli/alpha/internal/update/update_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ var _ = Describe("Prepare for internal update", func() {
281281
err = mockBinResponse(fakeBinScript, mockMake)
282282
Expect(err).ToNot(HaveOccurred())
283283

284-
runMakeTargets()
284+
runMakeTargets(true)
285285
})
286286
})
287287

0 commit comments

Comments
 (0)