-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Introduce ActionRunAttempt to represent each execution of a run
#37119
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
Draft
Zettat123
wants to merge
22
commits into
go-gitea:main
Choose a base branch
from
Zettat123:run-attempt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2f5cdb9
add run_attempt
Zettat123 d83ec3a
fix check concurrency bug
Zettat123 cc7ca30
fix find needs
Zettat123 19c82f9
fix parse 'attempt'
Zettat123 8b79334
remove unused field
Zettat123 e38cb32
remove GetLatestAttemptByRunID
Zettat123 5f188ca
fix tabs
Zettat123 eb294a3
fix
Zettat123 4fe29a1
fix models
Zettat123 738728d
fix model bugs
Zettat123 6918e8c
fix api
Zettat123 7d572e5
fix api
Zettat123 4c8b561
fix test
Zettat123 5d4a2c9
fix concurrency/rerun test
Zettat123 0f50150
Merge branch 'main' into run-attempt
Zettat123 20608e3
fix calculateDuration
Zettat123 6883819
fix rerun test
Zettat123 735c41b
improve rerun/actions log test
Zettat123 52c4e28
API support
Zettat123 870b17f
update swagger
Zettat123 674348a
fix test
Zettat123 f8c9a0e
fix lint
Zettat123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package actions | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "slices" | ||
| "time" | ||
|
|
||
| "code.gitea.io/gitea/models/db" | ||
| user_model "code.gitea.io/gitea/models/user" | ||
| "code.gitea.io/gitea/modules/timeutil" | ||
| "code.gitea.io/gitea/modules/util" | ||
| ) | ||
|
|
||
| // RunAttempt represents a single execution attempt of an ActionRun. | ||
| type RunAttempt struct { | ||
| ID int64 | ||
| RepoID int64 `xorm:"index"` | ||
| RunID int64 `xorm:"index UNIQUE(run_attempt)"` | ||
| Run *ActionRun `xorm:"-"` | ||
| Attempt int64 `xorm:"UNIQUE(run_attempt)"` | ||
|
|
||
| TriggerUserID int64 `xorm:"index"` | ||
| TriggerUser *user_model.User `xorm:"-"` | ||
|
|
||
| ConcurrencyGroup string | ||
| ConcurrencyCancel bool `xorm:"NOT NULL DEFAULT FALSE"` | ||
|
|
||
| Status Status `xorm:"index"` | ||
| Started timeutil.TimeStamp | ||
| RunStartedAt timeutil.TimeStamp | ||
| Stopped timeutil.TimeStamp | ||
|
|
||
| Created timeutil.TimeStamp `xorm:"created"` | ||
| Updated timeutil.TimeStamp `xorm:"updated"` | ||
| } | ||
|
|
||
| func (*RunAttempt) TableName() string { | ||
| return "action_run_attempt" | ||
| } | ||
|
|
||
| func init() { | ||
| db.RegisterModel(new(RunAttempt)) | ||
| } | ||
|
|
||
| func (attempt *RunAttempt) Duration() time.Duration { | ||
| return calculateDuration(attempt.Started, attempt.Stopped, attempt.Status) | ||
| } | ||
|
|
||
| func GetRunAttemptByRepoAndID(ctx context.Context, repoID, attemptID int64) (*RunAttempt, error) { | ||
| var attempt RunAttempt | ||
| has, err := db.GetEngine(ctx).Where("repo_id=? AND id=?", repoID, attemptID).Get(&attempt) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if !has { | ||
| return nil, fmt.Errorf("run attempt %d in repo %d: %w", attemptID, repoID, util.ErrNotExist) | ||
| } | ||
| return &attempt, nil | ||
| } | ||
|
|
||
| func GetLatestAttemptByRunID(ctx context.Context, runID int64) (*RunAttempt, bool, error) { | ||
Zettat123 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| var attempt RunAttempt | ||
| has, err := db.GetEngine(ctx).Where("run_id=?", runID).Desc("attempt").Get(&attempt) | ||
| if err != nil { | ||
| return nil, false, err | ||
| } else if !has { | ||
| return nil, false, nil | ||
| } | ||
| return &attempt, true, nil | ||
| } | ||
|
|
||
| func GetRunAttemptByRunIDAndAttemptNum(ctx context.Context, runID, attemptNum int64) (*RunAttempt, error) { | ||
| var attempt RunAttempt | ||
| has, err := db.GetEngine(ctx).Where("run_id=? AND attempt=?", runID, attemptNum).Get(&attempt) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if !has { | ||
| return nil, fmt.Errorf("run attempt %d for run %d: %w", attemptNum, runID, util.ErrNotExist) | ||
| } | ||
| return &attempt, nil | ||
| } | ||
|
|
||
| func ListRunAttemptsByRunID(ctx context.Context, runID int64) ([]*RunAttempt, error) { | ||
| return db.Find[RunAttempt](ctx, &FindRunAttemptOptions{ | ||
| RunID: runID, | ||
| ListOptions: db.ListOptionsAll, | ||
| }) | ||
| } | ||
|
|
||
| func UpdateRunAttempt(ctx context.Context, attempt *RunAttempt, cols ...string) error { | ||
| sess := db.GetEngine(ctx).ID(attempt.ID) | ||
| if len(cols) > 0 { | ||
| sess.Cols(cols...) | ||
| } | ||
| if _, err := sess.Update(attempt); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if len(cols) > 0 && !slices.Contains(cols, "status") && !slices.Contains(cols, "started") && !slices.Contains(cols, "stopped") { | ||
| return nil | ||
| } | ||
|
|
||
| run, err := GetRunByRepoAndID(ctx, attempt.RepoID, attempt.RunID) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if run.LatestAttemptID != attempt.ID { | ||
| return nil | ||
| } | ||
|
|
||
| run.Status = attempt.Status | ||
| run.Started = attempt.Started | ||
| run.Stopped = attempt.Stopped | ||
| return UpdateRun(ctx, run, "status", "started", "stopped") | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.