diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 6951540..bdcb071 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,5 +1,11 @@ # Release Notes +## 3.4.2 + +* [Fix label declaration](https://code.forgejo.org/forgejo/runner/pulls/176): Runner in daemon mode now takes labels found in config.yml into account when declaration was successful. +* [Fix the docker compose example](https://code.forgejo.org/forgejo/runner/pulls/175) to workaround the race on labels. +* [Fix the kubernetes dind example](https://code.forgejo.org/forgejo/runner/pulls/169). + ## 3.4.1 * Fixes a regression introduced in 3.4.0 by which a job with no image explicitly set would diff --git a/internal/app/cmd/daemon.go b/internal/app/cmd/daemon.go index e56a13f..8e47bf6 100644 --- a/internal/app/cmd/daemon.go +++ b/internal/app/cmd/daemon.go @@ -111,6 +111,7 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command, log.Infof("runner: %s, with version: %s, with labels: %v, declared successfully", resp.Msg.Runner.Name, resp.Msg.Runner.Version, resp.Msg.Runner.Labels) // if declared successfully, override the labels in the.runner file with valid labels in the config file (if specified) + runner.Update(ctx, ls) reg.Labels = ls.ToStrings() if err := config.SaveRegistration(cfg.Runner.File, reg); err != nil { return fmt.Errorf("failed to save runner config: %w", err) diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go index ee12165..ff54fa7 100644 --- a/internal/app/run/runner.go +++ b/internal/app/run/runner.go @@ -242,3 +242,7 @@ func (r *Runner) Declare(ctx context.Context, labels []string) (*connect.Respons Labels: labels, })) } + +func (r *Runner) Update(ctx context.Context, labels labels.Labels) { + r.labels = labels +} diff --git a/internal/app/run/runner_test.go b/internal/app/run/runner_test.go new file mode 100644 index 0000000..0145c70 --- /dev/null +++ b/internal/app/run/runner_test.go @@ -0,0 +1,37 @@ +package run + +import ( + "context" + "testing" + + "gitea.com/gitea/act_runner/internal/pkg/labels" + "github.com/stretchr/testify/assert" +) + +func TestLabelUpdate(t *testing.T) { + ctx := context.Background() + ls := labels.Labels{} + + initialLabel, err := labels.Parse("testlabel:docker://alpine") + assert.NoError(t, err) + ls = append(ls, initialLabel) + + newLs := labels.Labels{} + + newLabel, err := labels.Parse("next label:host") + assert.NoError(t, err) + newLs = append(newLs, initialLabel) + newLs = append(newLs, newLabel) + + runner := Runner{ + labels: ls, + } + + assert.Contains(t, runner.labels, initialLabel) + assert.NotContains(t, runner.labels, newLabel) + + runner.Update(ctx, newLs) + + assert.Contains(t, runner.labels, initialLabel) + assert.Contains(t, runner.labels, newLabel) +}