Skip to content

Commit

Permalink
workflow_dispatch support inputs config
Browse files Browse the repository at this point in the history
  • Loading branch information
pangliang committed Nov 29, 2023
1 parent 9d6f48e commit b3b5544
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ replace github.com/hashicorp/go-version => github.com/6543/go-version v1.3.1

replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0

replace github.com/nektos/act => gitea.com/gitea/act v0.2.51
replace github.com/nektos/act => gitea.com/pangliang/act v0.251.2-0.20231129053409-6a00b5cb3ceb

exclude github.com/gofrs/uuid v3.2.0+incompatible

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ gitea.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96 h1:+wWBi6Qfr
gitea.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96/go.mod h1:VyMQP6ue6MKHM8UsOXfNfuMKD0oSAWZdXVcpHIN2yaY=
gitea.com/lunny/levelqueue v0.4.2-0.20230414023320-3c0159fe0fe4 h1:IFT+hup2xejHqdhS7keYWioqfmxdnfblFDTGoOwcZ+o=
gitea.com/lunny/levelqueue v0.4.2-0.20230414023320-3c0159fe0fe4/go.mod h1:HBqmLbz56JWpfEGG0prskAV97ATNRoj5LDmPicD22hU=
gitea.com/pangliang/act v0.251.2-0.20231129053409-6a00b5cb3ceb h1:l1Jlxn7D6J+VfoP3R4F1IjxojZ7GEu2+tKeCet5HBkk=
gitea.com/pangliang/act v0.251.2-0.20231129053409-6a00b5cb3ceb/go.mod h1:YthlRq0FUQIzgfJ3ZWvCvVq3I3VsC9s2NYQ9b2Uxccs=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
gitee.com/travelliu/dm v1.8.11192/go.mod h1:DHTzyhCrM843x9VdKVbZ+GKXGRbKM2sJ4LxihRxShkE=
Expand Down
3 changes: 3 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3540,6 +3540,9 @@ workflow.disable_success = Workflow '%s' disabled successfully.
workflow.enable = Enable Workflow
workflow.enable_success = Workflow '%s' enabled successfully.
workflow.disabled = Workflow is disabled.
workflow.run = Run Workflow
workflow.not_found = Workflow '%s' not found.
workflow.run_success = Workflow '%s' run successfully.
need_approval_desc = Need approval to run workflows for fork pull request.
Expand Down
3 changes: 3 additions & 0 deletions options/locale/locale_zh-CN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3538,6 +3538,9 @@ workflow.disable_success=工作流 '%s' 已成功禁用。
workflow.enable=启用工作流
workflow.enable_success=工作流 '%s' 已成功启用。
workflow.disabled=工作流已禁用。
workflow.run=运行工作流
workflow.not_found=工作流 '%s' 不存在。
workflow.run_success=工作流 '%s' 触发成功。

need_approval_desc=该工作流由派生仓库的合并请求所触发,需要批准方可运行。

