support changing labels
This commit is contained in:
parent
81502dd33b
commit
6dece3226f
3 changed files with 32 additions and 0 deletions
|
@ -40,6 +40,14 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command,
|
|||
return fmt.Errorf("failed to load registration file: %w", err)
|
||||
}
|
||||
|
||||
if len(cfg.Runner.Labels) > 0 {
|
||||
// overwirte the labels in the config file to the state file
|
||||
reg.Labels = cfg.Runner.Labels
|
||||
if err := config.SaveRegistration(cfg.Runner.File, reg); err != nil {
|
||||
return fmt.Errorf("failed to save runner config: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
ls := labels.Labels{}
|
||||
for _, l := range reg.Labels {
|
||||
label, err := labels.Parse(l)
|
||||
|
@ -68,6 +76,11 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command,
|
|||
)
|
||||
|
||||
runner := run.NewRunner(cfg, reg, cli)
|
||||
// declare the labels of the runner before fetching tasks
|
||||
err = runner.Declare(ctx, ls.Names())
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to declare runner: %w", err)
|
||||
}
|
||||
poller := poll.New(cfg, cli, runner)
|
||||
|
||||
poller.Poll(ctx)
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"time"
|
||||
|
||||
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
|
||||
"github.com/bufbuild/connect-go"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/nektos/act/pkg/artifactcache"
|
||||
"github.com/nektos/act/pkg/common"
|
||||
|
@ -214,3 +215,13 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
|
|||
reporter.SetOutputs(job.Outputs)
|
||||
return execErr
|
||||
}
|
||||
|
||||
func (r *Runner) Declare(ctx context.Context, labels []string) error {
|
||||
_, err := r.client.Declare(ctx, connect.NewRequest(&runnerv1.DeclareRequest{
|
||||
Labels: labels,
|
||||
}))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -82,3 +82,11 @@ func (l Labels) PickPlatform(runsOn []string) string {
|
|||
// TODO: it may be not correct, what if the runner is used as host mode only?
|
||||
return "node:16-bullseye"
|
||||
}
|
||||
|
||||
func (l Labels) Names() []string {
|
||||
names := make([]string, 0, len(l))
|
||||
for _, label := range l {
|
||||
names = append(names, label.Name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue