Skip to content

Support Actions concurrency syntax #32751

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

Open
wants to merge 6 commits 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
@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
@lunny lunny added this to the 1.24.0 milestone Dec 16, 2024
@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch from 52833e7 to 130f2a2 Compare December 17, 2024 01:49
@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 <xiaolunwen@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@lunny lunny mentioned this pull request May 1, 2025
@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch 2 times, most recently from a73ff44 to 5b12954 Compare May 1, 2025 22:03
@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch 2 times, most recently from 90bb647 to 661dcf0 Compare May 11, 2025 22:25
@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch from 661dcf0 to d805fce Compare May 16, 2025 16:53
@lunny
Copy link
Member

lunny commented May 18, 2025

I created a test workflow file like this

on:
  push:
    branches:
      - main

concurrency:
  group: example-group
  cancel-in-progress: true

jobs:
  job-1:
    runs-on: ubuntu-latest
    steps:
      - run: echo 'test1' && sleep 60

But it seems new run task will not cancel the old one.

@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch from d805fce to 3ddc132 Compare May 20, 2025 16:53
@lunny
Copy link
Member

lunny commented May 20, 2025

For pull request jobs, maybe the previous job should be cancelled by default even if there is not concurrency statement.

@Zettat123 Zettat123 force-pushed the support-actions-concurrency branch from 4ddf509 to d6a95ce Compare May 20, 2025 19:54
@Zettat123
Copy link
Contributor Author

I created a test workflow file like this

on:
  push:
    branches:
      - main

concurrency:
  group: example-group
  cancel-in-progress: true

jobs:
  job-1:
    runs-on: ubuntu-latest
    steps:
      - run: echo 'test1' && sleep 60

But it seems new run task will not cancel the old one.

Good catch. There was a bug when checking workflow-level concurrency groups. Now it has been fixed.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 20, 2025
@ChristopherHX
Copy link
Contributor

ChristopherHX commented May 22, 2025

I just tried this, with workflow

on: push
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        no:
        - 1
        - 2
        - 3
        - 4
        - 5
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v4
    - name: Run tests
      run: |
        echo ${{ github.run_id }} > "/tmp/test.txt"
    - uses: christopherhx/gitea-upload-artifact@v4
      with:
        path: test.txt
        name: test
  • Without any connected act_runner I pushed this via automation.
  • pushed a second file
  • Connect a single act_runner
  • All good first workflow cancelled, last push succeeded 👍
  • Now rerun all jobs of the previously cancelled run
  • Rerun all jobs latest previously successful run (directly after the other rerun)
  • latest previously successful rerun is cancelled and the rerun of "previously cancelled" succeeded

I expected the same result as on initial push, same order opposite behavior

Maybe you could provide me some insights, or I am going to debug this myself and share you my findings

What works good so far

  • Pushing two workflows without concurrency, I like this

@@ -53,6 +53,10 @@ func PickTask(ctx context.Context, runner *actions_model.ActionRunner) (*runnerv
return nil
}

if err := CancelJobsByJobConcurrency(ctx, t.Job); err != nil {
Copy link
Contributor

@ChristopherHX ChristopherHX May 22, 2025

Choose a reason for hiding this comment

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

This code is cancelling implicitly a newer (re)run while a task is picked by an older (re)run and seems to be the cause for the behavior I described just before

I would expect only scheduling a job updates concurrency, since I am still using GitHub Actions side by side

Rerun all jobs didn't cancel the older run, which is already an error state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Rerun all jobs didn't cancel the older run, which is already an error state.

Status fixed, by respecting workflow concurrency in rerun all jobs.

Comment on lines +252 to +266
// cancel previous jobs in the same concurrency group
previousJobs, err := db.Find[ActionRunJob](ctx, &FindRunJobOptions{
RepoID: job.RepoID,
ConcurrencyGroup: job.ConcurrencyGroup,
Statuses: []Status{StatusRunning, StatusWaiting, StatusBlocked},
})
if err != nil {
return cancelledJobs, fmt.Errorf("find previous jobs: %w", err)
}
previousJobs = slices.DeleteFunc(previousJobs, func(j *ActionRunJob) bool { return j.ID == job.ID })
cjs, err := CancelJobs(ctx, previousJobs)
if err != nil {
return cancelledJobs, fmt.Errorf("cancel previous jobs: %w", err)
}
cancelledJobs = append(cancelledJobs, cjs...)
Copy link
Contributor

@ChristopherHX ChristopherHX May 22, 2025

Choose a reason for hiding this comment

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

I would expect that job concurrency key cancels equal workflow concurrency if defined on job level.

Based on my experience workflow and job concurrency use the same pool of concurrency keys. (deadlock handling required)

and CancelPreviousJobsByRunConcurrency to not be called here (EDIT 2 idk how this PR currently works, might break everything if not replaced)

e.g.

jobs:
  _:
    concurrency: test

cancels workflow

concurrency: test

In response of the unexpected behavior I have seen

EDIT
If we add an optional job / string parameter to CancelPreviousJobsByRunConcurrency , so the concurrency group of the job can be provided to replace the run concurrency key would fulfill my expectation, I guess.

@seriouz
Copy link

seriouz commented Jul 8, 2025

Any news on this? Is this still planed for 1.25.0?

@ChristopherHX
Copy link
Contributor

@Zettat123 I would try to fix my findings here and resolve the conflicts, but I have no access to this Pullrequest (Maintainer with read only access).

Allowing to queue up Workflows again is very nice, since I am not in favor of auto concurrency of length 1.

For own CI feedback I need create a new (draft) PR including all commits from here.

Then there are multiple options

  • I create a PR against the PR branch
  • You push my changes to your branch
  • We continue discussing on my followup PR

Thank you for all your work on this so far :).

@wxiaoguang
Copy link
Contributor

If you'd like to work with others' PRs often, maybe you can ask @go-gitea/technical-oversight-committee or some core members like @lunny to apply a merger's access, then you can edit PRs directly

@ChristopherHX
Copy link
Contributor

I would expect this to happen < 5 times per year. I actually only applied as maintainer due to work with others' PRs. I will ask formally in discord.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. 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!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

workflow_dispatch allows only one job in a branch [Actions] Opt-out from auto-cancellation [Actions] Support concurrency syntax
7 participants