From aeda0a5af4bfe39fd9411f6386179aa34295cf74 Mon Sep 17 00:00:00 2001 From: Francesco Renzi Date: Fri, 30 Jan 2026 14:41:46 +0100 Subject: [PATCH] Add --labels support in docker example (#51) --- examples/dockerscaleset/README.md | 1 + examples/dockerscaleset/config.go | 19 +++++++++++++++++++ examples/dockerscaleset/main.go | 7 ++----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/examples/dockerscaleset/README.md b/examples/dockerscaleset/README.md index 7d1461b..9c12a7b 100644 --- a/examples/dockerscaleset/README.md +++ b/examples/dockerscaleset/README.md @@ -40,6 +40,7 @@ You'll then need: |------|----------|-------------| | `--url` | Yes | Registration target (org, repo, or enterprise URL, e.g. `https://github.com/org/repo`). | | `--name` | Yes | Runner scale set name (must be unique within the runner group). | +| `--labels` | No | Labels for workflow targeting (comma-separated or repeated). Defaults to `--name` if not provided. | | `--max-runners` | No | Upper bound of concurrently provisioned runners (default 10). | | `--min-runners` | No | Lower bound to maintain (default 0). | | `--runner-group` | No | Runner group name (default `default`). | diff --git a/examples/dockerscaleset/config.go b/examples/dockerscaleset/config.go index 829c8bc..f62a929 100644 --- a/examples/dockerscaleset/config.go +++ b/examples/dockerscaleset/config.go @@ -15,6 +15,7 @@ type Config struct { MaxRunners int MinRunners int ScaleSetName string + Labels []string RunnerGroup string GitHubApp scaleset.GitHubAppAuth Token string @@ -47,6 +48,11 @@ func (c *Config) Validate() error { if c.ScaleSetName == "" { return fmt.Errorf("scale set name is required") } + for i, label := range c.Labels { + if strings.TrimSpace(label) == "" { + return fmt.Errorf("label at index %d is empty", i) + } + } if c.MaxRunners < c.MinRunners { return fmt.Errorf("max runners cannot be less than min-runners") } @@ -120,3 +126,16 @@ func (c *Config) Logger() *slog.Logger { return slog.New(slog.DiscardHandler) } } + +// BuildLabels returns the labels to use for the runner scale set. +// If custom labels are provided, those are used; otherwise, the scale set name is used as the label. +func (c *Config) BuildLabels() []scaleset.Label { + if len(c.Labels) > 0 { + labels := make([]scaleset.Label, len(c.Labels)) + for i, name := range c.Labels { + labels[i] = scaleset.Label{Name: strings.TrimSpace(name)} + } + return labels + } + return []scaleset.Label{{Name: c.ScaleSetName}} +} diff --git a/examples/dockerscaleset/main.go b/examples/dockerscaleset/main.go index 7cc8a52..a21568d 100644 --- a/examples/dockerscaleset/main.go +++ b/examples/dockerscaleset/main.go @@ -23,6 +23,7 @@ func init() { flags.IntVar(&cfg.MaxRunners, "max-runners", 10, "Maximum number of runners") flags.IntVar(&cfg.MinRunners, "min-runners", 0, "Minimum number of runners") flags.StringVar(&cfg.ScaleSetName, "name", "", "REQUIRED: Name of your scale set") + flags.StringSliceVar(&cfg.Labels, "labels", nil, "Labels for workflow targeting (comma-separated or repeated). Defaults to --name if not provided.") flags.StringVar(&cfg.RunnerGroup, "runner-group", scaleset.DefaultRunnerGroup, "Name of the runner group your scale set should belong to") flags.StringVar(&cfg.GitHubApp.ClientID, "app-client-id", "", "GitHub App client id") flags.Int64Var(&cfg.GitHubApp.InstallationID, "app-installation-id", 0, "GitHub App installation ID") @@ -77,11 +78,7 @@ func run(ctx context.Context, c Config) error { scaleSet, err := scalesetClient.CreateRunnerScaleSet(ctx, &scaleset.RunnerScaleSet{ Name: c.ScaleSetName, RunnerGroupID: runnerGroupID, - Labels: []scaleset.Label{ - { - Name: c.ScaleSetName, - }, - }, + Labels: c.BuildLabels(), RunnerSetting: scaleset.RunnerSetting{ DisableUpdate: true, },