diff --git a/cmd/root.go b/cmd/root.go index 8933a31..750e1b1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -33,7 +33,7 @@ func initLogging(cfg config.Config) { } func Execute(ctx context.Context) { - task := runtime.NewTask("gitea", 0, nil) + task := runtime.NewTask("gitea", 0, nil, nil) // ./act_runner rootCmd := &cobra.Command{ diff --git a/config/config.go b/config/config.go index b5ce40b..5b8a3df 100644 --- a/config/config.go +++ b/config/config.go @@ -75,9 +75,18 @@ func FromEnviron() (Config, error) { cfg.ForgeInstance = runner.ForgeInstance } + cfg.Client.Address = fmt.Sprintf( + "%s://%s", + cfg.Client.Proto, + cfg.Client.Host, + ) + // runner config if cfg.Runner.Environ == nil { - cfg.Runner.Environ = map[string]string{} + cfg.Runner.Environ = map[string]string{ + "GITHUB_API_URL": cfg.Client.Address + "/api/v1", + "GITHUB_SERVER_URL": cfg.Client.Address, + } } if cfg.Runner.Name == "" { cfg.Runner.Name, _ = os.Hostname() @@ -91,12 +100,6 @@ func FromEnviron() (Config, error) { cfg.Platform.Arch = runtime.GOARCH } - cfg.Client.Address = fmt.Sprintf( - "%s://%s", - cfg.Client.Proto, - cfg.Client.Host, - ) - if file := cfg.Runner.EnvFile; file != "" { envs, err := godotenv.Read(file) if err != nil { diff --git a/runtime/runtime.go b/runtime/runtime.go index 71ed4f8..644a77c 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -49,5 +49,5 @@ func (s *Runner) Run(ctx context.Context, task *runnerv1.Task) error { l.Info("update runner status to idle") }() - return NewTask(s.ForgeInstance, task.Id, s.Client).Run(ctx, task) + return NewTask(s.ForgeInstance, task.Id, s.Client, s.Environ).Run(ctx, task) } diff --git a/runtime/task.go b/runtime/task.go index c1be83e..d1588ee 100644 --- a/runtime/task.go +++ b/runtime/task.go @@ -31,7 +31,7 @@ type TaskInput struct { reuseContainers bool bindWorkdir bool // secrets []string - // envs []string + envs map[string]string // platforms []string // dryrun bool forcePull bool @@ -69,11 +69,12 @@ type Task struct { } // NewTask creates a new task -func NewTask(forgeInstance string, buildID int64, client client.Client) *Task { +func NewTask(forgeInstance string, buildID int64, client client.Client, runnerEnvs map[string]string) *Task { task := &Task{ Input: &TaskInput{ reuseContainers: true, ForgeInstance: forgeInstance, + envs: runnerEnvs, }, BuildID: buildID, @@ -172,9 +173,10 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error { } token := getToken(task) - log.Infof("task %v token is %v", task.Id, token) - dataContext := task.Context.Fields + + log.Infof("task %v token is %v %v", task.Id, token, dataContext["repository"].GetStringValue()) + preset := &model.GithubContext{ Event: dataContext["event"].GetStructValue().AsMap(), RunID: dataContext["run_id"].GetStringValue(), @@ -224,6 +226,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error { NoSkipCheckout: input.noSkipCheckout, PresetGitHubContext: preset, EventJSON: string(eventJSON), + Env: t.Input.envs, } r, err := runner.New(config) if err != nil {