Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d6a95ce
support concurrency
Zettat123 Dec 7, 2024
f713c68
Merge branch 'main' of https://github.com/go-gitea/gitea into pr/Zett…
ChristopherHX Jul 8, 2025
76f58ef
fix: lint
ChristopherHX Jul 8, 2025
249e315
fix: assert correct status code
ChristopherHX Jul 8, 2025
b012126
fix: rerun all jobs did not respect concurrency
ChristopherHX Jul 9, 2025
91fccb7
Fix and Test rerun single jobs
ChristopherHX Jul 9, 2025
2e6032a
Remove CancelJobsByJobConcurrency in PickTask
ChristopherHX Jul 13, 2025
1a08b87
Merge branch 'main' of https://github.com/go-gitea/gitea into pr/Zett…
ChristopherHX Jul 13, 2025
9bba25e
remove code
ChristopherHX Jul 15, 2025
e6d25e2
Merge branch 'main' of https://github.com/go-gitea/gitea into pr/Zett…
ChristopherHX Jul 15, 2025
dc86086
call EmitJobsIfReady when cancelling a run
Zettat123 Jul 19, 2025
8721155
add TestCancelConcurrentRun
Zettat123 Jul 19, 2025
c5444e7
improve concurrency index
Zettat123 Jul 21, 2025
63eaf15
modify cancel-in-progress behavior
Zettat123 Jul 22, 2025
96d6938
fix bugs and tests
Zettat123 Jul 22, 2025
ea2bc92
Merge branch 'main' into support-actions-concurrency
Zettat123 Jul 22, 2025
a4b76b6
update InsertRun
Zettat123 Jul 22, 2025
ca18672
modify cancel-in-progress behavior
Zettat123 Jul 23, 2025
dc003e4
fix lint
Zettat123 Jul 23, 2025
e45ca56
improve handling cancellation
Zettat123 Jul 25, 2025
5e2059a
rename migration
Zettat123 Jul 25, 2025
4ba788d
Merge branch 'main' into support-actions-concurrency
Zettat123 Jul 25, 2025
2481e83
fix migration
Zettat123 Jul 25, 2025
f585f90
remove blockRunByConcurrency todo for jobs
ChristopherHX Jul 25, 2025
5e43aa2
fix migration to use same index as model
ChristopherHX Jul 25, 2025
d5f6c44
implement evaluate concurrency expression again, vars may change afte…
ChristopherHX Jul 25, 2025
796d2c1
Use a single RawConcurrency in db
ChristopherHX Jul 25, 2025
6a9eb9e
fix fmt
ChristopherHX Jul 25, 2025
42c2ca2
add TestAbandonConcurrentRun
Zettat123 Jul 25, 2025
5a45b76
update to act dev version add new tests
ChristopherHX Jul 29, 2025
989e274
Merge branch 'main' into support-actions-concurrency
Zettat123 Oct 3, 2025
15cc5c5
resolve conflicts
Zettat123 Oct 3, 2025
defa2fd
fix status update
Zettat123 Oct 3, 2025
7d5c377
Merge branch 'main' into support-actions-concurrency
Zettat123 Oct 5, 2025
ffe50aa
Merge branch 'main' into support-actions-concurrency
Zettat123 Oct 6, 2025
63d9a56
resolve conflicts
Zettat123 Oct 6, 2025
2dbede9
add 'IgnoreDropIndices' option to migration
Zettat123 Oct 6, 2025
8356dbe
only keep new index
Zettat123 Oct 6, 2025
ffe9597
fix comments
Zettat123 Oct 7, 2025
9a70f52
Merge branch 'main' into support-actions-concurrency
Zettat123 Oct 7, 2025
7b30080
skip chanaged jobs when cancelling jobs
Zettat123 Oct 7, 2025
c652810
add more comments and fix ErrUnevaluatedConcurrency
Zettat123 Oct 8, 2025
15c504c
fix rerun job and update test
Zettat123 Oct 9, 2025
3b4ad5d
remove ErrUnevaluatedConcurrency
wxiaoguang Oct 9, 2025
ae81158
fix comment
wxiaoguang Oct 9, 2025
d91ec9b
update comments
wxiaoguang Oct 9, 2025
87d7f65
fix comment
wxiaoguang Oct 9, 2025
84d6254
fix comment
Zettat123 Oct 10, 2025
bb399e6
fix lint
Zettat123 Oct 10, 2025
90a31d0
refactor
wxiaoguang Oct 10, 2025
d7dcd8b
fine tune
wxiaoguang Oct 10, 2025
23c80cf
fix lint
wxiaoguang Oct 10, 2025
2ad1e67
fix
wxiaoguang Oct 10, 2025
02dc4fa
fix
wxiaoguang Oct 10, 2025
023e6e2
use shouldBlock instead of status checking
wxiaoguang Oct 10, 2025
e38d886
fix test
wxiaoguang Oct 10, 2025
4f5143f
fix prepare
wxiaoguang Oct 10, 2025
2383132
rename variable
wxiaoguang Oct 10, 2025
6d12149
fix
wxiaoguang Oct 10, 2025
d69d345
fine tune comment and func name
wxiaoguang Oct 10, 2025
dc1faf9
Merge branch 'main' into support-actions-concurrency
wxiaoguang Oct 10, 2025
aa419a5
Merge branch 'main' into support-actions-concurrency
GiteaBot Oct 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions models/actions/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,19 +391,6 @@ func UpdateRun(ctx context.Context, run *ActionRun, cols ...string) error {

type ActionRunIndex db.ResourceIndex

func ShouldBlockRunByConcurrency(ctx context.Context, actionRun *ActionRun) (bool, error) {
if actionRun.ConcurrencyGroup == "" || actionRun.ConcurrencyCancel {
return false, nil
}

runs, jobs, err := GetConcurrentRunsAndJobs(ctx, actionRun.RepoID, actionRun.ConcurrencyGroup, []Status{StatusRunning})
if err != nil {
return false, fmt.Errorf("find concurrent runs and jobs: %w", err)
}

return len(runs) > 0 || len(jobs) > 0, nil
}

func GetConcurrentRunsAndJobs(ctx context.Context, repoID int64, concurrencyGroup string, status []Status) ([]*ActionRun, []*ActionRunJob, error) {
runs, err := db.Find[ActionRun](ctx, &FindRunOptions{
RepoID: repoID,
Expand Down
22 changes: 1 addition & 21 deletions models/actions/run_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/setting"

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / lint-backend

"code.gitea.io/gitea/modules/setting" imported and not used (typecheck)

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

"code.gitea.io/gitea/modules/setting" imported and not used (typecheck)

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / checks-backend

"code.gitea.io/gitea/modules/setting" imported and not used

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / checks-backend

"code.gitea.io/gitea/modules/setting" imported and not used

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / checks-backend

"code.gitea.io/gitea/modules/setting" imported and not used

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / checks-backend

"code.gitea.io/gitea/modules/setting" imported and not used

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / checks-backend

"code.gitea.io/gitea/modules/setting" imported and not used

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / checks-backend

"code.gitea.io/gitea/modules/setting" imported and not used

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / checks-backend

"code.gitea.io/gitea/modules/setting" imported and not used

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / checks-backend

"code.gitea.io/gitea/modules/setting" imported and not used

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

"code.gitea.io/gitea/modules/setting" imported and not used (typecheck)

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / backend

"code.gitea.io/gitea/modules/setting" imported and not used

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / test-pgsql

"code.gitea.io/gitea/modules/setting" imported and not used

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / test-mysql

"code.gitea.io/gitea/modules/setting" imported and not used

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / test-unit

"code.gitea.io/gitea/modules/setting" imported and not used

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / test-mssql

"code.gitea.io/gitea/modules/setting" imported and not used

Check failure on line 14 in models/actions/run_job.go

View workflow job for this annotation

GitHub Actions / test-sqlite

"code.gitea.io/gitea/modules/setting" imported and not used
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"

Expand Down Expand Up @@ -213,27 +214,6 @@
}
}

func ShouldWaitJobForConcurrencyEvaluation(job *ActionRunJob) bool {
return job.RawConcurrency != "" && !job.IsConcurrencyEvaluated
}

func ShouldBlockJobByConcurrency(ctx context.Context, job *ActionRunJob) (bool, error) {
if ShouldWaitJobForConcurrencyEvaluation(job) {
panic("job concurrency not evaluated, this function shouldn't be called")
}

if job.ConcurrencyGroup == "" || job.ConcurrencyCancel {
return false, nil
}

runs, jobs, err := GetConcurrentRunsAndJobs(ctx, job.RepoID, job.ConcurrencyGroup, []Status{StatusRunning})
if err != nil {
return false, fmt.Errorf("GetConcurrentRunsAndJobs: %w", err)
}

return len(runs) > 0 || len(jobs) > 0, nil
}

func CancelPreviousJobsByJobConcurrency(ctx context.Context, job *ActionRunJob) (jobsToCancel []*ActionRunJob, _ error) {
if job.RawConcurrency == "" {
return nil, nil
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/actions/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob, shou
return fmt.Errorf("get run %d variables: %w", job.Run.ID, err)
}

if job.RawConcurrency != "" && job.Status != actions_model.StatusBlocked {
if job.RawConcurrency != "" && job.Status == actions_model.StatusWaiting {
err = actions_service.EvaluateJobConcurrencyAndFillJobModel(ctx, job.Run, job, vars)
if err != nil {
return fmt.Errorf("evaluate job concurrency: %w", err)
Expand Down
40 changes: 34 additions & 6 deletions services/actions/clear_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,28 @@ func CleanRepoScheduleTasks(ctx context.Context, repo *repo_model.Repository) er
return err
}

// PrepareToStartJobWithConcurrency prepares a job to start by evaluating its concurrency group and cancelling previous jobs if necessary.
func shouldBlockJobByConcurrency(ctx context.Context, job *actions_model.ActionRunJob) (bool, error) {
if job.RawConcurrency != "" && !job.IsConcurrencyEvaluated {
// when the job depends on other jobs, we cannot evaluate its concurrency, so it should be blocked and will be evaluated again when its dependencies are done
return true, nil
}

if job.ConcurrencyGroup == "" || job.ConcurrencyCancel {
return false, nil
}

runs, jobs, err := actions_model.GetConcurrentRunsAndJobs(ctx, job.RepoID, job.ConcurrencyGroup, []actions_model.Status{actions_model.StatusRunning})
if err != nil {
return false, fmt.Errorf("GetConcurrentRunsAndJobs: %w", err)
}

return len(runs) > 0 || len(jobs) > 0, nil
}

// PrepareToStartJobWithConcurrency prepares a job to start by its evaluated concurrency group and cancelling previous jobs if necessary.
// It returns the new status of the job (either StatusBlocked or StatusWaiting) and any error encountered during the process.
func PrepareToStartJobWithConcurrency(ctx context.Context, job *actions_model.ActionRunJob) (actions_model.Status, error) {
if actions_model.ShouldWaitJobForConcurrencyEvaluation(job) {
return actions_model.StatusBlocked, nil
}
shouldBlock, err := actions_model.ShouldBlockJobByConcurrency(ctx, job)
shouldBlock, err := shouldBlockJobByConcurrency(ctx, job)
if err != nil {
return actions_model.StatusBlocked, err
}
Expand All @@ -79,10 +94,23 @@ func PrepareToStartJobWithConcurrency(ctx context.Context, job *actions_model.Ac
return actions_model.StatusWaiting, err
}

func shouldBlockRunByConcurrency(ctx context.Context, actionRun *actions_model.ActionRun) (bool, error) {
if actionRun.ConcurrencyGroup == "" || actionRun.ConcurrencyCancel {
return false, nil
}

runs, jobs, err := actions_model.GetConcurrentRunsAndJobs(ctx, actionRun.RepoID, actionRun.ConcurrencyGroup, []actions_model.Status{actions_model.StatusRunning})
if err != nil {
return false, fmt.Errorf("find concurrent runs and jobs: %w", err)
}

return len(runs) > 0 || len(jobs) > 0, nil
}

// PrepareToStartRunWithConcurrency prepares a run to start by its evaluated concurrency group and cancelling previous jobs if necessary.
// It returns the new status of the job (either StatusBlocked or StatusWaiting) and any error encountered during the process.
func PrepareToStartRunWithConcurrency(ctx context.Context, run *actions_model.ActionRun) (actions_model.Status, error) {
shouldBlock, err := actions_model.ShouldBlockRunByConcurrency(ctx, run)
shouldBlock, err := shouldBlockRunByConcurrency(ctx, run)
if err != nil {
return actions_model.StatusBlocked, err
}
Expand Down
4 changes: 0 additions & 4 deletions services/actions/job_emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,6 @@ func (r *jobStatusResolver) resolve(ctx context.Context) map[int64]actions_model
}

func updateConcurrencyEvaluationForJobWithNeeds(ctx context.Context, actionRunJob *actions_model.ActionRunJob, vars map[string]string) error {
if !actions_model.ShouldWaitJobForConcurrencyEvaluation(actionRunJob) {
return nil
}

if err := actionRunJob.LoadAttributes(ctx); err != nil {
return err
}
Expand Down
Loading