Skip to content

Commit d5f6c44

Browse files
committed
implement evaluate concurrency expression again, vars may change after the run is done
1 parent 5e43aa2 commit d5f6c44

File tree

3 files changed

+50
-28
lines changed

3 files changed

+50
-28
lines changed

models/actions/run.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,31 @@ import (
2727

2828
// ActionRun represents a run of a workflow file
2929
type ActionRun struct {
30-
ID int64
31-
Title string
32-
RepoID int64 `xorm:"index unique(repo_index) index(repo_concurrency)"`
33-
Repo *repo_model.Repository `xorm:"-"`
34-
OwnerID int64 `xorm:"index"`
35-
WorkflowID string `xorm:"index"` // the name of workflow file
36-
Index int64 `xorm:"index unique(repo_index)"` // a unique number for each run of a repository
37-
TriggerUserID int64 `xorm:"index"`
38-
TriggerUser *user_model.User `xorm:"-"`
39-
ScheduleID int64
40-
Ref string `xorm:"index"` // the commit/tag/… that caused the run
41-
IsRefDeleted bool `xorm:"-"`
42-
CommitSHA string
43-
IsForkPullRequest bool // If this is triggered by a PR from a forked repository or an untrusted user, we need to check if it is approved and limit permissions when running the workflow.
44-
NeedApproval bool // may need approval if it's a fork pull request
45-
ApprovedBy int64 `xorm:"index"` // who approved
46-
Event webhook_module.HookEventType // the webhook event that causes the workflow to run
47-
EventPayload string `xorm:"LONGTEXT"`
48-
TriggerEvent string // the trigger event defined in the `on` configuration of the triggered workflow
49-
Status Status `xorm:"index"`
50-
Version int `xorm:"version default 0"` // Status could be updated concomitantly, so an optimistic lock is needed
51-
ConcurrencyGroup string `xorm:"index(repo_concurrency)"`
52-
ConcurrencyCancel bool
30+
ID int64
31+
Title string
32+
RepoID int64 `xorm:"index unique(repo_index) index(repo_concurrency)"`
33+
Repo *repo_model.Repository `xorm:"-"`
34+
OwnerID int64 `xorm:"index"`
35+
WorkflowID string `xorm:"index"` // the name of workflow file
36+
Index int64 `xorm:"index unique(repo_index)"` // a unique number for each run of a repository
37+
TriggerUserID int64 `xorm:"index"`
38+
TriggerUser *user_model.User `xorm:"-"`
39+
ScheduleID int64
40+
Ref string `xorm:"index"` // the commit/tag/… that caused the run
41+
IsRefDeleted bool `xorm:"-"`
42+
CommitSHA string
43+
IsForkPullRequest bool // If this is triggered by a PR from a forked repository or an untrusted user, we need to check if it is approved and limit permissions when running the workflow.
44+
NeedApproval bool // may need approval if it's a fork pull request
45+
ApprovedBy int64 `xorm:"index"` // who approved
46+
Event webhook_module.HookEventType // the webhook event that causes the workflow to run
47+
EventPayload string `xorm:"LONGTEXT"`
48+
TriggerEvent string // the trigger event defined in the `on` configuration of the triggered workflow
49+
Status Status `xorm:"index"`
50+
Version int `xorm:"version default 0"` // Status could be updated concomitantly, so an optimistic lock is needed
51+
RawConcurrencyGroup string
52+
RawConcurrencyCancel string
53+
ConcurrencyGroup string `xorm:"index(repo_concurrency)"`
54+
ConcurrencyCancel bool
5355
// Started and Stopped is used for recording last run time, if rerun happened, they will be reset to 0
5456
Started timeutil.TimeStamp
5557
Stopped timeutil.TimeStamp

models/migrations/v1_25/v322.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99

1010
func AddActionsConcurrency(x *xorm.Engine) error {
1111
type ActionRun struct {
12-
RepoID int64 `xorm:"index unique(repo_index) index(repo_concurrency)"`
13-
ConcurrencyGroup string `xorm:"index(repo_concurrency)"`
14-
ConcurrencyCancel bool
12+
RepoID int64 `xorm:"index unique(repo_index) index(repo_concurrency)"`
13+
RawConcurrencyGroup string
14+
RawConcurrencyCancel string
15+
ConcurrencyGroup string `xorm:"index(repo_concurrency)"`
16+
ConcurrencyCancel bool
1517
}
1618

1719
if err := x.Sync(new(ActionRun)); err != nil {

routers/web/repo/actions/view.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ func Rerun(ctx *context_module.Context) {
419419
return
420420
}
421421

422-
// TODO evaluate concurrency expression again, vars may change after the run is done
423422
// check run (workflow-level) concurrency
424423

425424
job, jobs := getRunJobs(ctx, runIndex, jobIndex)
@@ -435,6 +434,25 @@ func Rerun(ctx *context_module.Context) {
435434
run.Started = 0
436435
run.Stopped = 0
437436

437+
vars, err := actions_model.GetVariablesOfRun(ctx, run)
438+
if err != nil {
439+
ctx.ServerError("GetVariablesOfRun", fmt.Errorf("get run %d variables: %w", run.ID, err))
440+
return
441+
}
442+
443+
wfConcurrencyGroup, wfConcurrencyCancel, err := actions_service.EvaluateWorkflowConcurrency(ctx, run, &model.RawConcurrency{
444+
Group: run.RawConcurrencyGroup,
445+
CancelInProgress: run.RawConcurrencyCancel,
446+
}, vars)
447+
if err != nil {
448+
ctx.ServerError("EvaluateWorkflowConcurrency", fmt.Errorf("evaluate workflow concurrency: %w", err))
449+
return
450+
}
451+
if wfConcurrencyGroup != "" {
452+
run.ConcurrencyGroup = wfConcurrencyGroup
453+
run.ConcurrencyCancel = wfConcurrencyCancel
454+
}
455+
438456
blockRunByConcurrency, err = actions_model.ShouldBlockRunByConcurrency(ctx, run)
439457
if err != nil {
440458
ctx.ServerError("ShouldBlockRunByConcurrency", err)
@@ -449,7 +467,7 @@ func Rerun(ctx *context_module.Context) {
449467
ctx.ServerError("cancel jobs", err)
450468
return
451469
}
452-
if err := actions_model.UpdateRun(ctx, run, "started", "stopped", "previous_duration", "status"); err != nil {
470+
if err := actions_model.UpdateRun(ctx, run, "started", "stopped", "previous_duration", "status", "concurrency_group", "concurrency_cancel"); err != nil {
453471
ctx.ServerError("UpdateRun", err)
454472
return
455473
}

0 commit comments

Comments
 (0)