Fix all 93 lint-go errors

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
silverwind
2026-02-23 13:59:05 +01:00
parent 09d18916bf
commit 1670945af3
33 changed files with 158 additions and 128 deletions

View File

@@ -22,7 +22,7 @@ type cacheServerArgs struct {
}
func runCacheServer(configFile *string, cacheArgs *cacheServerArgs) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
return func(_ *cobra.Command, _ []string) error {
cfg, err := config.LoadDefault(*configFile)
if err != nil {
return fmt.Errorf("invalid configuration: %w", err)

View File

@@ -62,7 +62,7 @@ func Execute(ctx context.Context) {
Short: "Generate an example config file",
Args: cobra.MaximumNArgs(0),
Run: func(_ *cobra.Command, _ []string) {
fmt.Printf("%s", config.Example)
fmt.Fprintf(os.Stdout, "%s", config.Example)
},
})

View File

@@ -31,7 +31,7 @@ import (
)
func runDaemon(ctx context.Context, daemArgs *daemonArgs, configFile *string) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
return func(_ *cobra.Command, _ []string) error {
cfg, err := config.LoadDefault(*configFile)
if err != nil {
return fmt.Errorf("invalid configuration: %w", err)
@@ -144,10 +144,9 @@ func runDaemon(ctx context.Context, daemArgs *daemonArgs, configFile *string) fu
} else if err != nil {
log.WithError(err).Error("fail to invoke Declare")
return err
} else {
log.Infof("runner: %s, with version: %s, with labels: %v, declare successfully",
resp.Msg.Runner.Name, resp.Msg.Runner.Version, resp.Msg.Runner.Labels)
}
log.Infof("runner: %s, with version: %s, with labels: %v, declare successfully",
resp.Msg.Runner.Name, resp.Msg.Runner.Version, resp.Msg.Runner.Labels)
poller := poll.New(cfg, cli, runner)

View File

@@ -88,9 +88,9 @@ func (i *executeArgs) LoadSecrets() map[string]string {
} else if env, ok := os.LookupEnv(secretPairParts[0]); ok && env != "" {
s[secretPairParts[0]] = env
} else {
fmt.Printf("Provide value for '%s': ", secretPairParts[0])
fmt.Fprintf(os.Stdout, "Provide value for '%s': ", secretPairParts[0])
val, err := term.ReadPassword(int(os.Stdin.Fd()))
fmt.Println()
fmt.Fprintln(os.Stdout)
if err != nil {
log.Errorf("failed to read input: %v", err)
os.Exit(1)
@@ -241,7 +241,7 @@ func printList(plan *model.Plan) {
wfNameMaxWidth += 2
wfFileMaxWidth += 2
fmt.Printf("%*s%*s%*s%*s%*s%*s\n",
fmt.Fprintf(os.Stdout, "%*s%*s%*s%*s%*s%*s\n",
-stageMaxWidth, header.stage,
-jobIDMaxWidth, header.jobID,
-jobNameMaxWidth, header.jobName,
@@ -250,7 +250,7 @@ func printList(plan *model.Plan) {
-eventsMaxWidth, header.events,
)
for _, line := range lineInfos {
fmt.Printf("%*s%*s%*s%*s%*s%*s\n",
fmt.Fprintf(os.Stdout, "%*s%*s%*s%*s%*s%*s\n",
-stageMaxWidth, line.stage,
-jobIDMaxWidth, line.jobID,
-jobNameMaxWidth, line.jobName,
@@ -260,7 +260,7 @@ func printList(plan *model.Plan) {
)
}
if duplicateJobIDs {
fmt.Print("\nDetected multiple jobs with the same job name, use `-W` to specify the path to the specific workflow.\n")
fmt.Fprint(os.Stdout, "\nDetected multiple jobs with the same job name, use `-W` to specify the path to the specific workflow.\n")
}
}
@@ -312,7 +312,7 @@ func runExecList(planner model.WorkflowPlanner, execArgs *executeArgs) error {
}
func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command, args []string) error {
return func(_ *cobra.Command, args []string) error {
return func(_ *cobra.Command, _ []string) error {
planner, err := model.NewWorkflowPlanner(execArgs.WorkflowsPath(), model.PlannerConfig{
Recursive: !execArgs.noWorkflowRecurse,
Workflow: model.WorkflowConfig{
@@ -392,7 +392,7 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command
if len(execArgs.artifactServerPath) == 0 {
tempDir, err := os.MkdirTemp("", "gitea-act-")
if err != nil {
fmt.Println(err)
fmt.Fprintln(os.Stderr, err)
}
defer os.RemoveAll(tempDir)
@@ -460,7 +460,7 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command
log.Debugf("artifacts server started at %s:%s", execArgs.artifactServerPath, execArgs.artifactServerPort)
ctx = common.WithDryrun(ctx, execArgs.dryrun)
executor := r.NewPlanExecutor(plan).Finally(func(ctx context.Context) error {
executor := r.NewPlanExecutor(plan).Finally(func(_ context.Context) error {
artifactCancel()
return nil
})

View File

@@ -29,7 +29,7 @@ import (
// runRegister registers a runner to the server
func runRegister(ctx context.Context, regArgs *registerArgs, configFile *string) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {
return func(_ *cobra.Command, _ []string) error {
log.SetReportCaller(false)
isTerm := isatty.IsTerminal(os.Stdout.Fd())
log.SetFormatter(&log.TextFormatter{
@@ -251,7 +251,7 @@ func registerInteractive(ctx context.Context, configFile string, regArgs *regist
if stage == StageWaitingForRegistration {
log.Infof("Registering runner, name=%s, instance=%s, labels=%v.", inputs.RunnerName, inputs.InstanceAddr, inputs.Labels)
if err := doRegister(ctx, cfg, inputs); err != nil {
return fmt.Errorf("Failed to register runner: %w", err)
return fmt.Errorf("failed to register runner: %w", err)
}
log.Infof("Runner registered successfully.")
return nil
@@ -312,7 +312,7 @@ func registerNoInteractive(ctx context.Context, configFile string, regArgs *regi
return err
}
if err := doRegister(ctx, cfg, inputs); err != nil {
return fmt.Errorf("Failed to register runner: %w", err)
return fmt.Errorf("failed to register runner: %w", err)
}
log.Infof("Runner registered successfully.")
return nil

View File

@@ -143,14 +143,14 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
return err
}
job := workflow.GetJob(jobID)
var stepIds []string
var stepIDs []string
for i, v := range job.Steps {
if v.ID == "" {
v.ID = strconv.Itoa(i)
}
stepIds = append(stepIds, v.ID)
stepIDs = append(stepIDs, v.ID)
}
reporter.SetStepIdMapping(stepIds...)
reporter.SetStepIdMapping(stepIDs...)
taskContext := task.Context.Fields

View File

@@ -62,7 +62,7 @@ func generateWorkflow(task *runnerv1.Task) (*model.Workflow, string, error) {
// TODO GITEA
workflow.Jobs[jobID].RawNeeds = rawNeeds
workflow.Jobs[jobID].RawRunsOn.Encode("dummy")
_ = workflow.Jobs[jobID].RawRunsOn.Encode("dummy")
return workflow, jobID, nil
}

View File

@@ -8,9 +8,9 @@ import (
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
"gitea.com/gitea/act_runner/pkg/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.yaml.in/yaml/v4"
"gotest.tools/v3/assert"
)
func Test_generateWorkflow(t *testing.T) {
@@ -58,7 +58,7 @@ jobs:
},
},
assert: func(t *testing.T, wf *model.Workflow) {
assert.DeepEqual(t, wf.GetJob("job9").Needs(), []string{"job1", "job2"})
assert.Equal(t, []string{"job1", "job2"}, wf.GetJob("job9").Needs())
},
want1: "job9",
wantErr: false,
@@ -83,8 +83,8 @@ jobs:
},
assert: func(t *testing.T, wf *model.Workflow) {
job := wf.GetJob("test")
assert.DeepEqual(t, job.Needs(), []string{})
assert.Equal(t, len(job.Steps), 2)
assert.Equal(t, []string{}, job.Needs())
assert.Len(t, job.Steps, 2)
},
want1: "test",
wantErr: false,
@@ -125,9 +125,9 @@ jobs:
assert: func(t *testing.T, wf *model.Workflow) {
job := wf.GetJob("deploy")
needs := job.Needs()
assert.DeepEqual(t, needs, []string{"build", "lint", "test"})
assert.Equal(t, wf.Jobs["test"].Outputs["coverage"], "80%")
assert.Equal(t, wf.Jobs["lint"].Result, "failure")
assert.Equal(t, []string{"build", "lint", "test"}, needs)
assert.Equal(t, "80%", wf.Jobs["test"].Outputs["coverage"])
assert.Equal(t, "failure", wf.Jobs["lint"].Result)
},
want1: "deploy",
wantErr: false,
@@ -165,11 +165,11 @@ jobs:
},
},
assert: func(t *testing.T, wf *model.Workflow) {
assert.Equal(t, wf.Name, "Complex workflow")
assert.Equal(t, wf.Env["NODE_ENV"], "production")
assert.Equal(t, wf.Env["CI"], "true")
assert.Equal(t, "Complex workflow", wf.Name)
assert.Equal(t, "production", wf.Env["NODE_ENV"])
assert.Equal(t, "true", wf.Env["CI"])
job := wf.GetJob("build")
assert.Equal(t, len(job.Steps), 4)
assert.Len(t, job.Steps, 4)
},
want1: "build",
wantErr: false,
@@ -200,8 +200,8 @@ jobs:
assert: func(t *testing.T, wf *model.Workflow) {
job := wf.GetJob("integration")
container := job.Container()
assert.Equal(t, container.Image, "node:18")
assert.Equal(t, job.Services["postgres"].Image, "postgres:15")
assert.Equal(t, "node:18", container.Image)
assert.Equal(t, "postgres:15", job.Services["postgres"].Image)
},
want1: "integration",
wantErr: false,
@@ -231,7 +231,7 @@ jobs:
job := wf.GetJob("test")
matrixes, err := job.GetMatrixes()
require.NoError(t, err)
assert.Equal(t, len(matrixes), 2)
assert.Len(t, matrixes, 2)
},
want1: "test",
wantErr: false,
@@ -245,9 +245,9 @@ jobs:
},
},
assert: func(t *testing.T, wf *model.Workflow) {
assert.Equal(t, wf.Name, "Special: characters & test")
assert.Equal(t, "Special: characters & test", wf.Name)
job := wf.GetJob("test")
assert.Equal(t, len(job.Steps), 3)
assert.Len(t, job.Steps, 3)
},
want1: "test",
wantErr: false,
@@ -283,7 +283,7 @@ jobs:
}
require.NoError(t, err)
tt.assert(t, got)
assert.Equal(t, got1, tt.want1)
assert.Equal(t, tt.want1, got1)
})
}
}
@@ -301,7 +301,7 @@ func Test_yamlV4NodeRoundTrip(t *testing.T) {
out, err := yaml.Marshal(&node)
require.NoError(t, err)
assert.Equal(t, string(out), "- a\n- b\n- c\n")
assert.Equal(t, "- a\n- b\n- c\n", string(out))
})
t.Run("unmarshal and re-marshal workflow", func(t *testing.T) {
@@ -310,7 +310,7 @@ func Test_yamlV4NodeRoundTrip(t *testing.T) {
var wf map[string]any
err := yaml.Unmarshal(input, &wf)
require.NoError(t, err)
assert.Equal(t, wf["name"], "test")
assert.Equal(t, "test", wf["name"])
out, err := yaml.Marshal(wf)
require.NoError(t, err)
@@ -318,7 +318,7 @@ func Test_yamlV4NodeRoundTrip(t *testing.T) {
var wf2 map[string]any
err = yaml.Unmarshal(out, &wf2)
require.NoError(t, err)
assert.Equal(t, wf2["name"], "test")
assert.Equal(t, "test", wf2["name"])
})
t.Run("node kind constants", func(t *testing.T) {

View File

@@ -179,7 +179,7 @@ func (ee ExpressionEvaluator) evaluateYamlNodeInternal(ctx context.Context, node
case yaml.SequenceNode:
return ee.evaluateSequenceYamlNode(ctx, node, snode)
default:
return nil, nil
return nil, nil //nolint:nilnil
}
}