summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsillyguodong <33891828+sillyguodong@users.noreply.github.com>2024-04-24 02:55:25 +0800
committerGitHub <noreply@github.com>2024-04-23 20:55:25 +0200
commit2f6b1c46a1a4a90f56ca0f3ad7840e8e70daeab5 (patch)
treea0285609b16d287a8431586be22ec54acac309ec
parentb79e3db264e5734d8cc038be898d45186b3afcbd (diff)
downloadgitea-2f6b1c46a1a4a90f56ca0f3ad7840e8e70daeab5.tar.gz
gitea-2f6b1c46a1a4a90f56ca0f3ad7840e8e70daeab5.zip
Interpolate runs-on with variables when scheduling tasks (#30640)
Follow #29468 1. Interpolate runs-on with variables when scheduling tasks. 2. The `GetVariablesOfRun` function will check if the `Repo` of the run is nil. --------- Co-authored-by: Giteabot <teabot@gitea.io>
-rw-r--r--models/actions/run.go22
-rw-r--r--models/actions/variable.go5
-rw-r--r--services/actions/schedule_tasks.go8
3 files changed, 28 insertions, 7 deletions
diff --git a/models/actions/run.go b/models/actions/run.go
index fa9db0b554..b75fa49f3c 100644
--- a/models/actions/run.go
+++ b/models/actions/run.go
@@ -98,13 +98,10 @@ func (run *ActionRun) LoadAttributes(ctx context.Context) error {
return nil
}
- if run.Repo == nil {
- repo, err := repo_model.GetRepositoryByID(ctx, run.RepoID)
- if err != nil {
- return err
- }
- run.Repo = repo
+ if err := run.LoadRepo(ctx); err != nil {
+ return err
}
+
if err := run.Repo.LoadAttributes(ctx); err != nil {
return err
}
@@ -120,6 +117,19 @@ func (run *ActionRun) LoadAttributes(ctx context.Context) error {
return nil
}
+func (run *ActionRun) LoadRepo(ctx context.Context) error {
+ if run == nil || run.Repo != nil {
+ return nil
+ }
+
+ repo, err := repo_model.GetRepositoryByID(ctx, run.RepoID)
+ if err != nil {
+ return err
+ }
+ run.Repo = repo
+ return nil
+}
+
func (run *ActionRun) Duration() time.Duration {
return calculateDuration(run.Started, run.Stopped, run.Status) + run.PreviousDuration
}
diff --git a/models/actions/variable.go b/models/actions/variable.go
index b0a455e675..8aff844659 100644
--- a/models/actions/variable.go
+++ b/models/actions/variable.go
@@ -92,6 +92,11 @@ func DeleteVariable(ctx context.Context, id int64) error {
func GetVariablesOfRun(ctx context.Context, run *ActionRun) (map[string]string, error) {
variables := map[string]string{}
+ if err := run.LoadRepo(ctx); err != nil {
+ log.Error("LoadRepo: %v", err)
+ return nil, err
+ }
+
// Global
globalVariables, err := db.Find[ActionVariable](ctx, FindVariablesOpts{})
if err != nil {
diff --git a/services/actions/schedule_tasks.go b/services/actions/schedule_tasks.go
index e4e56e5122..18f3324fd2 100644
--- a/services/actions/schedule_tasks.go
+++ b/services/actions/schedule_tasks.go
@@ -132,8 +132,14 @@ func CreateScheduleTask(ctx context.Context, cron *actions_model.ActionSchedule)
Status: actions_model.StatusWaiting,
}
+ vars, err := actions_model.GetVariablesOfRun(ctx, run)
+ if err != nil {
+ log.Error("GetVariablesOfRun: %v", err)
+ return err
+ }
+
// Parse the workflow specification from the cron schedule
- workflows, err := jobparser.Parse(cron.Content)
+ workflows, err := jobparser.Parse(cron.Content, jobparser.WithVars(vars))
if err != nil {
return err
}