From ceb14cadc579b9663cfc2205d468e2e6f5a426db Mon Sep 17 00:00:00 2001 From: Anbraten <6918444+anbraten@users.noreply.github.com> Date: Sun, 7 Jul 2024 13:43:07 +0200 Subject: [PATCH] Fix deploy task env (#3878) --- cli/exec/flags.go | 8 +++--- cli/exec/metadata.go | 20 +++++++------- pipeline/frontend/metadata/environment.go | 8 +++--- pipeline/frontend/metadata/types.go | 26 +++++++++---------- .../frontend/yaml/constraint/constraint.go | 2 +- server/api/pipeline.go | 2 +- server/forge/github/parse.go | 2 +- server/forge/github/parse_test.go | 2 +- server/model/pipeline.go | 2 +- server/pipeline/stepbuilder/metadata.go | 19 +++++++------- 10 files changed, 45 insertions(+), 46 deletions(-) diff --git a/cli/exec/flags.go b/cli/exec/flags.go index eabce0470..66178188f 100644 --- a/cli/exec/flags.go +++ b/cli/exec/flags.go @@ -201,12 +201,12 @@ var flags = []cli.Flag{ Name: "pipeline-url", }, &cli.StringFlag{ - EnvVars: []string{"CI_PIPELINE_TARGET"}, - Name: "pipeline-target", + EnvVars: []string{"CI_PIPELINE_DEPLOY_TARGET", "CI_PIPELINE_TARGET"}, // TODO: remove CI_PIPELINE_TARGET in 3.x + Name: "pipeline-deploy-to", }, &cli.StringFlag{ - EnvVars: []string{"CI_PIPELINE_TASK"}, - Name: "pipeline-task", + EnvVars: []string{"CI_PIPELINE_DEPLOY_TASK", "CI_PIPELINE_TASK"}, // TODO: remove CI_PIPELINE_TASK in 3.x + Name: "pipeline-deploy-task", }, &cli.StringFlag{ EnvVars: []string{"CI_COMMIT_SHA"}, diff --git a/cli/exec/metadata.go b/cli/exec/metadata.go index 0cb471683..add382292 100644 --- a/cli/exec/metadata.go +++ b/cli/exec/metadata.go @@ -52,16 +52,16 @@ func metadataFromContext(c *cli.Context, axis matrix.Axis) metadata.Metadata { Trusted: c.Bool("repo-trusted"), }, Curr: metadata.Pipeline{ - Number: c.Int64("pipeline-number"), - Parent: c.Int64("pipeline-parent"), - Created: c.Int64("pipeline-created"), - Started: c.Int64("pipeline-started"), - Finished: c.Int64("pipeline-finished"), - Status: c.String("pipeline-status"), - Event: c.String("pipeline-event"), - ForgeURL: c.String("pipeline-url"), - Target: c.String("pipeline-target"), - Task: c.String("pipeline-task"), + Number: c.Int64("pipeline-number"), + Parent: c.Int64("pipeline-parent"), + Created: c.Int64("pipeline-created"), + Started: c.Int64("pipeline-started"), + Finished: c.Int64("pipeline-finished"), + Status: c.String("pipeline-status"), + Event: c.String("pipeline-event"), + ForgeURL: c.String("pipeline-url"), + DeployTo: c.String("pipeline-deploy-to"), + DeployTask: c.String("pipeline-deploy-task"), Commit: metadata.Commit{ Sha: c.String("commit-sha"), Ref: c.String("commit-ref"), diff --git a/pipeline/frontend/metadata/environment.go b/pipeline/frontend/metadata/environment.go index 782ccfce1..ccb4396b8 100644 --- a/pipeline/frontend/metadata/environment.go +++ b/pipeline/frontend/metadata/environment.go @@ -76,8 +76,8 @@ func (m *Metadata) Environ() map[string]string { "CI_PIPELINE_EVENT": m.Curr.Event, "CI_PIPELINE_URL": m.getPipelineWebURL(m.Curr, 0), "CI_PIPELINE_FORGE_URL": m.Curr.ForgeURL, - "CI_PIPELINE_DEPLOY_TARGET": m.Curr.Target, - "CI_PIPELINE_DEPLOY_TASK": m.Curr.Task, + "CI_PIPELINE_DEPLOY_TARGET": m.Curr.DeployTo, + "CI_PIPELINE_DEPLOY_TASK": m.Curr.DeployTask, "CI_PIPELINE_STATUS": m.Curr.Status, "CI_PIPELINE_CREATED": strconv.FormatInt(m.Curr.Created, 10), "CI_PIPELINE_STARTED": strconv.FormatInt(m.Curr.Started, 10), @@ -108,8 +108,8 @@ func (m *Metadata) Environ() map[string]string { "CI_PREV_PIPELINE_EVENT": m.Prev.Event, "CI_PREV_PIPELINE_URL": m.getPipelineWebURL(m.Prev, 0), "CI_PREV_PIPELINE_FORGE_URL": m.Prev.ForgeURL, - "CI_PREV_PIPELINE_DEPLOY_TARGET": m.Prev.Target, - "CI_PREV_PIPELINE_DEPLOY_TASK": m.Prev.Task, + "CI_PREV_PIPELINE_DEPLOY_TARGET": m.Prev.DeployTo, + "CI_PREV_PIPELINE_DEPLOY_TASK": m.Prev.DeployTask, "CI_PREV_PIPELINE_STATUS": m.Prev.Status, "CI_PREV_PIPELINE_CREATED": strconv.FormatInt(m.Prev.Created, 10), "CI_PREV_PIPELINE_STARTED": strconv.FormatInt(m.Prev.Started, 10), diff --git a/pipeline/frontend/metadata/types.go b/pipeline/frontend/metadata/types.go index ef2299479..9cf7e64a1 100644 --- a/pipeline/frontend/metadata/types.go +++ b/pipeline/frontend/metadata/types.go @@ -44,20 +44,18 @@ type ( // Pipeline defines runtime metadata for a pipeline. Pipeline struct { - Number int64 `json:"number,omitempty"` - Created int64 `json:"created,omitempty"` - Started int64 `json:"started,omitempty"` - Finished int64 `json:"finished,omitempty"` - Timeout int64 `json:"timeout,omitempty"` - Status string `json:"status,omitempty"` - Event string `json:"event,omitempty"` - ForgeURL string `json:"forge_url,omitempty"` - Target string `json:"target,omitempty"` - Task string `json:"task,omitempty"` - Trusted bool `json:"trusted,omitempty"` - Commit Commit `json:"commit,omitempty"` - Parent int64 `json:"parent,omitempty"` - Cron string `json:"cron,omitempty"` + Number int64 `json:"number,omitempty"` + Created int64 `json:"created,omitempty"` + Started int64 `json:"started,omitempty"` + Finished int64 `json:"finished,omitempty"` + Status string `json:"status,omitempty"` + Event string `json:"event,omitempty"` + ForgeURL string `json:"forge_url,omitempty"` + DeployTo string `json:"target,omitempty"` + DeployTask string `json:"task,omitempty"` + Commit Commit `json:"commit,omitempty"` + Parent int64 `json:"parent,omitempty"` + Cron string `json:"cron,omitempty"` } // Commit defines runtime metadata for a commit. diff --git a/pipeline/frontend/yaml/constraint/constraint.go b/pipeline/frontend/yaml/constraint/constraint.go index 48145266f..205f21fd3 100644 --- a/pipeline/frontend/yaml/constraint/constraint.go +++ b/pipeline/frontend/yaml/constraint/constraint.go @@ -164,7 +164,7 @@ func (c *Constraint) Match(m metadata.Metadata, global bool, env map[string]stri } match = match && c.Platform.Match(m.Sys.Platform) && - c.Environment.Match(m.Curr.Target) && + c.Environment.Match(m.Curr.DeployTo) && c.Event.Match(m.Curr.Event) && c.Repo.Match(path.Join(m.Repo.Owner, m.Repo.Name)) && c.Ref.Match(m.Curr.Commit.Ref) && diff --git a/server/api/pipeline.go b/server/api/pipeline.go index 2f4509d90..591a6db66 100644 --- a/server/api/pipeline.go +++ b/server/api/pipeline.go @@ -562,7 +562,7 @@ func PostPipeline(c *gin.Context) { return } - pl.Deploy = c.DefaultQuery("deploy_to", pl.Deploy) + pl.DeployTo = c.DefaultQuery("deploy_to", pl.DeployTo) } // Read query string parameters into pipelineParams, exclude reserved params diff --git a/server/forge/github/parse.go b/server/forge/github/parse.go index 5c1ed8dbe..c8d33bf8f 100644 --- a/server/forge/github/parse.go +++ b/server/forge/github/parse.go @@ -126,10 +126,10 @@ func parseDeployHook(hook *github.DeploymentEvent) (*model.Repo, *model.Pipeline Message: hook.GetDeployment().GetDescription(), Ref: hook.GetDeployment().GetRef(), Branch: hook.GetDeployment().GetRef(), - Deploy: hook.GetDeployment().GetEnvironment(), Avatar: hook.GetSender().GetAvatarURL(), Author: hook.GetSender().GetLogin(), Sender: hook.GetSender().GetLogin(), + DeployTo: hook.GetDeployment().GetEnvironment(), DeployTask: hook.GetDeployment().GetTask(), } // if the ref is a sha or short sha we need to manually construct the ref. diff --git a/server/forge/github/parse_test.go b/server/forge/github/parse_test.go index 39ca63f5c..225bfd3c9 100644 --- a/server/forge/github/parse_test.go +++ b/server/forge/github/parse_test.go @@ -119,7 +119,7 @@ func Test_parser(t *testing.T) { g.Assert(b).IsNotNil() g.Assert(p).IsNil() g.Assert(b.Event).Equal(model.EventDeploy) - g.Assert(b.Deploy).Equal("production") + g.Assert(b.DeployTo).Equal("production") g.Assert(b.DeployTask).Equal("deploy") }) }) diff --git a/server/model/pipeline.go b/server/model/pipeline.go index 674069cfd..5106308de 100644 --- a/server/model/pipeline.go +++ b/server/model/pipeline.go @@ -32,7 +32,7 @@ type Pipeline struct { Updated int64 `json:"updated_at" xorm:"'updated' NOT NULL DEFAULT 0 updated"` // TODO change JSON field to "updated" in 3.0 Started int64 `json:"started_at" xorm:"started"` // TODO change JSON field to "started" in 3.0 Finished int64 `json:"finished_at" xorm:"finished"` // TODO change JSON field to "finished" in 3.0 - Deploy string `json:"deploy_to" xorm:"deploy"` + DeployTo string `json:"deploy_to" xorm:"deploy"` DeployTask string `json:"deploy_task" xorm:"deploy_task"` Commit string `json:"commit" xorm:"commit"` Branch string `json:"branch" xorm:"branch"` diff --git a/server/pipeline/stepbuilder/metadata.go b/server/pipeline/stepbuilder/metadata.go index 2e2a3c106..6e48e4158 100644 --- a/server/pipeline/stepbuilder/metadata.go +++ b/server/pipeline/stepbuilder/metadata.go @@ -107,15 +107,16 @@ func metadataPipelineFromModelPipeline(pipeline *model.Pipeline, includeParent b } return metadata.Pipeline{ - Number: pipeline.Number, - Parent: parent, - Created: pipeline.Created, - Started: pipeline.Started, - Finished: pipeline.Finished, - Status: string(pipeline.Status), - Event: string(pipeline.Event), - ForgeURL: pipeline.ForgeURL, - Target: pipeline.Deploy, + Number: pipeline.Number, + Parent: parent, + Created: pipeline.Created, + Started: pipeline.Started, + Finished: pipeline.Finished, + Status: string(pipeline.Status), + Event: string(pipeline.Event), + ForgeURL: pipeline.ForgeURL, + DeployTo: pipeline.DeployTo, + DeployTask: pipeline.DeployTask, Commit: metadata.Commit{ Sha: pipeline.Commit, Ref: pipeline.Ref,