Skip to content

Commit 547df2a

Browse files
committed
Merge remote-tracking branch 'origin/main' into patch-mail-templates-1
2 parents 5c6c94e + c10c420 commit 547df2a

File tree

96 files changed

+2445
-2935
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+2445
-2935
lines changed

.github/workflows/pull-compliance.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@ jobs:
3232
runs-on: ubuntu-latest
3333
steps:
3434
- uses: actions/checkout@v4
35-
- uses: actions/setup-python@v5
36-
with:
37-
python-version: "3.12"
35+
- uses: astral-sh/setup-uv@v6
36+
- run: uv python install 3.12
3837
- uses: actions/setup-node@v4
3938
with:
4039
node-version: 24
4140
cache: npm
4241
cache-dependency-path: package-lock.json
43-
- run: pip install uv
4442
- run: make deps-py
4543
- run: make deps-frontend
4644
- run: make lint-templates
@@ -51,10 +49,8 @@ jobs:
5149
runs-on: ubuntu-latest
5250
steps:
5351
- uses: actions/checkout@v4
54-
- uses: actions/setup-python@v5
55-
with:
56-
python-version: "3.12"
57-
- run: pip install uv
52+
- uses: astral-sh/setup-uv@v6
53+
- run: uv python install 3.12
5854
- run: make deps-py
5955
- run: make lint-yaml
6056

models/actions/run.go

