@@ -32,8 +32,9 @@ import (
32
32
)
33
33
34
34
const (
35
- tplListActions templates.TplName = "repo/actions/list"
36
- tplViewActions templates.TplName = "repo/actions/view"
35
+ tplListActions templates.TplName = "repo/actions/list"
36
+ tplDispatchInputsActions templates.TplName = "repo/actions/workflow_dispatch_inputs"
37
+ tplViewActions templates.TplName = "repo/actions/view"
37
38
)
38
39
39
40
type Workflow struct {
@@ -64,107 +65,143 @@ func MustEnableActions(ctx *context.Context) {
64
65
func List (ctx * context.Context ) {
65
66
ctx .Data ["Title" ] = ctx .Tr ("actions.actions" )
66
67
ctx .Data ["PageIsActions" ] = true
68
+
69
+ commit , err := ctx .Repo .GitRepo .GetBranchCommit (ctx .Repo .Repository .DefaultBranch )
70
+ if err != nil {
71
+ ctx .ServerError ("GetBranchCommit" , err )
72
+ return
73
+ }
74
+
75
+ workflows := prepareWorkflowDispatchTemplate (ctx , commit )
76
+ if ctx .Written () {
77
+ return
78
+ }
79
+
80
+ prepareWorkflowList (ctx , workflows )
81
+ if ctx .Written () {
82
+ return
83
+ }
84
+
85
+ ctx .HTML (http .StatusOK , tplListActions )
86
+ }
87
+
88
+ func WorkflowDispatchInputs (ctx * context.Context ) {
89
+ ref := ctx .FormString ("ref" )
90
+ if ref == "" {
91
+ ctx .NotFound ("WorkflowDispatchInputs: no ref" , nil )
92
+ return
93
+ }
94
+ // get target commit of run from specified ref
95
+ refName := git .RefName (ref )
96
+ var commit * git.Commit
97
+ var err error
98
+ if refName .IsTag () {
99
+ commit , err = ctx .Repo .GitRepo .GetTagCommit (refName .TagName ())
100
+ } else if refName .IsBranch () {
101
+ commit , err = ctx .Repo .GitRepo .GetBranchCommit (refName .BranchName ())
102
+ } else {
103
+ ctx .ServerError ("UnsupportedRefType" , nil )
104
+ return
105
+ }
106
+ if err != nil {
107
+ ctx .ServerError ("GetTagCommit/GetBranchCommit" , err )
108
+ return
109
+ }
110
+ prepareWorkflowDispatchTemplate (ctx , commit )
111
+ if ctx .Written () {
112
+ return
113
+ }
114
+ ctx .HTML (http .StatusOK , tplDispatchInputsActions )
115
+ }
116
+
117
+ func prepareWorkflowDispatchTemplate (ctx * context.Context , commit * git.Commit ) (workflows []Workflow ) {
67
118
workflowID := ctx .FormString ("workflow" )
68
- actorID := ctx .FormInt64 ("actor" )
69
- status := ctx .FormInt ("status" )
70
119
ctx .Data ["CurWorkflow" ] = workflowID
120
+ ctx .Data ["CurWorkflowExists" ] = false
71
121
72
- var workflows []Workflow
73
122
var curWorkflow * model.Workflow
74
- if empty , err := ctx .Repo .GitRepo .IsEmpty (); err != nil {
75
- ctx .ServerError ("IsEmpty" , err )
76
- return
77
- } else if ! empty {
78
- commit , err := ctx .Repo .GitRepo .GetBranchCommit (ctx .Repo .Repository .DefaultBranch )
79
- if err != nil {
80
- ctx .ServerError ("GetBranchCommit" , err )
81
- return
82
- }
83
- entries , err := actions .ListWorkflows (commit )
84
- if err != nil {
85
- ctx .ServerError ("ListWorkflows" , err )
86
- return
87
- }
88
123
89
- // Get all runner labels
90
- runners , err := db .Find [actions_model.ActionRunner ](ctx , actions_model.FindRunnerOptions {
91
- RepoID : ctx .Repo .Repository .ID ,
92
- IsOnline : optional .Some (true ),
93
- WithAvailable : true ,
94
- })
124
+ entries , err := actions .ListWorkflows (commit )
125
+ if err != nil {
126
+ ctx .ServerError ("ListWorkflows" , err )
127
+ return nil
128
+ }
129
+
130
+ // Get all runner labels
131
+ runners , err := db .Find [actions_model.ActionRunner ](ctx , actions_model.FindRunnerOptions {
132
+ RepoID : ctx .Repo .Repository .ID ,
133
+ IsOnline : optional .Some (true ),
134
+ WithAvailable : true ,
135
+ })
136
+ if err != nil {
137
+ ctx .ServerError ("FindRunners" , err )
138
+ return nil
139
+ }
140
+ allRunnerLabels := make (container.Set [string ])
141
+ for _ , r := range runners {
142
+ allRunnerLabels .AddMultiple (r .AgentLabels ... )
143
+ }
144
+
145
+ workflows = make ([]Workflow , 0 , len (entries ))
146
+ for _ , entry := range entries {
147
+ workflow := Workflow {Entry : * entry }
148
+ content , err := actions .GetContentFromEntry (entry )
95
149
if err != nil {
96
- ctx .ServerError ("FindRunners " , err )
97
- return
150
+ ctx .ServerError ("GetContentFromEntry " , err )
151
+ return nil
98
152
}
99
- allRunnerLabels := make (container.Set [string ])
100
- for _ , r := range runners {
101
- allRunnerLabels .AddMultiple (r .AgentLabels ... )
153
+ wf , err := model .ReadWorkflow (bytes .NewReader (content ))
154
+ if err != nil {
155
+ workflow .ErrMsg = ctx .Locale .TrString ("actions.runs.invalid_workflow_helper" , err .Error ())
156
+ workflows = append (workflows , workflow )
157
+ continue
102
158
}
103
-
104
- workflows = make ([]Workflow , 0 , len (entries ))
105
- for _ , entry := range entries {
106
- workflow := Workflow {Entry : * entry }
107
- content , err := actions .GetContentFromEntry (entry )
108
- if err != nil {
109
- ctx .ServerError ("GetContentFromEntry" , err )
110
- return
111
- }
112
- wf , err := model .ReadWorkflow (bytes .NewReader (content ))
113
- if err != nil {
114
- workflow .ErrMsg = ctx .Locale .TrString ("actions.runs.invalid_workflow_helper" , err .Error ())
115
- workflows = append (workflows , workflow )
159
+ // The workflow must contain at least one job without "needs". Otherwise, a deadlock will occur and no jobs will be able to run.
160
+ hasJobWithoutNeeds := false
161
+ // Check whether you have matching runner and a job without "needs"
162
+ emptyJobsNumber := 0
163
+ for _ , j := range wf .Jobs {
164
+ if j == nil {
165
+ emptyJobsNumber ++
116
166
continue
117
167
}
118
- // The workflow must contain at least one job without "needs". Otherwise, a deadlock will occur and no jobs will be able to run.
119
- hasJobWithoutNeeds := false
120
- // Check whether have matching runner and a job without "needs"
121
- emptyJobsNumber := 0
122
- for _ , j := range wf .Jobs {
123
- if j == nil {
124
- emptyJobsNumber ++
168
+ if ! hasJobWithoutNeeds && len (j .Needs ()) == 0 {
169
+ hasJobWithoutNeeds = true
170
+ }
171
+ runsOnList := j .RunsOn ()
172
+ for _ , ro := range runsOnList {
173
+ if strings .Contains (ro , "${{" ) {
174
+ // Skip if it contains expressions.
175
+ // The expressions could be very complex and could not be evaluated here,
176
+ // so just skip it, it's OK since it's just a tooltip message.
125
177
continue
126
178
}
127
- if ! hasJobWithoutNeeds && len (j .Needs ()) == 0 {
128
- hasJobWithoutNeeds = true
129
- }
130
- runsOnList := j .RunsOn ()
131
- for _ , ro := range runsOnList {
132
- if strings .Contains (ro , "${{" ) {
133
- // Skip if it contains expressions.
134
- // The expressions could be very complex and could not be evaluated here,
135
- // so just skip it, it's OK since it's just a tooltip message.
136
- continue
137
- }
138
- if ! allRunnerLabels .Contains (ro ) {
139
- workflow .ErrMsg = ctx .Locale .TrString ("actions.runs.no_matching_online_runner_helper" , ro )
140
- break
141
- }
142
- }
143
- if workflow .ErrMsg != "" {
179
+ if ! allRunnerLabels .Contains (ro ) {
180
+ workflow .ErrMsg = ctx .Locale .TrString ("actions.runs.no_matching_online_runner_helper" , ro )
144
181
break
145
182
}
146
183
}
147
- if ! hasJobWithoutNeeds {
148
- workflow .ErrMsg = ctx .Locale .TrString ("actions.runs.no_job_without_needs" )
149
- }
150
- if emptyJobsNumber == len (wf .Jobs ) {
151
- workflow .ErrMsg = ctx .Locale .TrString ("actions.runs.no_job" )
184
+ if workflow .ErrMsg != "" {
185
+ break
152
186
}
153
- workflows = append (workflows , workflow )
187
+ }
188
+ if ! hasJobWithoutNeeds {
189
+ workflow .ErrMsg = ctx .Locale .TrString ("actions.runs.no_job_without_needs" )
190
+ }
191
+ if emptyJobsNumber == len (wf .Jobs ) {
192
+ workflow .ErrMsg = ctx .Locale .TrString ("actions.runs.no_job" )
193
+ }
194
+ workflows = append (workflows , workflow )
154
195
155
- if workflow .Entry .Name () == workflowID {
156
- curWorkflow = wf
157
- }
196
+ if workflow .Entry .Name () == workflowID {
197
+ curWorkflow = wf
198
+ ctx . Data [ "CurWorkflowExists" ] = true
158
199
}
159
200
}
201
+
160
202
ctx .Data ["workflows" ] = workflows
161
203
ctx .Data ["RepoLink" ] = ctx .Repo .Repository .Link ()
162
204
163
- page := ctx .FormInt ("page" )
164
- if page <= 0 {
165
- page = 1
166
- }
167
-
168
205
actionsConfig := ctx .Repo .Repository .MustGetUnit (ctx , unit .TypeActions ).ActionsConfig ()
169
206
ctx .Data ["ActionsConfig" ] = actionsConfig
170
207
@@ -188,7 +225,7 @@ func List(ctx *context.Context) {
188
225
branches , err := git_model .FindBranchNames (ctx , branchOpts )
189
226
if err != nil {
190
227
ctx .ServerError ("FindBranchNames" , err )
191
- return
228
+ return nil
192
229
}
193
230
// always put default branch on the top if it exists
194
231
if slices .Contains (branches , ctx .Repo .Repository .DefaultBranch ) {
@@ -200,12 +237,23 @@ func List(ctx *context.Context) {
200
237
tags , err := repo_model .GetTagNamesByRepoID (ctx , ctx .Repo .Repository .ID )
201
238
if err != nil {
202
239
ctx .ServerError ("GetTagNamesByRepoID" , err )
203
- return
240
+ return nil
204
241
}
205
242
ctx .Data ["Tags" ] = tags
206
243
}
207
244
}
208
245
}
246
+ return workflows
247
+ }
248
+
249
+ func prepareWorkflowList (ctx * context.Context , workflows []Workflow ) {
250
+ actorID := ctx .FormInt64 ("actor" )
251
+ status := ctx .FormInt ("status" )
252
+ workflowID := ctx .FormString ("workflow" )
253
+ page := ctx .FormInt ("page" )
254
+ if page <= 0 {
255
+ page = 1
256
+ }
209
257
210
258
// if status or actor query param is not given to frontend href, (href="/<repoLink>/actions")
211
259
// they will be 0 by default, which indicates get all status or actors
@@ -264,8 +312,6 @@ func List(ctx *context.Context) {
264
312
pager .AddParamFromRequest (ctx .Req )
265
313
ctx .Data ["Page" ] = pager
266
314
ctx .Data ["HasWorkflowsOrRuns" ] = len (workflows ) > 0 || len (runs ) > 0
267
-
268
- ctx .HTML (http .StatusOK , tplListActions )
269
315
}
270
316
271
317
// loadIsRefDeleted loads the IsRefDeleted field for each run in the list.
0 commit comments