mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-05-02 17:00:26 +08:00
## Consumer-facing breaking changes
- **Go module path**: `gitea.com/gitea/act_runner` → `gitea.com/gitea/runner`. Anything importing `act/...` or `internal/...` packages (notably Gitea itself) must update imports.
- **Binary name**: `act_runner` → `gitea-runner`. Wrapper scripts, systemd units, init scripts, and documentation referencing the binary by `act_runner` will break.
- **Docker image**: `gitea/act_runner` → `gitea/runner` (incl. `*-dind-rootless` variants). Users pulling `gitea/act_runner:nightly` etc. will get stale images. Note: the image name is `gitea/runner`, not `gitea/gitea-runner`.
- **Release artifact paths**: S3 directory `act_runner/{{.Version}}` → `gitea-runner/{{.Version}}`, and artifact filenames change with the new project name. Existing download URLs break.
- **Metrics namespace**: changed from `act_runner` to `gitea_runner` (e.g. `act_runner_jobs_total` → `gitea_runner_jobs_total`); existing monitors/dashboards must be updated.
- **ldflags version path**: `gitea.com/gitea/act_runner/internal/pkg/ver.version` → `gitea.com/gitea/runner/internal/pkg/ver.version`. Affects anyone building with custom ldflags.
- **Kubernetes example resource names**: `act-runner` / `act-runner-vol` → `runner` / `runner-vol`. Users who copied the manifests verbatim will see resource churn on apply.
- **s6 service name**: `scripts/s6/act_runner/` → `scripts/s6/gitea-runner/` (image-internal; only matters for downstream image overrides).
Unchanged: YAML config field names, env vars (`GITEA_*`), CLI flags/subcommands, registration file format.
---------
Co-authored-by: silverwind <me@silverwind.io>
Reviewed-on: https://gitea.com/gitea/runner/pulls/850
Reviewed-by: Zettat123 <39446+zettat123@noreply.gitea.com>
Reviewed-by: silverwind <2021+silverwind@noreply.gitea.com>
Reviewed-by: Nicolas <bircni@icloud.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
194 lines
4.6 KiB
Go
194 lines
4.6 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// Copyright 2020 The nektos/act Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package runner
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
|
|
"gitea.com/gitea/runner/act/common"
|
|
"gitea.com/gitea/runner/act/model"
|
|
|
|
"github.com/sirupsen/logrus/hooks/test"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSetEnv(t *testing.T) {
|
|
a := assert.New(t)
|
|
ctx := context.Background()
|
|
rc := new(RunContext)
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
handler("::set-env name=x::valz\n")
|
|
a.Equal("valz", rc.Env["x"])
|
|
}
|
|
|
|
func TestSetOutput(t *testing.T) {
|
|
a := assert.New(t)
|
|
ctx := context.Background()
|
|
rc := new(RunContext)
|
|
rc.StepResults = make(map[string]*model.StepResult)
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
rc.CurrentStep = "my-step"
|
|
rc.StepResults[rc.CurrentStep] = &model.StepResult{
|
|
Outputs: make(map[string]string),
|
|
}
|
|
handler("::set-output name=x::valz\n")
|
|
a.Equal("valz", rc.StepResults["my-step"].Outputs["x"])
|
|
|
|
handler("::set-output name=x::percent2%25\n")
|
|
a.Equal("percent2%", rc.StepResults["my-step"].Outputs["x"])
|
|
|
|
handler("::set-output name=x::percent2%25%0Atest\n")
|
|
a.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x"])
|
|
|
|
handler("::set-output name=x::percent2%25%0Atest another3%25test\n")
|
|
a.Equal("percent2%\ntest another3%test", rc.StepResults["my-step"].Outputs["x"])
|
|
|
|
handler("::set-output name=x%3A::percent2%25%0Atest\n")
|
|
a.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x:"])
|
|
|
|
handler("::set-output name=x%3A%2C%0A%25%0D%3A::percent2%25%0Atest\n")
|
|
a.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x:,\n%\r:"])
|
|
}
|
|
|
|
func TestAddpath(t *testing.T) {
|
|
a := assert.New(t)
|
|
ctx := context.Background()
|
|
rc := new(RunContext)
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
handler("::add-path::/zoo\n")
|
|
a.Equal("/zoo", rc.ExtraPath[0])
|
|
|
|
handler("::add-path::/boo\n")
|
|
a.Equal("/boo", rc.ExtraPath[0])
|
|
}
|
|
|
|
func TestStopCommands(t *testing.T) {
|
|
logger, hook := test.NewNullLogger()
|
|
|
|
a := assert.New(t)
|
|
ctx := common.WithLogger(context.Background(), logger)
|
|
rc := new(RunContext)
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
handler("::set-env name=x::valz\n")
|
|
a.Equal("valz", rc.Env["x"])
|
|
handler("::stop-commands::my-end-token\n")
|
|
handler("::set-env name=x::abcd\n")
|
|
a.Equal("valz", rc.Env["x"])
|
|
handler("::my-end-token::\n")
|
|
handler("::set-env name=x::abcd\n")
|
|
a.Equal("abcd", rc.Env["x"])
|
|
|
|
messages := make([]string, 0)
|
|
for _, entry := range hook.AllEntries() {
|
|
messages = append(messages, entry.Message)
|
|
}
|
|
|
|
a.Contains(messages, "::set-env name=x::abcd\n")
|
|
}
|
|
|
|
func TestAddpathADO(t *testing.T) {
|
|
a := assert.New(t)
|
|
ctx := context.Background()
|
|
rc := new(RunContext)
|
|
handler := rc.commandHandler(ctx)
|
|
|
|
handler("##[add-path]/zoo\n")
|
|
a.Equal("/zoo", rc.ExtraPath[0])
|
|
|
|
handler("##[add-path]/boo\n")
|
|
a.Equal("/boo", rc.ExtraPath[0])
|
|
}
|
|
|
|
func TestAddmask(t *testing.T) {
|
|
logger, hook := test.NewNullLogger()
|
|
|
|
a := assert.New(t)
|
|
ctx := context.Background()
|
|
loggerCtx := common.WithLogger(ctx, logger)
|
|
|
|
rc := new(RunContext)
|
|
handler := rc.commandHandler(loggerCtx)
|
|
handler("::add-mask::my-secret-value\n")
|
|
|
|
a.Equal("***", hook.LastEntry().Message)
|
|
a.NotEqual("*my-secret-value", hook.LastEntry().Message)
|
|
}
|
|
|
|
// based on https://stackoverflow.com/a/10476304
|
|
func captureOutput(t *testing.T, f func()) string {
|
|
old := os.Stdout
|
|
r, w, _ := os.Pipe()
|
|
os.Stdout = w
|
|
|
|
f()
|
|
|
|
outC := make(chan string)
|
|
|
|
go func() {
|
|
var buf bytes.Buffer
|
|
_, err := io.Copy(&buf, r)
|
|
if err != nil {
|
|
a := assert.New(t)
|
|
a.Fail("io.Copy failed")
|
|
}
|
|
outC <- buf.String()
|
|
}()
|
|
|
|
w.Close()
|
|
os.Stdout = old
|
|
out := <-outC
|
|
|
|
return out
|
|
}
|
|
|
|
func TestAddmaskUsemask(t *testing.T) {
|
|
rc := new(RunContext)
|
|
rc.StepResults = make(map[string]*model.StepResult)
|
|
rc.CurrentStep = "my-step"
|
|
rc.StepResults[rc.CurrentStep] = &model.StepResult{
|
|
Outputs: make(map[string]string),
|
|
}
|
|
|
|
a := assert.New(t)
|
|
|
|
config := &Config{
|
|
Secrets: map[string]string{},
|
|
InsecureSecrets: false,
|
|
}
|
|
|
|
re := captureOutput(t, func() {
|
|
ctx := context.Background()
|
|
ctx = WithJobLogger(ctx, "0", "testjob", config, &rc.Masks, map[string]any{})
|
|
|
|
handler := rc.commandHandler(ctx)
|
|
handler("::add-mask::secret\n")
|
|
handler("::set-output:: token=secret\n")
|
|
})
|
|
|
|
a.Equal("[testjob] ***\n[testjob] ::set-output:: = token=***\n", re)
|
|
}
|
|
|
|
func TestSaveState(t *testing.T) {
|
|
rc := &RunContext{
|
|
CurrentStep: "step",
|
|
StepResults: map[string]*model.StepResult{},
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
handler := rc.commandHandler(ctx)
|
|
handler("::save-state name=state-name::state-value\n")
|
|
|
|
assert.Equal(t, "state-value", rc.IntraActionState["step"]["state-name"])
|
|
}
|