aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/actions/runner/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api/actions/runner/utils.go')
-rw-r--r--routers/api/actions/runner/utils.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/routers/api/actions/runner/utils.go b/routers/api/actions/runner/utils.go
index 9af51f2d7e..cc9c06ab45 100644
--- a/routers/api/actions/runner/utils.go
+++ b/routers/api/actions/runner/utils.go
@@ -36,6 +36,7 @@ func pickTask(ctx context.Context, runner *actions_model.ActionRunner) (*runnerv
WorkflowPayload: t.Job.WorkflowPayload,
Context: generateTaskContext(t),
Secrets: getSecretsOfTask(ctx, t),
+ Vars: getVariablesOfTask(ctx, t),
}
if needs, err := findTaskNeeds(ctx, t); err != nil {
@@ -88,6 +89,29 @@ func getSecretsOfTask(ctx context.Context, task *actions_model.ActionTask) map[s
return secrets
}
+func getVariablesOfTask(ctx context.Context, task *actions_model.ActionTask) map[string]string {
+ variables := map[string]string{}
+
+ // Org / User level
+ ownerVariables, err := actions_model.FindVariables(ctx, actions_model.FindVariablesOpts{OwnerID: task.Job.Run.Repo.OwnerID})
+ if err != nil {
+ log.Error("find variables of org: %d, error: %v", task.Job.Run.Repo.OwnerID, err)
+ }
+
+ // Repo level
+ repoVariables, err := actions_model.FindVariables(ctx, actions_model.FindVariablesOpts{RepoID: task.Job.Run.RepoID})
+ if err != nil {
+ log.Error("find variables of repo: %d, error: %v", task.Job.Run.RepoID, err)
+ }
+
+ // Level precedence: Repo > Org / User
+ for _, v := range append(ownerVariables, repoVariables...) {
+ variables[v.Name] = v.Data
+ }
+
+ return variables
+}
+
func generateTaskContext(t *actions_model.ActionTask) *structpb.Struct {
event := map[string]interface{}{}
_ = json.Unmarshal([]byte(t.Job.Run.EventPayload), &event)