Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Actions concurrency syntax #32751

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Zettat123
Copy link
Contributor

@Zettat123 Zettat123 commented Dec 7, 2024

Fix #24769
Fix #32662
Fix #33260

Depends on https://gitea.com/gitea/act/pulls/124

⚠️ BREAKING ⚠️

This PR removes the auto-cancellation feature added by #25716. Users need to manually add concurrency to workflows to control concurrent workflows or jobs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 7, 2024
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 7, 2024
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code modifies/migrations modifies/dependencies labels Dec 7, 2024
@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch from 3551677 to fcf4517 Compare December 10, 2024 08:56
@pull-request-size pull-request-size bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 12, 2024
@lunny lunny added this to the 1.24.0 milestone Dec 16, 2024
@pull-request-size pull-request-size bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 16, 2024
@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch from 52833e7 to 130f2a2 Compare December 17, 2024 01:49
@pull-request-size pull-request-size bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 17, 2024
@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch 3 times, most recently from 461c7c1 to d5168a2 Compare January 6, 2025 06:16
@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch from e038ed2 to f77f266 Compare January 10, 2025 06:00
@Zettat123 Zettat123 changed the title WIP: Support concurrency for Actions WIP: Support Actions concurrency syntax Jan 15, 2025
@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch from ad71599 to 8f5948b Compare January 15, 2025 03:03
@Zettat123

This comment was marked as resolved.

wxiaoguang added a commit that referenced this pull request Jan 15, 2025
)

Move the main logic of `generateTaskContext` and `findTaskNeeds` to the
`services` layer.

This is a part of #32751, since we need the git context and `needs` to
parse the concurrency expressions.

---------

Co-authored-by: Lunny Xiao <[email protected]>
Co-authored-by: wxiaoguang <[email protected]>
@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch 2 times, most recently from 87a79d9 to eb43091 Compare January 16, 2025 02:09
@github-actions github-actions bot removed the modifies/api This PR adds API routes or modifies them label Jan 16, 2025
@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch 2 times, most recently from 19d3dcb to 93af0ee Compare January 24, 2025 09:41
project-mirrors-bot-tu bot pushed a commit to project-mirrors/forgejo-as-gitea-fork that referenced this pull request Jan 26, 2025
…gitea#33280)

Move the main logic of `generateTaskContext` and `findTaskNeeds` to the
`services` layer.

This is a part of go-gitea#32751, since we need the git context and `needs` to
parse the concurrency expressions.

---------

Co-authored-by: Lunny Xiao <[email protected]>
Co-authored-by: wxiaoguang <[email protected]>
(cherry picked from commit d0962ce)

Conflicts:
	routers/api/actions/runner/main_test.go
	routers/api/actions/runner/utils.go
	services/actions/context_test.go
	services/actions/init_test.go
	tests/integration/actions_job_test.go
  simple conflicts related to

  ref_type":          string(refName.RefType()),                            // string, The type of ref that triggered the workflow run. Valid values are branch or tag.

  Use env GITEA_RUNNER_REGISTRATION_TOKEN as global runner token (go-gitea#32946)
@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch 2 times, most recently from a1d070c to c433843 Compare February 8, 2025 02:09
@Zettat123 Zettat123 marked this pull request as ready for review February 8, 2025 02:29
@Zettat123 Zettat123 changed the title WIP: Support Actions concurrency syntax Support Actions concurrency syntax Feb 8, 2025
@Zettat123
Copy link
Contributor Author

This PR is ready for review. Please also review https://gitea.com/gitea/act/pulls/124 .

@lunny lunny added the pr/breaking Merging this PR means builds will break. Needs a description what exactly breaks, and how to fix it! label Feb 8, 2025
@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch from c433843 to 7b27a42 Compare February 11, 2025 03:27
@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch from 3263d4e to 85baf37 Compare February 11, 2025 07:03
chhe pushed a commit to chhe/act that referenced this pull request Feb 12, 2025
To support `concurrency` syntax for Gitea Actions

Gitea PR: go-gitea/gitea#32751

Reviewed-on: https://gitea.com/gitea/act/pulls/124
Reviewed-by: Lunny Xiao <[email protected]>
Co-authored-by: Zettat123 <[email protected]>
Co-committed-by: Zettat123 <[email protected]>
@lunny
Copy link
Member

lunny commented Feb 17, 2025

Please resolve the conflicts and since https://gitea.com/gitea/act/pulls/124 merged, this PR can be updated.

@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch from 85baf37 to 9e21174 Compare February 18, 2025 02:50
@Zettat123
Copy link
Contributor Author

Please resolve the conflicts and since https://gitea.com/gitea/act/pulls/124 merged, this PR can be updated.

The conflicts were caused by model migrations instead of gitea/act. Now I've updated this PR and conflicts are resolved.

return ShouldBlockRunByConcurrency(ctx, job.Run)
}

func CancelPreviousJobsByConcurrency(ctx context.Context, job *ActionRunJob) error {
Copy link
Contributor

@ChristopherHX ChristopherHX Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I became today aware of a bug in the CancelPreviousJobs, jobs cancelled by this method don't get it's commit status updated from pending to cancelled this PR rewrites it.

Furthermore the actions_model cannot send webhooks / commit status, my conclusion is we have to change the return type to be like

([]*ActionRunJob, error) and always return the list for all jobs successfully cancelled. Then the actions_service can expose the function to its callers while handling commit status (and in future webhook) by traversing the ActionRunJob array

This bug did hit me in my workflow_job event hook code aka #33694 (comment) and this function reproduces it

The reason I got this bug was that I looked where commitstatus is maintained and this one never triggered a webhook, but it seems to skip commit status as well.

I will write an bug report soon and a proposed fix, but since this PR also changes affected code I want to sync here first.

My idea how to fix this method is shown in #33764 and should be integrated here or fixed differently.

Comment on lines +323 to +326
if err := CancelPreviousJobsByConcurrency(ctx, job); err != nil {
return nil, false, err
}

Copy link
Contributor

@ChristopherHX ChristopherHX Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...per previous comment, this need to forward cancelled jobs as list to actions_service for both error and non error return value (we need to maintain the successfully cancelled status checks even if some failed)

actually this PR simplifies the bug surface a lot, only pickTask in actions services is a caller.
The old auto conconcurrency had a much larger defect area

r := newJobStatusResolver(tt.jobs)
assert.Equal(t, tt.want, r.Resolve())
r := newJobStatusResolver(tt.jobs, nil)
assert.Equal(t, tt.want, r.Resolve(context.Background()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert.Equal(t, tt.want, r.Resolve(context.Background()))
assert.Equal(t, tt.want, r.Resolve(t.Context()))

}

gitCtx := GenerateGiteaContext(run, nil)
jobResults := map[string]*jobparser.JobResult{"": {}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the empty element is necessary?

@@ -99,6 +100,9 @@ func (opts FindRunOptions) ToConds() builder.Cond {
if opts.TriggerEvent != "" {
cond = cond.And(builder.Eq{"trigger_event": opts.TriggerEvent})
}
if len(opts.ConcurrencyGroup) > 0 {
cond = cond.And(builder.Eq{"concurrency_group": opts.ConcurrencyGroup})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is concurrency_group an index column?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/dependencies modifies/go Pull requests that update Go code modifies/migrations pr/breaking Merging this PR means builds will break. Needs a description what exactly breaks, and how to fix it! size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
4 participants