Skip to content

Commit 1750756

Browse files
authored
Merge branch 'main' into actionbg
2 parents 37207b9 + 226231e commit 1750756

File tree

17 files changed

+154
-53
lines changed

17 files changed

+154
-53
lines changed

models/asymkey/ssh_key_authorized_keys.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
139139
if err != nil {
140140
return err
141141
}
142+
defer f.Close()
143+
142144
scanner := bufio.NewScanner(f)
143145
for scanner.Scan() {
144146
line := scanner.Text()
@@ -148,15 +150,12 @@ func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
148150
}
149151
_, err = t.WriteString(line + "\n")
150152
if err != nil {
151-
f.Close()
152153
return err
153154
}
154155
}
155-
err = scanner.Err()
156-
if err != nil {
157-
return fmt.Errorf("scan: %w", err)
156+
if err = scanner.Err(); err != nil {
157+
return fmt.Errorf("RegeneratePublicKeys scan: %w", err)
158158
}
159-
f.Close()
160159
}
161160
return nil
162161
}

modules/actions/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func ReadLogs(ctx context.Context, inStorage bool, filename string, offset, limi
100100
}
101101

102102
if err := scanner.Err(); err != nil {
103-
return nil, fmt.Errorf("scan: %w", err)
103+
return nil, fmt.Errorf("ReadLogs scan: %w", err)
104104
}
105105

106106
return rows, nil

