diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 17b47f14..2bf274c3 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -3,6 +3,7 @@ ## 8.0.0 (not published yet) * Breaking change: workflows files go through a [schema validation](https://code.forgejo.org/forgejo/act/pulls/170) and will not run if they do not pass. Some existing workflows may have syntax errors that did not prevent them from running with versions 7.0.0 and below but they will no longer work with versions 8.0.0 and above. If the error is not immediately obvious, please file an issue with a copy of the failed workflow and revert to using version 7.0.0 until it is resolved. +* Breaking change: in the absence of a label or a label, [default to `docker://node:22-bookworm` instead of `docker://node:20-bullseye` or `host`](https://code.forgejo.org/forgejo/runner/issues/134). If the `lxc` scheme is set with no argument, it defaults to `lxc://debian:bookworm` instead of `lxc://debian:bullseye`. * [secrets that contain multiple lines are masked from the output](https://code.forgejo.org/forgejo/runner/pulls/661). * [bash fallback to sh if it is not available](https://code.forgejo.org/forgejo/runner/issues/150). diff --git a/internal/pkg/labels/labels.go b/internal/pkg/labels/labels.go index f448fdf2..7befaf42 100644 --- a/internal/pkg/labels/labels.go +++ b/internal/pkg/labels/labels.go @@ -9,9 +9,13 @@ import ( ) const ( - SchemeHost = "host" + SchemeHost = "host" + SchemeDocker = "docker" - SchemeLXC = "lxc" + ArgDocker = "//node:22-bookworm" + + SchemeLXC = "lxc" + ArgLXC = "//debian:bookworm" ) type Label struct { @@ -24,18 +28,32 @@ func Parse(str string) (*Label, error) { splits := strings.SplitN(str, ":", 3) label := &Label{ Name: splits[0], - Schema: "host", - Arg: "", + Schema: "docker", } + if len(splits) >= 2 { label.Schema = splits[1] + if label.Schema != SchemeHost && label.Schema != SchemeDocker && label.Schema != SchemeLXC { + return nil, fmt.Errorf("unsupported schema: %s", label.Schema) + } } + if len(splits) >= 3 { + if label.Schema == SchemeHost { + return nil, fmt.Errorf("schema: %s does not have arguments", label.Schema) + } + label.Arg = splits[2] } - if label.Schema != SchemeHost && label.Schema != SchemeDocker && label.Schema != SchemeLXC { - return nil, fmt.Errorf("unsupported schema: %s", label.Schema) + if label.Arg == "" { + switch label.Schema { + case SchemeDocker: + label.Arg = ArgDocker + case SchemeLXC: + label.Arg = ArgLXC + } } + return label, nil } @@ -72,17 +90,7 @@ func (l Labels) PickPlatform(runsOn []string) string { } } - // TODO: support multiple labels - // like: - // ["ubuntu-22.04"] => "ubuntu:22.04" - // ["with-gpu"] => "linux:with-gpu" - // ["ubuntu-22.04", "with-gpu"] => "ubuntu:22.04_with-gpu" - - // return default. - // So the runner receives a task with a label that the runner doesn't have, - // it happens when the user have edited the label of the runner in the web UI. - // TODO: it may be not correct, what if the runner is used as host mode only? - return "node:20-bullseye" + return strings.TrimPrefix(ArgDocker, "//") } func (l Labels) Names() []string { diff --git a/internal/pkg/labels/labels_test.go b/internal/pkg/labels/labels_test.go index 9b799140..db2f0adf 100644 --- a/internal/pkg/labels/labels_test.go +++ b/internal/pkg/labels/labels_test.go @@ -18,34 +18,69 @@ func TestParse(t *testing.T) { wantErr bool }{ { - args: "ubuntu:docker://node:18", + args: "label1", want: &Label{ - Name: "ubuntu", - Schema: "docker", + Name: "label1", + Schema: SchemeDocker, + Arg: ArgDocker, + }, + wantErr: false, + }, + { + args: "label1:docker", + want: &Label{ + Name: "label1", + Schema: SchemeDocker, + Arg: ArgDocker, + }, + wantErr: false, + }, + { + args: "label1:docker://node:18", + want: &Label{ + Name: "label1", + Schema: SchemeDocker, Arg: "//node:18", }, wantErr: false, }, + { - args: "ubuntu:host", + args: "label1:lxc", want: &Label{ - Name: "ubuntu", + Name: "label1", + Schema: SchemeLXC, + Arg: ArgLXC, + }, + wantErr: false, + }, + { + args: "label1:lxc://debian:buster", + want: &Label{ + Name: "label1", + Schema: SchemeLXC, + Arg: "//debian:buster", + }, + wantErr: false, + }, + + { + args: "label1:host", + want: &Label{ + Name: "label1", Schema: "host", Arg: "", }, wantErr: false, }, { - args: "ubuntu", - want: &Label{ - Name: "ubuntu", - Schema: "host", - Arg: "", - }, - wantErr: false, + args: "label1:host:something", + want: nil, + wantErr: true, }, + { - args: "ubuntu:vm:ubuntu-18.04", + args: "label1:invalidscheme", want: nil, wantErr: true, },