Skip to content

Commit

Permalink
Fix deploy task env (woodpecker-ci#3878)
Browse files Browse the repository at this point in the history
  • Loading branch information
anbraten authored and 6543 committed Sep 5, 2024
1 parent 34e10fa commit 4a46e31
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 46 deletions.
8 changes: 4 additions & 4 deletions cli/exec/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
20 changes: 10 additions & 10 deletions cli/exec/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
8 changes: 4 additions & 4 deletions pipeline/frontend/metadata/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
26 changes: 12 additions & 14 deletions pipeline/frontend/metadata/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pipeline/frontend/yaml/constraint/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
2 changes: 1 addition & 1 deletion server/api/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/forge/github/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion server/forge/github/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})
Expand Down
2 changes: 1 addition & 1 deletion server/model/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
19 changes: 10 additions & 9 deletions server/pipeline/stepbuilder/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4a46e31

Please sign in to comment.