mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-18 19:11:06 +00:00
## Fixes #36983 ## Summary 1. Add transitional `Cancelling` status (between `Running` and `Cancelled`); cancel flow marks active tasks `Cancelling`, runner finalizes to `Cancelled` on terminal result. 2. Taskless jobs cancel directly (no runner to finalize). 3. Runner-protocol responses map `Cancelling` → `RESULT_CANCELLED`. 4. Run/job aggregation treats `Cancelling` as active. 5. Status mapping/aggregation tests + en-US locale added. **Problem** When a workflow was cancelled from the UI, jobs were marked cancelled immediately, which could skip post-run cleanup behavior. ## Solution Use a transitional status path: Running → Cancelling → Cancelled This allows runner finalization and cleanup path execution before final terminal state. **Testing** > 1. go test -tags "sqlite sqlite_unlock_notify" ./models/actions -run "TestAggregateJobStatus|TestStatusAsResult|TestStatusFromResult" > 2. go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.11.4 run ./models/actions/... ./routers/api/actions/runner/... ## Related - act_runner: https://gitea.com/gitea/act_runner/pulls/825 — independent; this PR's capability gate keeps legacy runners on the immediate-cancel path. The new flow activates only for runners that advertise the `cancelling` capability. Co-authored-by: Nicolas <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com> Co-authored-by: Zettat123 <zettat123@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io>
131 lines
3.3 KiB
Go
131 lines
3.3 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"slices"
|
|
|
|
"code.gitea.io/gitea/modules/translation"
|
|
|
|
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
|
|
)
|
|
|
|
// Status represents the status of ActionRun, ActionRunJob, ActionTask, or ActionTaskStep
|
|
type Status int
|
|
|
|
const (
|
|
StatusUnknown Status = iota // 0, consistent with runnerv1.Result_RESULT_UNSPECIFIED
|
|
StatusSuccess // 1, consistent with runnerv1.Result_RESULT_SUCCESS
|
|
StatusFailure // 2, consistent with runnerv1.Result_RESULT_FAILURE
|
|
StatusCancelled // 3, consistent with runnerv1.Result_RESULT_CANCELLED
|
|
StatusSkipped // 4, consistent with runnerv1.Result_RESULT_SKIPPED
|
|
StatusWaiting // 5, isn't a runnerv1.Result
|
|
StatusRunning // 6, isn't a runnerv1.Result
|
|
StatusBlocked // 7, isn't a runnerv1.Result
|
|
StatusCancelling // 8, isn't a runnerv1.Result
|
|
)
|
|
|
|
var statusNames = map[Status]string{
|
|
StatusUnknown: "unknown",
|
|
StatusWaiting: "waiting",
|
|
StatusRunning: "running",
|
|
StatusSuccess: "success",
|
|
StatusFailure: "failure",
|
|
StatusCancelled: "cancelled",
|
|
StatusCancelling: "cancelling",
|
|
StatusSkipped: "skipped",
|
|
StatusBlocked: "blocked",
|
|
}
|
|
|
|
// String returns the string name of the Status
|
|
func (s Status) String() string {
|
|
return statusNames[s]
|
|
}
|
|
|
|
// LocaleString returns the locale string name of the Status
|
|
func (s Status) LocaleString(lang translation.Locale) string {
|
|
return lang.TrString("actions.status." + s.String())
|
|
}
|
|
|
|
// IsDone returns whether the Status is final
|
|
func (s Status) IsDone() bool {
|
|
return s.In(StatusSuccess, StatusFailure, StatusCancelled, StatusSkipped)
|
|
}
|
|
|
|
// HasRun returns whether the Status is a result of running
|
|
func (s Status) HasRun() bool {
|
|
return s.In(StatusSuccess, StatusFailure)
|
|
}
|
|
|
|
func (s Status) IsUnknown() bool {
|
|
return s == StatusUnknown
|
|
}
|
|
|
|
func (s Status) IsSuccess() bool {
|
|
return s == StatusSuccess
|
|
}
|
|
|
|
func (s Status) IsFailure() bool {
|
|
return s == StatusFailure
|
|
}
|
|
|
|
func (s Status) IsCancelled() bool {
|
|
return s == StatusCancelled
|
|
}
|
|
|
|
func (s Status) IsSkipped() bool {
|
|
return s == StatusSkipped
|
|
}
|
|
|
|
func (s Status) IsWaiting() bool {
|
|
return s == StatusWaiting
|
|
}
|
|
|
|
func (s Status) IsRunning() bool {
|
|
return s == StatusRunning
|
|
}
|
|
|
|
func (s Status) IsBlocked() bool {
|
|
return s == StatusBlocked
|
|
}
|
|
|
|
func (s Status) IsCancelling() bool {
|
|
return s == StatusCancelling
|
|
}
|
|
|
|
// In returns whether s is one of the given statuses
|
|
func (s Status) In(statuses ...Status) bool {
|
|
return slices.Contains(statuses, s)
|
|
}
|
|
|
|
func (s Status) AsResult() runnerv1.Result {
|
|
switch s {
|
|
case StatusSuccess:
|
|
return runnerv1.Result_RESULT_SUCCESS
|
|
case StatusFailure:
|
|
return runnerv1.Result_RESULT_FAILURE
|
|
case StatusCancelled, StatusCancelling:
|
|
return runnerv1.Result_RESULT_CANCELLED
|
|
case StatusSkipped:
|
|
return runnerv1.Result_RESULT_SKIPPED
|
|
default:
|
|
return runnerv1.Result_RESULT_UNSPECIFIED
|
|
}
|
|
}
|
|
|
|
func StatusFromResult(r runnerv1.Result) Status {
|
|
switch r {
|
|
case runnerv1.Result_RESULT_SUCCESS:
|
|
return StatusSuccess
|
|
case runnerv1.Result_RESULT_FAILURE:
|
|
return StatusFailure
|
|
case runnerv1.Result_RESULT_CANCELLED:
|
|
return StatusCancelled
|
|
case runnerv1.Result_RESULT_SKIPPED:
|
|
return StatusSkipped
|
|
default:
|
|
return StatusUnknown
|
|
}
|
|
}
|