mirror of
https://gitea.com/gitea/act_runner
synced 2026-11-03 10:57:22 +01:00
Removes dead code and redundant logic and consolidates tests, so there is less to read and maintain. No behavior change. 1. **act/runner**: inline single-use wrappers, compile regexes once instead of per call, embed the trampoline as a string, drop the unused legacy result of `parseActionCommand` 2. **act/container**: `sanitizeConfig` and `mergeContainerConfigs` stop returning the configs they already mutate in place, drop never-set option fields and the unused `user` parameter of `ExecWithCmdLine` 3. **act/common and cache server**: drop the unused `Trace`/`Tracef` loggers and the short SHA of `FindGitRevision`, `RegisterJob` releases through `RevokeJob` 4. **daemon, poller and reporter**: one shutdown wait for both poll modes, drop an unreachable fetch timeout branch, guard the reporter's last report time with its existing lock instead of an atomic 5. **build**: drop unused Makefile and release workflow variables, collapse the goreleaser ignore list to the same build targets 6. **tests**: fold near-duplicate tests into tables with shared setup Throughout, hand-rolled logic gives way to `cmp.Or`, `strings.Cut`, `slices` and `min`/`max`. Reviewed-on: https://gitea.com/gitea/runner/pulls/1335 Reviewed-by: bircni <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io>
88 lines
2.9 KiB
Go
88 lines
2.9 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package runner
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.dev/actionslib/pkg/model"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.yaml.in/yaml/v4"
|
|
)
|
|
|
|
func TestMaxParallelStrategy(t *testing.T) {
|
|
for _, tt := range []struct {
|
|
name string
|
|
maxParallelString string
|
|
expectedMaxParallel int
|
|
}{
|
|
{"max-parallel-1", "1", 1},
|
|
{"max-parallel-2", "2", 2},
|
|
{"max-parallel-default", "", 4},
|
|
{"max-parallel-10-clamped-to-combinations", "10", 5},
|
|
{"max-parallel-invalid-falls-back-to-default", "tow", 4},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
var rawMatrix yaml.Node
|
|
require.NoError(t, rawMatrix.Encode(map[string][]any{"version": {1, 2, 3, 4, 5}}))
|
|
job := &model.Job{Strategy: &model.Strategy{MaxParallelString: tt.maxParallelString, RawMatrix: rawMatrix}}
|
|
|
|
matrixes, err := job.GetMatrixes()
|
|
require.NoError(t, err)
|
|
require.Len(t, matrixes, 5)
|
|
assert.Equal(t, tt.expectedMaxParallel, maxParallelFor(job.Strategy, len(matrixes)))
|
|
})
|
|
}
|
|
|
|
t.Run("deferred strategy", func(t *testing.T) {
|
|
workflow, err := model.ReadWorkflow(strings.NewReader(`
|
|
jobs:
|
|
test:
|
|
if: false
|
|
strategy: ${{ fromJSON('{"max-parallel":2,"fail-fast":false,"matrix":{"os":["ubuntu","windows"]}}') }}
|
|
`))
|
|
require.NoError(t, err)
|
|
job := workflow.Jobs["test"]
|
|
rawStrategy := model.CloneYamlNode(job.RawStrategy)
|
|
require.NoError(t, (&runnerImpl{config: &Config{}}).NewPlanExecutor(&model.Plan{Stages: []*model.Stage{{Runs: []*model.Run{{Workflow: workflow, JobID: "test"}}}}})(t.Context()))
|
|
require.NotNil(t, job.Strategy)
|
|
assert.False(t, job.Strategy.GetFailFast())
|
|
assert.Equal(t, 2, maxParallelFor(job.Strategy, 5))
|
|
matrixes, err := job.GetMatrixes()
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []map[string]any{{"os": "ubuntu"}, {"os": "windows"}}, matrixes)
|
|
assert.Equal(t, rawStrategy, job.RawStrategy)
|
|
})
|
|
}
|
|
|
|
func TestNewPlanExecutorInvalidMatrix(t *testing.T) {
|
|
var rawMatrix yaml.Node
|
|
require.NoError(t, rawMatrix.Encode(map[string]any{
|
|
"config": map[string]any{"nested": "value"},
|
|
}))
|
|
|
|
plan := &model.Plan{Stages: []*model.Stage{{Runs: []*model.Run{{
|
|
Workflow: &model.Workflow{Jobs: map[string]*model.Job{
|
|
"test": {Strategy: &model.Strategy{RawMatrix: rawMatrix}},
|
|
}},
|
|
JobID: "test",
|
|
}}}}}
|
|
runner := &runnerImpl{config: &Config{}}
|
|
|
|
require.ErrorContains(t, runner.NewPlanExecutor(plan)(t.Context()), "could not get job matrix:")
|
|
|
|
for _, strategy := range []string{
|
|
`${{ fromJSON('invalid') }}`,
|
|
`${{ '${{ inputs.unresolved }}' }}`,
|
|
} {
|
|
t.Run(strategy, func(t *testing.T) {
|
|
workflow, err := model.ReadWorkflow(strings.NewReader("jobs:\n test:\n strategy: " + strategy))
|
|
require.NoError(t, err)
|
|
require.Error(t, runner.NewPlanExecutor(&model.Plan{Stages: []*model.Stage{{Runs: []*model.Run{{Workflow: workflow, JobID: "test"}}}}})(t.Context()))
|
|
})
|
|
}
|
|
}
|