From 5fc35faf17a4628392103688648a795fa8d3a912 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 16 Nov 2022 18:08:12 +0800 Subject: [PATCH] Support bot site --- cmd/daemon.go | 2 +- config/config.go | 12 +++++------- core/runner.go | 11 +++++------ go.mod | 2 +- go.sum | 4 ++-- register/register.go | 1 - runtime/task.go | 11 ++++++----- 7 files changed, 20 insertions(+), 23 deletions(-) diff --git a/cmd/daemon.go b/cmd/daemon.go index 61af798..7c78806 100644 --- a/cmd/daemon.go +++ b/cmd/daemon.go @@ -52,7 +52,7 @@ func runDaemon(ctx context.Context, envFile string) func(cmd *cobra.Command, arg runner := &runtime.Runner{ Client: cli, Machine: cfg.Runner.Name, - ForgeInstance: cfg.ForgeInstance, + ForgeInstance: cfg.Client.Address, Environ: cfg.Runner.Environ, } diff --git a/config/config.go b/config/config.go index 2390236..1cf8858 100644 --- a/config/config.go +++ b/config/config.go @@ -15,12 +15,11 @@ import ( type ( // Config provides the system configuration. Config struct { - Debug bool `envconfig:"GITEA_DEBUG"` - Trace bool `envconfig:"GITEA_TRACE"` - Client Client - Runner Runner - Platform Platform - ForgeInstance string + Debug bool `envconfig:"GITEA_DEBUG"` + Trace bool `envconfig:"GITEA_TRACE"` + Client Client + Runner Runner + Platform Platform } Client struct { @@ -72,7 +71,6 @@ func FromEnviron() (Config, error) { if runner.Address != "" { cfg.Client.Address = runner.Address } - cfg.ForgeInstance = runner.ForgeInstance } // runner config diff --git a/core/runner.go b/core/runner.go index 1a03452..a948639 100644 --- a/core/runner.go +++ b/core/runner.go @@ -7,10 +7,9 @@ const ( // Runner struct type Runner struct { - ID int64 `json:"id"` - UUID string `json:"uuid"` - Name string `json:"name"` - Token string `json:"token"` - Address string `json:"address"` - ForgeInstance string `json:"forge_instance"` + ID int64 `json:"id"` + UUID string `json:"uuid"` + Name string `json:"name"` + Token string `json:"token"` + Address string `json:"address"` } diff --git a/go.mod b/go.mod index 6a16d26..8c71640 100644 --- a/go.mod +++ b/go.mod @@ -72,4 +72,4 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/nektos/act => gitea.com/gitea/act v0.0.0-20221108101106-28099ee68a88 +replace github.com/nektos/act => gitea.com/gitea/act v0.0.0-20221116100712-3caee171b716 diff --git a/go.sum b/go.sum index e92a47c..1d7f968 100644 --- a/go.sum +++ b/go.sum @@ -23,8 +23,8 @@ cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiy cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -gitea.com/gitea/act v0.0.0-20221108101106-28099ee68a88 h1:pfeGhadGGQbQuXqIgi/C6NQ+VopNEkHayz49IgANPAg= -gitea.com/gitea/act v0.0.0-20221108101106-28099ee68a88/go.mod h1:lpzib6X73FHLSaTqTakan1xcsCAVhlZvPSpLns7jkRo= +gitea.com/gitea/act v0.0.0-20221116100712-3caee171b716 h1:wPFBAjfK5OFBruaX9BNSdPoRcVdEbsjviSpryVjFZjY= +gitea.com/gitea/act v0.0.0-20221116100712-3caee171b716/go.mod h1:lpzib6X73FHLSaTqTakan1xcsCAVhlZvPSpLns7jkRo= gitea.com/gitea/proto-go v0.0.0-20221028125601-35c4f6b05835 h1:27PhT7Nli/pgRo1bDYVZ+hlCKuF9cfFuo+y9muaPVJY= gitea.com/gitea/proto-go v0.0.0-20221028125601-35c4f6b05835/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y= github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= diff --git a/register/register.go b/register/register.go index c4c16a2..cf80b54 100644 --- a/register/register.go +++ b/register/register.go @@ -47,7 +47,6 @@ func (p *Register) Register(ctx context.Context, cfg config.Runner) (*core.Runne Name: resp.Msg.Runner.Name, Token: resp.Msg.Runner.Token, Address: p.Client.Address(), - // ForgeInstance: resp.Msg.Runner.ForgeInstance, TODO: add me } file, err := json.MarshalIndent(data, "", " ") diff --git a/runtime/task.go b/runtime/task.go index 4d8578e..df28936 100644 --- a/runtime/task.go +++ b/runtime/task.go @@ -56,8 +56,7 @@ type TaskInput struct { noSkipCheckout bool // remoteName string - ForgeInstance string - EnvFile string + EnvFile string } type Task struct { @@ -73,7 +72,6 @@ func NewTask(forgeInstance string, buildID int64, client client.Client, runnerEn task := &Task{ Input: &TaskInput{ reuseContainers: false, - ForgeInstance: forgeInstance, envs: runnerEnvs, noSkipCheckout: true, }, @@ -170,7 +168,9 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error { token := getToken(task) dataContext := task.Context.Fields - log.Infof("task %v token is %v %v", task.Id, token, dataContext["repository"].GetStringValue()) + log.Infof("task %v repo is %v %v %v", task.Id, dataContext["repository"].GetStringValue(), + dataContext["gitea_default_bots_url"].GetStringValue(), + t.client.Address()) preset := &model.GithubContext{ Event: dataContext["event"].GetStructValue().AsMap(), @@ -213,7 +213,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error { ContainerArchitecture: input.containerArchitecture, ContainerDaemonSocket: input.containerDaemonSocket, UseGitIgnore: input.useGitIgnore, - GitHubInstance: input.ForgeInstance, + GitHubInstance: t.client.Address(), ContainerCapAdd: input.containerCapAdd, ContainerCapDrop: input.containerCapDrop, AutoRemove: input.autoRemove, @@ -223,6 +223,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error { PresetGitHubContext: preset, EventJSON: string(eventJSON), ContainerNamePrefix: fmt.Sprintf("gitea-task-%d", task.Id), + DefaultActionInstance: dataContext["gitea_default_bots_url"].GetStringValue(), } r, err := runner.New(config) if err != nil {