From bb18b0c9a29a34fa5d6ef63a0800b086d807844c Mon Sep 17 00:00:00 2001 From: Lauris BH Date: Wed, 13 Dec 2023 14:06:56 +0200 Subject: [PATCH 1/5] Allow to restart pipelines that has warnings --- .vscode/launch.json | 1 + server/pipeline/items.go | 6 ++---- server/pipeline/restart.go | 7 +++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 7cccf02203..81a6129130 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -42,6 +42,7 @@ "runtimeArgs": ["start"], "cwd": "${workspaceFolder}/web", "resolveSourceMapLocations": ["${workspaceFolder}/web/**", "!**/node_modules/**"], + "envFile": "${workspaceFolder}/.env", "skipFiles": ["/**"] } ] diff --git a/server/pipeline/items.go b/server/pipeline/items.go index 02026c9303..ae8ab4ae0d 100644 --- a/server/pipeline/items.go +++ b/server/pipeline/items.go @@ -91,7 +91,7 @@ func createPipelineItems(c context.Context, store store.Store, yamls []*forge_types.FileMeta, envs map[string]string, ) (*model.Pipeline, []*pipeline.Item, error) { pipelineItems, err := parsePipeline(store, currentPipeline, user, repo, yamls, envs) - if err != nil { + if err != nil && pipeline_errors.HasBlockingErrors(err) { currentPipeline, uerr := UpdateToStatusError(store, *currentPipeline, err) if uerr != nil { log.Error().Err(uerr).Msgf("Error setting error status of pipeline for %s#%d", repo.FullName, currentPipeline.Number) @@ -99,9 +99,7 @@ func createPipelineItems(c context.Context, store store.Store, updatePipelineStatus(c, currentPipeline, repo, user) } - if pipeline_errors.HasBlockingErrors(err) { - return currentPipeline, nil, err - } + return currentPipeline, nil, err } currentPipeline = setPipelineStepsOnPipeline(currentPipeline, pipelineItems) diff --git a/server/pipeline/restart.go b/server/pipeline/restart.go index 125f40d775..9a782b6de1 100644 --- a/server/pipeline/restart.go +++ b/server/pipeline/restart.go @@ -22,6 +22,7 @@ import ( "github.com/rs/zerolog/log" + pipeline_errors "go.woodpecker-ci.org/woodpecker/v2/pipeline/errors" "go.woodpecker-ci.org/woodpecker/v2/server" forge_types "go.woodpecker-ci.org/woodpecker/v2/server/forge/types" "go.woodpecker-ci.org/woodpecker/v2/server/model" @@ -94,10 +95,12 @@ func Restart(ctx context.Context, store store.Store, lastPipeline *model.Pipelin } newPipeline, pipelineItems, err := createPipelineItems(ctx, store, newPipeline, user, repo, pipelineFiles, envs) - if err != nil { + if pipeline_errors.HasBlockingErrors(err) { msg := fmt.Sprintf("failure to createPipelineItems for %s", repo.FullName) log.Error().Err(err).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, err + } else if err != nil { + newPipeline.Errors = pipeline_errors.GetPipelineErrors(err) } newPipeline, err = start(ctx, store, newPipeline, user, repo, pipelineItems) From 281e1563cce7da8d2e6626b53f557bacff023531 Mon Sep 17 00:00:00 2001 From: Lauris BH Date: Wed, 13 Dec 2023 14:14:43 +0200 Subject: [PATCH 2/5] Refactor code to be more easy to handle --- server/pipeline/approve.go | 5 +---- server/pipeline/items.go | 6 ++++-- server/pipeline/restart.go | 5 +---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/server/pipeline/approve.go b/server/pipeline/approve.go index 2755912913..a5a4e85227 100644 --- a/server/pipeline/approve.go +++ b/server/pipeline/approve.go @@ -20,7 +20,6 @@ import ( "github.com/rs/zerolog/log" - "go.woodpecker-ci.org/woodpecker/v2/pipeline/errors" forge_types "go.woodpecker-ci.org/woodpecker/v2/server/forge/types" "go.woodpecker-ci.org/woodpecker/v2/server/model" "go.woodpecker-ci.org/woodpecker/v2/server/store" @@ -51,12 +50,10 @@ func Approve(ctx context.Context, store store.Store, currentPipeline *model.Pipe } currentPipeline, pipelineItems, err := createPipelineItems(ctx, store, currentPipeline, user, repo, yamls, nil) - if errors.HasBlockingErrors(err) { + if err != nil { msg := fmt.Sprintf("failure to createPipelineItems for %s", repo.FullName) log.Error().Err(err).Msg(msg) return nil, err - } else if err != nil { - currentPipeline.Errors = errors.GetPipelineErrors(err) } currentPipeline, err = start(ctx, store, currentPipeline, user, repo, pipelineItems) diff --git a/server/pipeline/items.go b/server/pipeline/items.go index ae8ab4ae0d..39e788aaa8 100644 --- a/server/pipeline/items.go +++ b/server/pipeline/items.go @@ -91,7 +91,7 @@ func createPipelineItems(c context.Context, store store.Store, yamls []*forge_types.FileMeta, envs map[string]string, ) (*model.Pipeline, []*pipeline.Item, error) { pipelineItems, err := parsePipeline(store, currentPipeline, user, repo, yamls, envs) - if err != nil && pipeline_errors.HasBlockingErrors(err) { + if pipeline_errors.HasBlockingErrors(err) { currentPipeline, uerr := UpdateToStatusError(store, *currentPipeline, err) if uerr != nil { log.Error().Err(uerr).Msgf("Error setting error status of pipeline for %s#%d", repo.FullName, currentPipeline.Number) @@ -100,11 +100,13 @@ func createPipelineItems(c context.Context, store store.Store, } return currentPipeline, nil, err + } else if err != nil { + currentPipeline.Errors = pipeline_errors.GetPipelineErrors(err) } currentPipeline = setPipelineStepsOnPipeline(currentPipeline, pipelineItems) - return currentPipeline, pipelineItems, err + return currentPipeline, pipelineItems, nil } // setPipelineStepsOnPipeline is the link between pipeline representation in "pipeline package" and server diff --git a/server/pipeline/restart.go b/server/pipeline/restart.go index 9a782b6de1..5423fb8b4a 100644 --- a/server/pipeline/restart.go +++ b/server/pipeline/restart.go @@ -22,7 +22,6 @@ import ( "github.com/rs/zerolog/log" - pipeline_errors "go.woodpecker-ci.org/woodpecker/v2/pipeline/errors" "go.woodpecker-ci.org/woodpecker/v2/server" forge_types "go.woodpecker-ci.org/woodpecker/v2/server/forge/types" "go.woodpecker-ci.org/woodpecker/v2/server/model" @@ -95,12 +94,10 @@ func Restart(ctx context.Context, store store.Store, lastPipeline *model.Pipelin } newPipeline, pipelineItems, err := createPipelineItems(ctx, store, newPipeline, user, repo, pipelineFiles, envs) - if pipeline_errors.HasBlockingErrors(err) { + if err != nil { msg := fmt.Sprintf("failure to createPipelineItems for %s", repo.FullName) log.Error().Err(err).Msg(msg) return nil, err - } else if err != nil { - newPipeline.Errors = pipeline_errors.GetPipelineErrors(err) } newPipeline, err = start(ctx, store, newPipeline, user, repo, pipelineItems) From ec48efc0f087293bbc5d0706e1b0fc50a93ab89e Mon Sep 17 00:00:00 2001 From: Lauris BH Date: Wed, 13 Dec 2023 14:16:40 +0200 Subject: [PATCH 3/5] Undo accidental change --- server/pipeline/restart.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/pipeline/restart.go b/server/pipeline/restart.go index 5423fb8b4a..125f40d775 100644 --- a/server/pipeline/restart.go +++ b/server/pipeline/restart.go @@ -97,7 +97,7 @@ func Restart(ctx context.Context, store store.Store, lastPipeline *model.Pipelin if err != nil { msg := fmt.Sprintf("failure to createPipelineItems for %s", repo.FullName) log.Error().Err(err).Msg(msg) - return nil, err + return nil, fmt.Errorf(msg) } newPipeline, err = start(ctx, store, newPipeline, user, repo, pipelineItems) From 2a5a5bd6b546e4dac4abc03362a8be00dafa576a Mon Sep 17 00:00:00 2001 From: Lauris BH Date: Wed, 13 Dec 2023 14:51:46 +0200 Subject: [PATCH 4/5] Fix to store pipeline errors --- server/pipeline/items.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/pipeline/items.go b/server/pipeline/items.go index 39e788aaa8..a51a1ee7a6 100644 --- a/server/pipeline/items.go +++ b/server/pipeline/items.go @@ -102,11 +102,12 @@ func createPipelineItems(c context.Context, store store.Store, return currentPipeline, nil, err } else if err != nil { currentPipeline.Errors = pipeline_errors.GetPipelineErrors(err) + err = updatePipelinePending(c, store, currentPipeline, repo, user) } currentPipeline = setPipelineStepsOnPipeline(currentPipeline, pipelineItems) - return currentPipeline, pipelineItems, nil + return currentPipeline, pipelineItems, err } // setPipelineStepsOnPipeline is the link between pipeline representation in "pipeline package" and server From 112befdab7d26310b32585f84c5e228951f58b30 Mon Sep 17 00:00:00 2001 From: Lauris BH Date: Wed, 13 Dec 2023 14:55:27 +0200 Subject: [PATCH 5/5] Fix to return correct error response --- server/pipeline/approve.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/pipeline/approve.go b/server/pipeline/approve.go index a5a4e85227..6f38c2a2b5 100644 --- a/server/pipeline/approve.go +++ b/server/pipeline/approve.go @@ -53,7 +53,7 @@ func Approve(ctx context.Context, store store.Store, currentPipeline *model.Pipe if err != nil { msg := fmt.Sprintf("failure to createPipelineItems for %s", repo.FullName) log.Error().Err(err).Msg(msg) - return nil, err + return nil, fmt.Errorf(msg) } currentPipeline, err = start(ctx, store, currentPipeline, user, repo, pipelineItems)