|
4 | 4 | package actions |
5 | 5 |
|
6 | 6 | import ( |
7 | | - actions_module "code.gitea.io/gitea/modules/actions" |
8 | | - container_module "code.gitea.io/gitea/modules/container" |
9 | | - log_module "code.gitea.io/gitea/modules/log" |
10 | | - storage_module "code.gitea.io/gitea/modules/storage" |
11 | 7 | "context" |
12 | 8 | "errors" |
13 | 9 | "fmt" |
@@ -443,74 +439,4 @@ func UpdateRun(ctx context.Context, run *ActionRun, cols ...string) error { |
443 | 439 | return nil |
444 | 440 | } |
445 | 441 |
|
446 | | -// TODO: When deleting a run, it should at lease delete artifacts, tasks logs, database record. |
447 | | -func DeleteRun(ctx context.Context, repoID int64, run *ActionRun, jobs []*ActionRunJob) error { |
448 | | - tasks := make(TaskList, 0) |
449 | | - |
450 | | - jobIDs := container_module.FilterSlice(jobs, func(j *ActionRunJob) (int64, bool) { |
451 | | - return j.ID, j.ID != 0 |
452 | | - }) |
453 | | - |
454 | | - if len(jobIDs) > 0 { |
455 | | - if err := db.GetEngine(ctx).Where("repo_id = ?", repoID).In("job_id", jobIDs).Find(&tasks); err != nil { |
456 | | - return err |
457 | | - } |
458 | | - } |
459 | | - |
460 | | - artifacts, err := db.Find[ActionArtifact](ctx, FindArtifactsOptions{ |
461 | | - RepoID: repoID, |
462 | | - RunID: run.ID, |
463 | | - }) |
464 | | - if err != nil { |
465 | | - return err |
466 | | - } |
467 | | - |
468 | | - var recordsToDelete []any |
469 | | - |
470 | | - for _, task := range tasks { |
471 | | - recordsToDelete = append(recordsToDelete, &ActionTask{ |
472 | | - RepoID: repoID, |
473 | | - ID: task.ID, |
474 | | - }) |
475 | | - recordsToDelete = append(recordsToDelete, &ActionTaskStep{ |
476 | | - RepoID: repoID, |
477 | | - TaskID: task.ID, |
478 | | - }) |
479 | | - } |
480 | | - recordsToDelete = append(recordsToDelete, &ActionRunJob{ |
481 | | - RepoID: repoID, |
482 | | - RunID: run.ID, |
483 | | - }) |
484 | | - recordsToDelete = append(recordsToDelete, &ActionRun{ |
485 | | - RepoID: repoID, |
486 | | - ID: run.ID, |
487 | | - }) |
488 | | - recordsToDelete = append(recordsToDelete, &ActionArtifact{ |
489 | | - RepoID: repoID, |
490 | | - RunID: run.ID, |
491 | | - }) |
492 | | - |
493 | | - if err := db.WithTx(ctx, func(ctx context.Context) error { |
494 | | - return db.DeleteBeans(ctx, recordsToDelete...) |
495 | | - }); err != nil { |
496 | | - return err |
497 | | - } |
498 | | - |
499 | | - // Delete files on storage |
500 | | - for _, tas := range tasks { |
501 | | - err := actions_module.RemoveLogs(ctx, tas.LogInStorage, tas.LogFilename) |
502 | | - if err != nil { |
503 | | - log_module.Error("remove log file %q: %v", tas.LogFilename, err) |
504 | | - } |
505 | | - } |
506 | | - for _, art := range artifacts { |
507 | | - if err := storage_module.ActionsArtifacts.Delete(art.StoragePath); err != nil { |
508 | | - log_module.Error("remove artifact file %q: %v", art.StoragePath, err) |
509 | | - } |
510 | | - } |
511 | | - |
512 | | - // TODO: Delete commit status? Looks like it has no direct reference to a run/task/job. Not quite feasible without modifying db models (Dangerous). |
513 | | - return nil |
514 | | -} |
515 | | - |
516 | 442 | type ActionRunIndex db.ResourceIndex |
0 commit comments