mirror of
https://gitea.com/gitea/act_runner
synced 2026-05-01 01:27:56 +02: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>
299 lines
7.4 KiB
Go
299 lines
7.4 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// Copyright 2022 The nektos/act Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package runner
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"io"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.com/gitea/runner/act/common"
|
|
"gitea.com/gitea/runner/act/model"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
"go.yaml.in/yaml/v4"
|
|
)
|
|
|
|
type stepActionLocalMocks struct {
|
|
mock.Mock
|
|
}
|
|
|
|
func (salm *stepActionLocalMocks) runAction(step actionStep, actionDir string, remoteAction *remoteAction) common.Executor {
|
|
args := salm.Called(step, actionDir, remoteAction)
|
|
return args.Get(0).(func(context.Context) error)
|
|
}
|
|
|
|
func (salm *stepActionLocalMocks) readAction(_ context.Context, step *model.Step, actionDir, actionPath string, readFile actionYamlReader, writeFile fileWriter) (*model.Action, error) {
|
|
args := salm.Called(step, actionDir, actionPath, readFile, writeFile)
|
|
return args.Get(0).(*model.Action), args.Error(1)
|
|
}
|
|
|
|
func TestStepActionLocalTest(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
cm := &containerMock{}
|
|
salm := &stepActionLocalMocks{}
|
|
|
|
sal := &stepActionLocal{
|
|
readAction: salm.readAction,
|
|
runAction: salm.runAction,
|
|
RunContext: &RunContext{
|
|
StepResults: map[string]*model.StepResult{},
|
|
ExprEval: &expressionEvaluator{},
|
|
Config: &Config{
|
|
Workdir: "/tmp",
|
|
},
|
|
Run: &model.Run{
|
|
JobID: "1",
|
|
Workflow: &model.Workflow{
|
|
Jobs: map[string]*model.Job{
|
|
"1": {
|
|
Defaults: model.Defaults{
|
|
Run: model.RunDefaults{
|
|
Shell: "bash",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
JobContainer: cm,
|
|
},
|
|
Step: &model.Step{
|
|
ID: "1",
|
|
Uses: "./path/to/action",
|
|
},
|
|
}
|
|
|
|
salm.On("readAction", sal.Step, filepath.Clean("/tmp/path/to/action"), "", mock.Anything, mock.Anything).
|
|
Return(&model.Action{}, nil)
|
|
|
|
cm.On("Copy", "/var/run/act", mock.AnythingOfType("[]*container.FileEntry")).Return(func(ctx context.Context) error {
|
|
return nil
|
|
})
|
|
|
|
cm.On("UpdateFromEnv", "/var/run/act/workflow/envs.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
|
|
return nil
|
|
})
|
|
|
|
cm.On("UpdateFromEnv", "/var/run/act/workflow/statecmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
|
|
return nil
|
|
})
|
|
|
|
cm.On("UpdateFromEnv", "/var/run/act/workflow/outputcmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
|
|
return nil
|
|
})
|
|
|
|
cm.On("GetContainerArchive", ctx, "/var/run/act/workflow/pathcmd.txt").Return(io.NopCloser(&bytes.Buffer{}), nil)
|
|
|
|
salm.On("runAction", sal, filepath.Clean("/tmp/path/to/action"), (*remoteAction)(nil)).Return(func(ctx context.Context) error {
|
|
return nil
|
|
})
|
|
|
|
err := sal.pre()(ctx)
|
|
assert.NoError(t, err) //nolint:testifylint // pre-existing issue from nektos/act
|
|
|
|
err = sal.main()(ctx)
|
|
assert.NoError(t, err) //nolint:testifylint // pre-existing issue from nektos/act
|
|
|
|
cm.AssertExpectations(t)
|
|
salm.AssertExpectations(t)
|
|
}
|
|
|
|
func TestStepActionLocalPost(t *testing.T) {
|
|
table := []struct {
|
|
name string
|
|
stepModel *model.Step
|
|
actionModel *model.Action
|
|
initialStepResults map[string]*model.StepResult
|
|
err error
|
|
mocks struct {
|
|
env bool
|
|
exec bool
|
|
}
|
|
}{
|
|
{
|
|
name: "main-success",
|
|
stepModel: &model.Step{
|
|
ID: "step",
|
|
Uses: "./local/action",
|
|
},
|
|
actionModel: &model.Action{
|
|
Runs: model.ActionRuns{
|
|
Using: "node16",
|
|
Post: "post.js",
|
|
PostIf: "always()",
|
|
},
|
|
},
|
|
initialStepResults: map[string]*model.StepResult{
|
|
"step": {
|
|
Conclusion: model.StepStatusSuccess,
|
|
Outcome: model.StepStatusSuccess,
|
|
Outputs: map[string]string{},
|
|
},
|
|
},
|
|
mocks: struct {
|
|
env bool
|
|
exec bool
|
|
}{
|
|
env: true,
|
|
exec: true,
|
|
},
|
|
},
|
|
{
|
|
name: "main-failed",
|
|
stepModel: &model.Step{
|
|
ID: "step",
|
|
Uses: "./local/action",
|
|
},
|
|
actionModel: &model.Action{
|
|
Runs: model.ActionRuns{
|
|
Using: "node16",
|
|
Post: "post.js",
|
|
PostIf: "always()",
|
|
},
|
|
},
|
|
initialStepResults: map[string]*model.StepResult{
|
|
"step": {
|
|
Conclusion: model.StepStatusFailure,
|
|
Outcome: model.StepStatusFailure,
|
|
Outputs: map[string]string{},
|
|
},
|
|
},
|
|
mocks: struct {
|
|
env bool
|
|
exec bool
|
|
}{
|
|
env: true,
|
|
exec: true,
|
|
},
|
|
},
|
|
{
|
|
name: "skip-if-failed",
|
|
stepModel: &model.Step{
|
|
ID: "step",
|
|
Uses: "./local/action",
|
|
},
|
|
actionModel: &model.Action{
|
|
Runs: model.ActionRuns{
|
|
Using: "node16",
|
|
Post: "post.js",
|
|
PostIf: "success()",
|
|
},
|
|
},
|
|
initialStepResults: map[string]*model.StepResult{
|
|
"step": {
|
|
Conclusion: model.StepStatusFailure,
|
|
Outcome: model.StepStatusFailure,
|
|
Outputs: map[string]string{},
|
|
},
|
|
},
|
|
mocks: struct {
|
|
env bool
|
|
exec bool
|
|
}{
|
|
env: false,
|
|
exec: false,
|
|
},
|
|
},
|
|
{
|
|
name: "skip-if-main-skipped",
|
|
stepModel: &model.Step{
|
|
ID: "step",
|
|
If: yaml.Node{Value: "failure()"},
|
|
Uses: "./local/action",
|
|
},
|
|
actionModel: &model.Action{
|
|
Runs: model.ActionRuns{
|
|
Using: "node16",
|
|
Post: "post.js",
|
|
PostIf: "always()",
|
|
},
|
|
},
|
|
initialStepResults: map[string]*model.StepResult{
|
|
"step": {
|
|
Conclusion: model.StepStatusSkipped,
|
|
Outcome: model.StepStatusSkipped,
|
|
Outputs: map[string]string{},
|
|
},
|
|
},
|
|
mocks: struct {
|
|
env bool
|
|
exec bool
|
|
}{
|
|
env: false,
|
|
exec: false,
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range table {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
cm := &containerMock{}
|
|
|
|
sal := &stepActionLocal{
|
|
env: map[string]string{},
|
|
RunContext: &RunContext{
|
|
Config: &Config{
|
|
GitHubInstance: "https://github.com",
|
|
},
|
|
JobContainer: cm,
|
|
Run: &model.Run{
|
|
JobID: "1",
|
|
Workflow: &model.Workflow{
|
|
Jobs: map[string]*model.Job{
|
|
"1": {},
|
|
},
|
|
},
|
|
},
|
|
StepResults: tt.initialStepResults,
|
|
},
|
|
Step: tt.stepModel,
|
|
action: tt.actionModel,
|
|
}
|
|
sal.RunContext.ExprEval = sal.RunContext.NewExpressionEvaluator(ctx)
|
|
|
|
if tt.mocks.exec {
|
|
suffixMatcher := func(suffix string) any {
|
|
return mock.MatchedBy(func(array []string) bool {
|
|
return strings.HasSuffix(array[1], suffix)
|
|
})
|
|
}
|
|
cm.On("Exec", suffixMatcher("runner/local/action/post.js"), sal.env, "", "").Return(func(ctx context.Context) error { return tt.err })
|
|
|
|
cm.On("Copy", "/var/run/act", mock.AnythingOfType("[]*container.FileEntry")).Return(func(ctx context.Context) error {
|
|
return nil
|
|
})
|
|
|
|
cm.On("UpdateFromEnv", "/var/run/act/workflow/envs.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
|
|
return nil
|
|
})
|
|
|
|
cm.On("UpdateFromEnv", "/var/run/act/workflow/statecmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
|
|
return nil
|
|
})
|
|
|
|
cm.On("UpdateFromEnv", "/var/run/act/workflow/outputcmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
|
|
return nil
|
|
})
|
|
|
|
cm.On("GetContainerArchive", ctx, "/var/run/act/workflow/pathcmd.txt").Return(io.NopCloser(&bytes.Buffer{}), nil)
|
|
}
|
|
|
|
err := sal.post()(ctx)
|
|
|
|
assert.Equal(t, tt.err, err)
|
|
assert.Equal(t, sal.RunContext.StepResults["post-step"], (*model.StepResult)(nil)) //nolint:testifylint // pre-existing issue from nektos/act
|
|
cm.AssertExpectations(t)
|
|
})
|
|
}
|
|
}
|