modules/git/commit.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,8 @@ func (c *Commit) GetSubModules() (*ObjectCache, error) {
397397
}
398398
}
399399
}
400-
err = scanner.Err()
401-
if err != nil {
402-
return nil, fmt.Errorf("scan: %w", err)
400+
if err = scanner.Err(); err != nil {
401+
return nil, fmt.Errorf("GetSubModules scan: %w", err)
403402
}
404403

405404
return c.submoduleCache, nil

modules/git/repo_stats.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
124124
}
125125
}
126126
}
127-
err = scanner.Err()
128-
if err != nil {
129-
return fmt.Errorf("scan: %w", err)
127+
if err = scanner.Err(); err != nil {
128+
_ = stdoutReader.Close()
129+
return fmt.Errorf("GetCodeActivityStats scan: %w", err)
130130
}
131131
a := make([]*CodeActivityAuthor, 0, len(authors))
132132
for _, v := range authors {

modules/markup/csv/csv.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ func (Renderer) fallbackRender(input io.Reader, tmpBlock *bufio.Writer) error {
124124
return err
125125
}
126126
}
127-
err = scan.Err()
128-
if err != nil {
129-
return fmt.Errorf("scan: %w", err)
127+
if err = scan.Err(); err != nil {
128+
return fmt.Errorf("fallbackRender scan: %w", err)
130129
}
131130

132131
_, err = tmpBlock.WriteString("</pre>")

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3626,6 +3626,7 @@ runs.scheduled = Scheduled
36263626
runs.pushed_by = pushed by
36273627
runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s
36283628
runs.no_matching_online_runner_helper = No matching online runner with label: %s
3629+
runs.no_job_without_needs = The workflow must contain at least one job without dependencies.
36293630
runs.actor = Actor
36303631
runs.status = Status
36313632
runs.actors_no_select = All actors

routers/web/repo/actions/actions.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,13 @@ func List(ctx *context.Context) {
104104
workflows = append(workflows, workflow)
105105
continue
106106
}
107-
// Check whether have matching runner
107+
// The workflow must contain at least one job without "needs". Otherwise, a deadlock will occur and no jobs will be able to run.
108+
hasJobWithoutNeeds := false
109+
// Check whether have matching runner and a job without "needs"
108110
for _, j := range wf.Jobs {
111+
if !hasJobWithoutNeeds && len(j.Needs()) == 0 {
112+
hasJobWithoutNeeds = true
113+
}
109114
runsOnList := j.RunsOn()
110115
for _, ro := range runsOnList {
111116
if strings.Contains(ro, "${{") {
@@ -123,6 +128,9 @@ func List(ctx *context.Context) {
123128
break
124129
}
125130
}
131+
if !hasJobWithoutNeeds {
132+
workflow.ErrMsg = ctx.Locale.TrString("actions.runs.no_job_without_needs")
133+
}
126134
workflows = append(workflows, workflow)
127135
}
128136
}

routers/web/repo/actions/view.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,25 @@ func Rerun(ctx *context_module.Context) {
303303
return
304304
}
305305

306-
if jobIndexStr != "" {
307-
jobs = []*actions_model.ActionRunJob{job}
306+
if jobIndexStr == "" { // rerun all jobs
307+
for _, j := range jobs {
308+
// if the job has needs, it should be set to "blocked" status to wait for other jobs
309+
shouldBlock := len(j.Needs) > 0
310+
if err := rerunJob(ctx, j, shouldBlock); err != nil {
311+
ctx.Error(http.StatusInternalServerError, err.Error())
312+
return
313+
}
314+
}
315+
ctx.JSON(http.StatusOK, struct{}{})
316+
return
308317
}
309318

310-
for _, j := range jobs {
311-
if err := rerunJob(ctx, j); err != nil {
319+
rerunJobs := actions_service.GetAllRerunJobs(job, jobs)
320+
321+
for _, j := range rerunJobs {
322+
// jobs other than the specified one should be set to "blocked" status
323+
shouldBlock := j.JobID != job.JobID
324+
if err := rerunJob(ctx, j, shouldBlock); err != nil {
312325
ctx.Error(http.StatusInternalServerError, err.Error())
313326
return
314327
}
@@ -317,14 +330,17 @@ func Rerun(ctx *context_module.Context) {
317330
ctx.JSON(http.StatusOK, struct{}{})
318331
}
319332

320-
func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob) error {
333+
func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob, shouldBlock bool) error {
321334
status := job.Status
322335
if !status.IsDone() {
323336
return nil
324337
}
325338

326339
job.TaskID = 0
327340
job.Status = actions_model.StatusWaiting
341+
if shouldBlock {
342+
job.Status = actions_model.StatusBlocked
343+
}
328344
job.Started = 0
329345
job.Stopped = 0
330346

routers/web/repo/compare.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -980,9 +980,8 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu
980980
}
981981
diffLines = append(diffLines, diffLine)
982982
}
983-
err = scanner.Err()
984-
if err != nil {
985-
return nil, fmt.Errorf("scan: %w", err)
983+
if err = scanner.Err(); err != nil {
984+
return nil, fmt.Errorf("getExcerptLines scan: %w", err)
986985
}
987986
return diffLines, nil
988987
}

routers/web/repo/editor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
333333
ctx.Error(http.StatusInternalServerError, err.Error())
334334
}
335335
} else if models.IsErrCommitIDDoesNotMatch(err) {
336-
ctx.RenderWithErr(ctx.Tr("repo.editor.commit_id_not_matching", ctx.Repo.RepoLink+"/compare/"+util.PathEscapeSegments(form.LastCommit)+"..."+util.PathEscapeSegments(ctx.Repo.CommitID)), tplEditFile, &form)
336+
ctx.RenderWithErr(ctx.Tr("repo.editor.commit_id_not_matching"), tplEditFile, &form)
337337
} else if git.IsErrPushOutOfDate(err) {
338-
ctx.RenderWithErr(ctx.Tr("repo.editor.push_out_of_date", ctx.Repo.RepoLink+"/compare/"+util.PathEscapeSegments(form.LastCommit)+"..."+util.PathEscapeSegments(form.NewBranchName)), tplEditFile, &form)
338+
ctx.RenderWithErr(ctx.Tr("repo.editor.push_out_of_date"), tplEditFile, &form)
339339
} else if git.IsErrPushRejected(err) {
340340
errPushRej := err.(*git.ErrPushRejected)
341341
if len(errPushRej.Message) == 0 {

0 commit comments

Comments
 (0)