1
0
mirror of https://gitea.com/gitea/act_runner synced 2024-11-09 18:05:52 +01:00

add new envs

This commit is contained in:
Lunny Xiao 2022-11-04 17:23:59 +08:00 committed by Jason Song
parent 93e42d1465
commit 222b5100b6
4 changed files with 19 additions and 13 deletions

@ -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{

@ -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 {

@ -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)
}

@ -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 {