Lines changed: 55 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -282,77 +282,72 @@ func CancelPreviousJobs(ctx context.Context, repoID int64, ref, workflowID strin
282282
// InsertRun inserts a run
283283
// The title will be cut off at 255 characters if it's longer than 255 characters.
284284
func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWorkflow) error {
285-
ctx, committer, err := db.TxContext(ctx)
286-
if err != nil {
287-
return err
288-
}
289-
defer committer.Close()
290-
291-
index, err := db.GetNextResourceIndex(ctx, "action_run_index", run.RepoID)
292-
if err != nil {
293-
return err
294-
}
295-
run.Index = index
296-
run.Title = util.EllipsisDisplayString(run.Title, 255)
297-
298-
if err := db.Insert(ctx, run); err != nil {
299-
return err
300-
}
301-
302-
if run.Repo == nil {
303-
repo, err := repo_model.GetRepositoryByID(ctx, run.RepoID)
285+
return db.WithTx(ctx, func(ctx context.Context) error {
286+
index, err := db.GetNextResourceIndex(ctx, "action_run_index", run.RepoID)
304287
if err != nil {
305288
return err
306289
}
307-
run.Repo = repo
308-
}
290+
run.Index = index
291+
run.Title = util.EllipsisDisplayString(run.Title, 255)
309292

310-
if err := updateRepoRunsNumbers(ctx, run.Repo); err != nil {
311-
return err
312-
}
313-
314-
runJobs := make([]*ActionRunJob, 0, len(jobs))
315-
var hasWaiting bool
316-
for _, v := range jobs {
317-
id, job := v.Job()
318-
needs := job.Needs()
319-
if err := v.SetJob(id, job.EraseNeeds()); err != nil {
293+
if err := db.Insert(ctx, run); err != nil {
320294
return err
321295
}
322-
payload, _ := v.Marshal()
323-
status := StatusWaiting
324-
if len(needs) > 0 || run.NeedApproval {
325-
status = StatusBlocked
326-
} else {
327-
hasWaiting = true
296+
297+
if run.Repo == nil {
298+
repo, err := repo_model.GetRepositoryByID(ctx, run.RepoID)
299+
if err != nil {
300+
return err
301+
}
302+
run.Repo = repo
328303
}
329-
job.Name = util.EllipsisDisplayString(job.Name, 255)
330-
runJobs = append(runJobs, &ActionRunJob{
331-
RunID: run.ID,
332-
RepoID: run.RepoID,
333-
OwnerID: run.OwnerID,
334-
CommitSHA: run.CommitSHA,
335-
IsForkPullRequest: run.IsForkPullRequest,
336-
Name: job.Name,
337-
WorkflowPayload: payload,
338-
JobID: id,
339-
Needs: needs,
340-
RunsOn: job.RunsOn(),
341-
Status: status,
342-
})
343-
}
344-
if err := db.Insert(ctx, runJobs); err != nil {
345-
return err
346-
}
347304

348-
// if there is a job in the waiting status, increase tasks version.
349-
if hasWaiting {
350-
if err := IncreaseTaskVersion(ctx, run.OwnerID, run.RepoID); err != nil {
305+
if err := updateRepoRunsNumbers(ctx, run.Repo); err != nil {
351306
return err
352307
}
353-
}
354308

355-
return committer.Commit()
309+
runJobs := make([]*ActionRunJob, 0, len(jobs))
310+
var hasWaiting bool
311+
for _, v := range jobs {
312+
id, job := v.Job()
313+
needs := job.Needs()
314+
if err := v.SetJob(id, job.EraseNeeds()); err != nil {
315+
return err
316+
}
317+
payload, _ := v.Marshal()
318+
status := StatusWaiting
319+
if len(needs) > 0 || run.NeedApproval {
320+
status = StatusBlocked
321+
} else {
322+
hasWaiting = true
323+
}
324+
job.Name = util.EllipsisDisplayString(job.Name, 255)
325+
runJobs = append(runJobs, &ActionRunJob{
326+
RunID: run.ID,
327+
RepoID: run.RepoID,
328+
OwnerID: run.OwnerID,
329+
CommitSHA: run.CommitSHA,
330+
IsForkPullRequest: run.IsForkPullRequest,
331+
Name: job.Name,
332+
WorkflowPayload: payload,
333+
JobID: id,
334+
Needs: needs,
335+
RunsOn: job.RunsOn(),
336+
Status: status,
337+
})
338+
}
339+
if err := db.Insert(ctx, runJobs); err != nil {
340+
return err
341+
}
342+
343+
// if there is a job in the waiting status, increase tasks version.
344+
if hasWaiting {
345+
if err := IncreaseTaskVersion(ctx, run.OwnerID, run.RepoID); err != nil {
346+
return err
347+
}
348+
}
349+
return nil
350+
})
356351
}
357352

358353
func GetRunByRepoAndID(ctx context.Context, repoID, runID int64) (*ActionRun, error) {

models/actions/run_job.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ func AggregateJobStatus(jobs []*ActionRunJob) Status {
187187
return StatusCancelled
188188
case hasRunning:
189189
return StatusRunning
190-
case hasFailure:
191-
return StatusFailure
192190
case hasWaiting:
193191
return StatusWaiting
192+
case hasFailure:
193+
return StatusFailure
194194
case hasBlocked:
195195
return StatusBlocked
196196
default:

models/actions/run_job_status_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestAggregateJobStatus(t *testing.T) {
6464
{[]Status{StatusFailure, StatusSuccess}, StatusFailure},
6565
{[]Status{StatusFailure, StatusSkipped}, StatusFailure},
6666
{[]Status{StatusFailure, StatusCancelled}, StatusCancelled},
67-
{[]Status{StatusFailure, StatusWaiting}, StatusFailure},
67+
{[]Status{StatusFailure, StatusWaiting}, StatusWaiting},
6868
{[]Status{StatusFailure, StatusRunning}, StatusRunning},
6969
{[]Status{StatusFailure, StatusBlocked}, StatusFailure},
7070

models/actions/schedule.go

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -56,65 +56,54 @@ func CreateScheduleTask(ctx context.Context, rows []*ActionSchedule) error {
5656
return nil
5757
}
5858

59-
// Begin transaction
60-
ctx, committer, err := db.TxContext(ctx)
61-
if err != nil {
62-
return err
63-
}
64-
defer committer.Close()
65-
66-
// Loop through each schedule row
67-
for _, row := range rows {
68-
row.Title = util.EllipsisDisplayString(row.Title, 255)
69-
// Create new schedule row
70-
if err = db.Insert(ctx, row); err != nil {
71-
return err
72-
}
73-
74-
// Loop through each schedule spec and create a new spec row
75-
now := time.Now()
76-
77-
for _, spec := range row.Specs {
78-
specRow := &ActionScheduleSpec{
79-
RepoID: row.RepoID,
80-
ScheduleID: row.ID,
81-
Spec: spec,
82-
}
83-
// Parse the spec and check for errors
84-
schedule, err := specRow.Parse()
85-
if err != nil {
86-
continue // skip to the next spec if there's an error
59+
return db.WithTx(ctx, func(ctx context.Context) error {
60+
// Loop through each schedule row
61+
for _, row := range rows {
62+
row.Title = util.EllipsisDisplayString(row.Title, 255)
63+
// Create new schedule row
64+
if err := db.Insert(ctx, row); err != nil {
65+
return err
8766
}
8867

89-
specRow.Next = timeutil.TimeStamp(schedule.Next(now).Unix())
90-
91-
// Insert the new schedule spec row
92-
if err = db.Insert(ctx, specRow); err != nil {
93-
return err
68+
// Loop through each schedule spec and create a new spec row
69+
now := time.Now()
70+
71+
for _, spec := range row.Specs {
72+
specRow := &ActionScheduleSpec{
73+
RepoID: row.RepoID,
74+
ScheduleID: row.ID,
75+
Spec: spec,
76+
}
77+
// Parse the spec and check for errors
78+
schedule, err := specRow.Parse()
79+
if err != nil {
80+
continue // skip to the next spec if there's an error
81+
}
82+
83+
specRow.Next = timeutil.TimeStamp(schedule.Next(now).Unix())
84+
85+
// Insert the new schedule spec row
86+
if err = db.Insert(ctx, specRow); err != nil {
87+
return err
88+
}
9489
}
9590
}
96-
}
97-
98-
// Commit transaction
99-
return committer.Commit()
91+
return nil
92+
})
10093
}
10194

10295
func DeleteScheduleTaskByRepo(ctx context.Context, id int64) error {
103-
ctx, committer, err := db.TxContext(ctx)
104-
if err != nil {
105-
return err
106-
}
107-
defer committer.Close()
108-
109-
if _, err := db.GetEngine(ctx).Delete(&ActionSchedule{RepoID: id}); err != nil {
110-
return err
111-
}
96+
return db.WithTx(ctx, func(ctx context.Context) error {
97+
if _, err := db.GetEngine(ctx).Delete(&ActionSchedule{RepoID: id}); err != nil {
98+
return err
99+
}
112100

113-
if _, err := db.GetEngine(ctx).Delete(&ActionScheduleSpec{RepoID: id}); err != nil {
114-
return err
115-
}
101+
if _, err := db.GetEngine(ctx).Delete(&ActionScheduleSpec{RepoID: id}); err != nil {
102+
return err
103+
}
116104

117-
return committer.Commit()
105+
return nil
106+
})
118107
}
119108

120109
func CleanRepoScheduleTasks(ctx context.Context, repo *repo_model.Repository) ([]*ActionRunJob, error) {

0 commit comments

Comments
 (0)