Expand Down
1 change: 1 addition & 0 deletions routers/web/repo/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func List(ctx *context.Context) {
for _, event := range events {
if event.Name == webhook_module.HookEventWorkflowDispatch.Event() {
ctx.Data["AllowTriggerWorkflowDispatchEvent"] = true
ctx.Data["WorkflowDispatchConfig"] = event.WorkflowDispatch()
break
}
}
Expand Down
26 changes: 21 additions & 5 deletions routers/web/repo/actions/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,9 @@ func disableOrEnableWorkflowFile(ctx *context_module.Context, isEnable bool) {
}

func Run(ctx *context_module.Context) {
redirectURL := fmt.Sprintf("%s/actions?workflow=%s&actor=%s&status=%s", ctx.Repo.RepoLink, url.QueryEscape(ctx.FormString("workflow")),
url.QueryEscape(ctx.FormString("actor")), url.QueryEscape(ctx.FormString("status")))

workflow := ctx.FormString("workflow")
if len(workflow) == 0 {
ctx.ServerError("workflow", nil)
Expand All @@ -641,7 +644,8 @@ func Run(ctx *context_module.Context) {
cfgUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions)
cfg := cfgUnit.ActionsConfig()
if cfg.IsWorkflowDisabled(workflow) {
ctx.JSONError(ctx.Locale.Tr("actions.workflow.disabled"))
ctx.Flash.Error(ctx.Tr("actions.workflow.disabled", workflow))
ctx.Redirect(redirectURL)
return
}

Expand Down Expand Up @@ -675,7 +679,8 @@ func Run(ctx *context_module.Context) {
}

if dwf == nil {
ctx.JSONError(ctx.Locale.Tr("actions.workflow.not_found"))
ctx.Flash.Error(ctx.Tr("actions.workflow.not_found", workflow))
ctx.Redirect(redirectURL)
return
}

Expand Down Expand Up @@ -710,6 +715,18 @@ func Run(ctx *context_module.Context) {
return
}

for _, wf := range workflows {
if wf.Env == nil {
wf.Env = make(map[string]string)
}
for k, v := range ctx.Req.PostForm {
if k == "_csrf" || len(v) == 0 || v[0] == "" {
continue
}
wf.Env[k] = v[0]
}
}

// Insert the action run and its associated jobs into the database
if err := actions_model.InsertRun(ctx, run, workflows); err != nil {
ctx.ServerError("workflow", err)
Expand All @@ -722,7 +739,6 @@ func Run(ctx *context_module.Context) {
}
actions_service.CreateCommitStatus(ctx, alljobs...)

redirectURL := fmt.Sprintf("%s/actions?workflow=%s&actor=%s&status=%s", ctx.Repo.RepoLink, url.QueryEscape(workflow),
url.QueryEscape(ctx.FormString("actor")), url.QueryEscape(ctx.FormString("status")))
ctx.JSONRedirect(redirectURL)
ctx.Flash.Success(ctx.Tr("actions.workflow.run_success", workflow))
ctx.Redirect(redirectURL)
}
9 changes: 5 additions & 4 deletions templates/repo/actions/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@
</div>
</button>
{{end}}

{{if .AllowTriggerWorkflowDispatchEvent}}
<button class="ui basic small compact button gt-mr-0 link-action" data-url="{{$.Link}}/run?workflow={{$.CurWorkflow}}&actor={{.CurActor}}&status={{$.CurStatus}}">{{ctx.Locale.Tr "Run workflow"}}</button>
{{end}}
</div>

{{if .AllowTriggerWorkflowDispatchEvent}}
{{template "repo/actions/workflow_dispatch" .}}
{{end}}

{{template "repo/actions/runs_list" .}}
</div>
</div>
Expand Down
35 changes: 35 additions & 0 deletions templates/repo/actions/workflow_dispatch.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div class="ui ignored info message">
This workflow has a workflow_dispatch event trigger.
<button class="ui right floated mini button" onclick="$('#runWorkflowDispatchModal').modal('show');">{{ctx.Locale.Tr "actions.workflow.run"}}{{svg "octicon-triangle-down" 14 "dropdown icon"}}</button>
</div>
<div id="runWorkflowDispatchModal" class="ui mini modal">
<div class="content">
<form class="ui form" action="{{$.Link}}/run?workflow={{$.CurWorkflow}}&actor={{$.CurActor}}&status={{.Status}}" method="post">
{{.CsrfTokenHtml}}
{{if .WorkflowDispatchConfig}}
{{range $key, $item := .WorkflowDispatchConfig.Inputs}}
<div class="ui field {{if .Required}}required{{end}}">
<label>{{$key}} :</label>
{{if eq .Type "choice"}}
<select class="ui fluid dropdown" name="{{$key}}">
{{range .Options}}
<option value="{{.}}" {{if eq $item.Default .}}selected{{end}} >{{.}}</option>
{{end}}
</select>
<span class="help">{{.Description}}</span>
{{else if eq .Type "boolean"}}
<div class="ui toggle checkbox">
<input type="checkbox" name="{{$key}}" {{if eq .Default "true"}}checked{{end}}>
<label class="help">{{.Description}}</label>
</div>
{{else}}
<input name="{{$key}}" value="{{.Default}}">
<span class="help">{{.Description}}</span>
{{end}}
</div>
{{end}}
{{end}}
<button class="ui tiny blue button">Submit</button>
</form>
</div>
</div>

0 comments on commit b3b5544

Please sign in to comment.