jojo/models
Mathieu Fenniak 5f757d9e83 [v13.0/forgejo] feat: allow workflows to control cancellation of existing jobs (#9797)
Partial backport of #9434.

Fixes a bug: it was intended that pushes to a branch and pushes to a pull request would cancel any previous running job from the same workflow, however this functionality only worked on a `on: push` workflow.  This PR fixes it for an `on: pull_request` workflow.

Adds a feature: `concurrency.cancel-in-progress` can be used to override the automatic cancellation behaviour and disable it.

It can be disabled unconditionally in a workflow:
```yaml
concurrency:
    cancel-in-progress: false
```

Or it can be disabled with some logic; for example, keeping the cancel behaviour on PRs but disabling it otherwise:
```yaml
concurrency:
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}
```

Only a small subset of automated tests were applicable for backport, so I supplemented with manual testing in these cases:

|                                                                    | Expected      | Actual        |
| ------------------------------------------------------------------ | ------------- | ------------- |
| Default behaviour:                                                 |               |               |
| on: pull_request -- push to a PR when it's already running         | Cancelled     | Cancelled     |
| on: push -- push to a branch (eg. main) when it's already running  | Cancelled     | Cancelled     |
| on: workflow_dispatch -- run again when it is already running      | Multiple Runs | Multiple Runs |
|                                                                    |               |               |
| Set cancel-in-progress: true                                       |               |               |
| on: pull_request -- push to a PR when it's already running         | Cancelled     | Cancelled     |
| on: push -- push to a branch (eg. main) when it's already running  | Cancelled     | Cancelled     |
| on: workflow_dispatch -- run again when it is already running      | Multiple Runs | Multiple Runs |
|                                                                    |               |               |
| Set cancel-in-progress: false                                      |               |               |
| on: pull_request -- push to a PR when it's already running         | Multiple Runs | Multiple Runs |
| on: push -- push to a branch (eg. main) when it's already running  | Multiple Runs | Multiple Runs |
| on: workflow_dispatch -- run again when it is already running      | Multiple Runs | Multiple Runs |
|                                                                    |               |               |
| Set cancel-in-progress: ${{ github.event_name == 'pull_request' }} |               |               |
| on: pull_request -- push to a PR when it's already running         | Cancelled     | Cancelled     |
| on: push -- push to a branch (eg. main) when it's already running  | Multiple Runs | Multiple Runs |
| on: workflow_dispatch -- run again when it is already running      | Multiple Runs | Multiple Runs |

## Checklist

The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org).

### Tests

- I added test coverage for Go changes...
  - [x] in their respective `*_test.go` for unit tests.
  - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server.
- I added test coverage for JavaScript changes...
  - [ ] in `web_src/js/*.test.js` if it can be unit tested.
  - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)).

### Documentation

- [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change.
  - **TODO:**  Will backport the relevant documentation.
- [ ] I did not document these changes and I do not expect someone else to do it.

### Release notes

- [ ] I do not want this change to show in the release notes.
- [x] I want the title to show in the release notes with a link to this pull request.
- [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title.

<!--start release-notes-assistant-->

## Release notes
<!--URL:https://codeberg.org/forgejo/forgejo-->
- Features
  - [PR](https://codeberg.org/forgejo/forgejo/pulls/9797): <!--number 9797 --><!--line 0 --><!--description ZmVhdDogYWxsb3cgd29ya2Zsb3dzIHRvIGNvbnRyb2wgY2FuY2VsbGF0aW9uIG9mIGV4aXN0aW5nIGpvYnM=-->feat: allow workflows to control cancellation of existing jobs<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9797
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net>
Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
2025-11-23 23:01:09 +01:00
..
actions [v13.0/forgejo] feat: allow workflows to control cancellation of existing jobs (#9797) 2025-11-23 23:01:09 +01:00
activities fix: prevent user-entered text with | characters from being truncated in activity feed (#8844) 2025-08-10 19:48:46 +02:00
admin chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
asymkey feat(build): improve lint-locale-usage further (#8736) 2025-08-27 23:47:34 +02:00
auth chore: add SQL fault injector testing (#9314) 2025-09-18 00:39:06 +02:00
avatars chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
db [v13.0/forgejo] fix: get new session from enginegroup instead of masterengine (#10148) 2025-11-18 06:28:07 +01:00
dbfs Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
fixtures [v13.0/forgejo] fix: endless redirection loop between /user/settings/change_password and /user/settings/security (#10013) 2025-11-07 22:38:32 +01:00
forgefed Federated user activity following: Isolated model changes (#8078) 2025-06-21 12:02:58 +02:00
forgejo/semver Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
forgejo_migrations Update module golang.org/x/crypto to v0.45.0 (v13.0/forgejo) (#10175) 2025-11-20 13:00:29 +01:00
git feat: always publish the link to the commit status (#8177) 2025-06-13 12:41:34 +02:00
issues fix: do not display the title of unsubscribed issues or pull requests in the notification web page (#9362) 2025-09-19 22:32:06 +02:00
migrations [v13.0/forgejo] fix: strict error handling on corrupted DB migration tracking tables (#9776) 2025-10-20 19:13:50 +02:00
moderation feat(build): improve lint-locale-usage further (#8736) 2025-08-27 23:47:34 +02:00
organization [v13.0/forgejo] fix: prevent orgs from being added as members of orgs (#10027) 2025-11-08 22:50:35 +01:00
packages several fixes of ALT Package registry (#8475) 2025-07-10 17:12:07 +02:00
perm fix: allow Actions tokens to access repos readable by signed in users (#8889) 2025-08-18 14:40:07 +02:00
project feat(build): improve lint-locale-usage further (#8736) 2025-08-27 23:47:34 +02:00
pull fix: do not ignore automerge while a PR is checking for conflicts (#8189) 2025-06-17 10:58:07 +02:00
quota fix: quotas double counting repo size when calculating size:all (#9234) 2025-09-11 16:30:04 +02:00
repo chore: remove redundant code (#9378) 2025-09-22 09:18:19 +02:00
secret feat: migrate action secrets to keying to store them more securely (#8692) 2025-07-29 01:03:36 +02:00
shared/types chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
system Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
unit feat(build): improve lint-locale-usage further (#8736) 2025-08-27 23:47:34 +02:00
unittest chore: add SQL fault injector testing (#9314) 2025-09-18 00:39:06 +02:00
user [v13.0/forgejo] fix: prevent orgs from being added as members of orgs (#10027) 2025-11-08 22:50:35 +01:00
webhook Actions Failure, Succes, Recover Webhooks (#7508) 2025-06-03 14:29:19 +02:00
error.go fix: don't allow credentials in migrate/push mirror URL 2025-08-30 08:07:23 +02:00
main_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
org.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
org_team.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
org_team_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
org_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
repo.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
repo_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
repo_transfer.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
repo_transfer_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00