more lint errors

This commit is contained in:
Christopher Homberger
2026-02-23 00:30:44 +01:00
parent bffc600775
commit 09d18916bf
22 changed files with 46 additions and 61 deletions

View File

@@ -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 { func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error { return func(_ *cobra.Command, args []string) error {
planner, err := model.NewWorkflowPlanner(execArgs.WorkflowsPath(), model.PlannerConfig{ planner, err := model.NewWorkflowPlanner(execArgs.WorkflowsPath(), model.PlannerConfig{
Recursive: !execArgs.noWorkflowRecurse, Recursive: !execArgs.noWorkflowRecurse,
Workflow: model.WorkflowConfig{ Workflow: model.WorkflowConfig{

View File

@@ -1,14 +1,13 @@
package functions package functions
import ( import (
"fmt"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestFormat(t *testing.T) { func TestFormat(t *testing.T) {
s, err := Format("Hello {0}, you have {1} new messages", "Alice", 5) _, err := Format("Hello {0}, you have {1} new messages", "Alice", 5)
require.NoError(t, err) require.NoError(t, err)
fmt.Println(s) // Hello Alice, you have 5 new messages // fmt.Println(s) // Hello Alice, you have 5 new messages
} }

View File

@@ -187,7 +187,7 @@ func (e *Evaluator) evalBinaryNodeLeft(node *exprparser.BinaryNode, left *Evalua
return CreateIntermediateResult(e.Context(), ret), nil return CreateIntermediateResult(e.Context(), ret), nil
} }
} }
return nil, nil return nil, errors.ErrUnsupported
} }
func (e *Evaluator) evalBinaryNodeRight(node *exprparser.BinaryNode, left *EvaluationResult, right *EvaluationResult) (*EvaluationResult, error) { func (e *Evaluator) evalBinaryNodeRight(node *exprparser.BinaryNode, left *EvaluationResult, right *EvaluationResult) (*EvaluationResult, error) {

View File

@@ -6,8 +6,8 @@ package labels
import ( import (
"testing" "testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"gotest.tools/v3/assert"
) )
func TestParse(t *testing.T) { func TestParse(t *testing.T) {
@@ -57,7 +57,7 @@ func TestParse(t *testing.T) {
return return
} }
require.NoError(t, err) require.NoError(t, err)
assert.DeepEqual(t, got, tt.want) assert.Equal(t, tt.want, got)
}) })
} }
} }

View File

@@ -134,14 +134,14 @@ func (c ArtifactContext) JSON(status int, _ ...any) {
c.Resp.WriteHeader(status) c.Resp.WriteHeader(status)
} }
func validateRunIDV4(ctx *ArtifactContext, rawRunID string) (any, int64, bool) { func validateRunIDV4(ctx *ArtifactContext, rawRunID string) (int64, bool) {
runID, err := strconv.ParseInt(rawRunID, 10, 64) runID, err := strconv.ParseInt(rawRunID, 10, 64)
if err != nil /* || task.Job.RunID != runID*/ { if err != nil /* || task.Job.RunID != runID*/ {
log.Error("Error runID not match") log.Error("Error runID not match")
ctx.Error(http.StatusBadRequest, "run-id does not match") ctx.Error(http.StatusBadRequest, "run-id does not match")
return nil, 0, false return 0, false
} }
return nil, runID, true return runID, true
} }
func RoutesV4(router *httprouter.Router, baseDir string, fsys WriteFS, rfs fs.FS) { func RoutesV4(router *httprouter.Router, baseDir string, fsys WriteFS, rfs fs.FS) {
@@ -271,7 +271,7 @@ func (r *artifactV4Routes) createArtifact(ctx *ArtifactContext) {
if ok := r.parseProtbufBody(ctx, &req); !ok { if ok := r.parseProtbufBody(ctx, &req); !ok {
return return
} }
_, runID, ok := validateRunIDV4(ctx, req.WorkflowRunBackendId) runID, ok := validateRunIDV4(ctx, req.WorkflowRunBackendId)
if !ok { if !ok {
return return
} }
@@ -342,7 +342,7 @@ func (r *artifactV4Routes) finalizeArtifact(ctx *ArtifactContext) {
if ok := r.parseProtbufBody(ctx, &req); !ok { if ok := r.parseProtbufBody(ctx, &req); !ok {
return return
} }
_, _, ok := validateRunIDV4(ctx, req.WorkflowRunBackendId) _, ok := validateRunIDV4(ctx, req.WorkflowRunBackendId)
if !ok { if !ok {
return return
} }
@@ -360,7 +360,7 @@ func (r *artifactV4Routes) listArtifacts(ctx *ArtifactContext) {
if ok := r.parseProtbufBody(ctx, &req); !ok { if ok := r.parseProtbufBody(ctx, &req); !ok {
return return
} }
_, runID, ok := validateRunIDV4(ctx, req.WorkflowRunBackendId) runID, ok := validateRunIDV4(ctx, req.WorkflowRunBackendId)
if !ok { if !ok {
return return
} }
@@ -405,7 +405,7 @@ func (r *artifactV4Routes) getSignedArtifactURL(ctx *ArtifactContext) {
if ok := r.parseProtbufBody(ctx, &req); !ok { if ok := r.parseProtbufBody(ctx, &req); !ok {
return return
} }
_, runID, ok := validateRunIDV4(ctx, req.WorkflowRunBackendId) runID, ok := validateRunIDV4(ctx, req.WorkflowRunBackendId)
if !ok { if !ok {
return return
} }
@@ -439,7 +439,7 @@ func (r *artifactV4Routes) deleteArtifact(ctx *ArtifactContext) {
if ok := r.parseProtbufBody(ctx, &req); !ok { if ok := r.parseProtbufBody(ctx, &req); !ok {
return return
} }
_, runID, ok := validateRunIDV4(ctx, req.WorkflowRunBackendId) runID, ok := validateRunIDV4(ctx, req.WorkflowRunBackendId)
if !ok { if !ok {
return return
} }

View File

@@ -277,7 +277,7 @@ func TestArtifactFlow(t *testing.T) {
func runTestJobFile(ctx context.Context, t *testing.T, tjfi TestJobFileInfo) { func runTestJobFile(ctx context.Context, t *testing.T, tjfi TestJobFileInfo) {
t.Run(tjfi.workflowPath, func(t *testing.T) { t.Run(tjfi.workflowPath, func(t *testing.T) {
fmt.Printf("::group::%s\n", tjfi.workflowPath) t.Logf("::group::%s\n", tjfi.workflowPath)
if err := os.RemoveAll(artifactsPath); err != nil { if err := os.RemoveAll(artifactsPath); err != nil {
panic(err) panic(err)
@@ -317,7 +317,7 @@ func runTestJobFile(ctx context.Context, t *testing.T, tjfi TestJobFileInfo) {
assert.Nil(t, plan) assert.Nil(t, plan)
} }
fmt.Println("::endgroup::") t.Log("::endgroup::")
}) })
} }

View File

@@ -302,7 +302,7 @@ func TestParseWithMacAddress(t *testing.T) {
t.Fatalf("Expected an error with %v mac-address, got %v", invalidMacAddress, err) t.Fatalf("Expected an error with %v mac-address, got %v", invalidMacAddress, err)
} }
config, hostConfig, _ := mustParse(t, validMacAddress) config, hostConfig, _ := mustParse(t, validMacAddress)
fmt.Printf("MacAddress: %+v\n", hostConfig) t.Logf("MacAddress: %+v\n", hostConfig)
assert.Equal(t, "92:d0:c6:0a:29:33", config.MacAddress) //nolint:staticcheck assert.Equal(t, "92:d0:c6:0a:29:33", config.MacAddress) //nolint:staticcheck
} }

View File

@@ -154,7 +154,7 @@ func TestDockerExecAbort(t *testing.T) {
cancel() cancel()
err := <-channel err := <-channel
assert.ErrorIs(t, err, context.Canceled) require.ErrorIs(t, err, context.Canceled)
conn.AssertExpectations(t) conn.AssertExpectations(t)
client.AssertExpectations(t) client.AssertExpectations(t)
@@ -231,7 +231,7 @@ func TestDockerCopyTarStreamErrorInCopyFiles(t *testing.T) {
} }
err := cr.CopyTarStream(ctx, "/var/run/act", &bytes.Buffer{}) err := cr.CopyTarStream(ctx, "/var/run/act", &bytes.Buffer{})
assert.ErrorIs(t, err, merr) require.ErrorIs(t, err, merr)
conn.AssertExpectations(t) conn.AssertExpectations(t)
client.AssertExpectations(t) client.AssertExpectations(t)
@@ -256,7 +256,7 @@ func TestDockerCopyTarStreamErrorInMkdir(t *testing.T) {
} }
err := cr.CopyTarStream(ctx, "/var/run/act", &bytes.Buffer{}) err := cr.CopyTarStream(ctx, "/var/run/act", &bytes.Buffer{})
assert.ErrorIs(t, err, merr) require.ErrorIs(t, err, merr)
conn.AssertExpectations(t) conn.AssertExpectations(t)
client.AssertExpectations(t) client.AssertExpectations(t)

View File

@@ -20,7 +20,7 @@ func TestGetSocketAndHostWithSocket(t *testing.T) {
CommonSocketLocations = originalCommonSocketLocations CommonSocketLocations = originalCommonSocketLocations
dockerHost := "unix:///my/docker/host.sock" dockerHost := "unix:///my/docker/host.sock"
socketURI := "/path/to/my.socket" socketURI := "/path/to/my.socket"
os.Setenv("DOCKER_HOST", dockerHost) t.Setenv("DOCKER_HOST", dockerHost)
// Act // Act
ret, err := GetSocketAndHost(socketURI) ret, err := GetSocketAndHost(socketURI)
@@ -33,7 +33,7 @@ func TestGetSocketAndHostWithSocket(t *testing.T) {
func TestGetSocketAndHostNoSocket(t *testing.T) { func TestGetSocketAndHostNoSocket(t *testing.T) {
// Arrange // Arrange
dockerHost := "unix:///my/docker/host.sock" dockerHost := "unix:///my/docker/host.sock"
os.Setenv("DOCKER_HOST", dockerHost) t.Setenv("DOCKER_HOST", dockerHost)
// Act // Act
ret, err := GetSocketAndHost("") ret, err := GetSocketAndHost("")
@@ -64,7 +64,7 @@ func TestGetSocketAndHostDontMount(t *testing.T) {
// Arrange // Arrange
CommonSocketLocations = originalCommonSocketLocations CommonSocketLocations = originalCommonSocketLocations
dockerHost := "unix:///my/docker/host.sock" dockerHost := "unix:///my/docker/host.sock"
os.Setenv("DOCKER_HOST", dockerHost) t.Setenv("DOCKER_HOST", dockerHost)
// Act // Act
ret, err := GetSocketAndHost("-") ret, err := GetSocketAndHost("-")

View File

@@ -38,8 +38,7 @@ func TestCopyDir(t *testing.T) {
} }
func TestGetContainerArchive(t *testing.T) { func TestGetContainerArchive(t *testing.T) {
dir, err := os.MkdirTemp("", "test-host-env-*") dir := t.TempDir()
require.NoError(t, err)
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
ctx := context.Background() ctx := context.Background()
e := &HostEnvironment{ e := &HostEnvironment{
@@ -55,7 +54,7 @@ func TestGetContainerArchive(t *testing.T) {
_ = os.MkdirAll(e.ToolCache, 0700) _ = os.MkdirAll(e.ToolCache, 0700)
_ = os.MkdirAll(e.ActPath, 0700) _ = os.MkdirAll(e.ActPath, 0700)
expectedContent := []byte("sdde/7sh") expectedContent := []byte("sdde/7sh")
err = os.WriteFile(filepath.Join(e.Path, "action.yml"), expectedContent, 0600) err := os.WriteFile(filepath.Join(e.Path, "action.yml"), expectedContent, 0600)
require.NoError(t, err) require.NoError(t, err)
archive, err := e.GetContainerArchive(ctx, e.Path) archive, err := e.GetContainerArchive(ctx, e.Path)
require.NoError(t, err) require.NoError(t, err)

View File

@@ -35,18 +35,13 @@ func TestContainerPath(t *testing.T) {
{fmt.Sprintf("/mnt/%v/act", rootDriveLetter), "act", rootDrive + "\\"}, {fmt.Sprintf("/mnt/%v/act", rootDriveLetter), "act", rootDrive + "\\"},
} { } {
if v.workDir != "" { if v.workDir != "" {
if err := os.Chdir(v.workDir); err != nil { t.Chdir(v.workDir)
log.Error(err)
t.Fail()
}
} }
assert.Equal(t, v.destinationPath, linuxcontainerext.ToContainerPath(v.sourcePath)) assert.Equal(t, v.destinationPath, linuxcontainerext.ToContainerPath(v.sourcePath))
} }
if err := os.Chdir(cwd); err != nil { t.Chdir(cwd)
log.Error(err)
}
} else { } else {
cwd, err := os.Getwd() cwd, err := os.Getwd()
if err != nil { if err != nil {

View File

@@ -9,6 +9,7 @@ import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
//nolint:gosec //nolint:gosec
@@ -69,7 +70,7 @@ func TestActionCache(t *testing.T) {
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
// G110: Potential DoS vulnerability via decompression bomb (gosec) // G110: Potential DoS vulnerability via decompression bomb (gosec)
_, err = io.Copy(buf, mytar) _, err = io.Copy(buf, mytar)
a.NoError(err) require.NoError(t, err)
str := buf.String() str := buf.String()
a.NotEmpty(str) a.NotEmpty(str)
}) })

View File

@@ -3,6 +3,7 @@ package runner
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"fmt" "fmt"
"maps" "maps"
"path" "path"
@@ -431,7 +432,7 @@ func rewriteSubExpression(ctx context.Context, in string, forceFormat bool) (str
if strStart > -1 { if strStart > -1 {
matches := strPattern.FindStringIndex(in[pos:]) matches := strPattern.FindStringIndex(in[pos:])
if matches == nil { if matches == nil {
panic("unclosed string.") return "", errors.New("unclosed string.")
} }
strStart = -1 strStart = -1

View File

@@ -189,7 +189,7 @@ func TestEvaluateStep(t *testing.T) {
require.NoError(t, err, table.in) require.NoError(t, err, table.in)
assertObject.Equal(table.out, out, table.in) assertObject.Equal(table.out, out, table.in)
} else { } else {
assertObject.Error(err, table.in) require.Error(t, err, table.in)
assertObject.Equal(table.errMesg, err.Error(), table.in) assertObject.Equal(table.errMesg, err.Error(), table.in)
} }
}) })

View File

@@ -3,7 +3,6 @@ package runner
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"io" "io"
"slices" "slices"
"testing" "testing"
@@ -240,7 +239,7 @@ func TestNewJobExecutor(t *testing.T) {
for _, tt := range table { for _, tt := range table {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
fmt.Printf("::group::%s\n", tt.name) t.Log("::group::%s\n", tt.name)
ctx := common.WithJobErrorContainer(context.Background()) ctx := common.WithJobErrorContainer(context.Background())
jim := &jobInfoMock{} jim := &jobInfoMock{}
@@ -331,7 +330,7 @@ func TestNewJobExecutor(t *testing.T) {
jim.AssertExpectations(t) jim.AssertExpectations(t)
sfm.AssertExpectations(t) sfm.AssertExpectations(t)
fmt.Println("::endgroup::") t.Log("::endgroup::")
}) })
} }
} }

View File

@@ -620,7 +620,7 @@ func (rc *RunContext) waitForServiceContainer(c container.ExecutionsEnvironment)
return func(ctx context.Context) error { return func(ctx context.Context) error {
sctx, cancel := context.WithTimeout(ctx, time.Minute*5) sctx, cancel := context.WithTimeout(ctx, time.Minute*5)
defer cancel() defer cancel()
health := container.HealthStarting var health container.Health
delay := time.Second delay := time.Second
for i := 0; ; i++ { for i := 0; ; i++ {
health = c.GetHealth(sctx) health = c.GetHealth(sctx)
@@ -1119,7 +1119,7 @@ func (rc *RunContext) setMainCtxVars(env map[string]string, name string, value s
} }
} }
func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubContext, env map[string]string) map[string]string { func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubContext, env map[string]string) {
env["CI"] = "true" env["CI"] = "true"
rc.setMainCtxVars(env, "WORKFLOW", github.Workflow) rc.setMainCtxVars(env, "WORKFLOW", github.Workflow)
rc.setMainCtxVars(env, "RUN_ATTEMPT", github.RunAttempt) rc.setMainCtxVars(env, "RUN_ATTEMPT", github.RunAttempt)
@@ -1165,8 +1165,6 @@ func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubCon
} }
} }
} }
return env
} }
func setActionRuntimeVars(rc *RunContext, env map[string]string) { func setActionRuntimeVars(rc *RunContext, env map[string]string) {

View File

@@ -160,7 +160,7 @@ func TestRunContext_EvalBool(t *testing.T) {
assertObject := assert.New(t) assertObject := assert.New(t)
b, err := EvalBool(context.Background(), rc.ExprEval, table.in, exprparser.DefaultStatusCheckSuccess) b, err := EvalBool(context.Background(), rc.ExprEval, table.in, exprparser.DefaultStatusCheckSuccess)
if table.wantErr { if table.wantErr {
assertObject.Error(err) require.Error(t, err)
} }
assertObject.Equal(table.out, b, "Expected %s to be %v, was %v", table.in, table.out, b) assertObject.Equal(table.out, b, "Expected %s to be %v, was %v", table.in, table.out, b)

View File

@@ -6,7 +6,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"io" "io"
"os" "os"
"os/exec" "os/exec"
@@ -117,7 +116,7 @@ func TestGraphWithMissing(t *testing.T) {
plan, err := planner.PlanEvent("push") plan, err := planner.PlanEvent("push")
assert.NotNil(t, plan) assert.NotNil(t, plan)
assert.Empty(t, plan.Stages) assert.Empty(t, plan.Stages)
assert.EqualError(t, err, "unable to build dependency graph for missing (missing.yml)") require.EqualError(t, err, "unable to build dependency graph for missing (missing.yml)")
assert.Contains(t, buf.String(), "unable to build dependency graph for missing (missing.yml)") assert.Contains(t, buf.String(), "unable to build dependency graph for missing (missing.yml)")
log.SetOutput(out) log.SetOutput(out)
} }
@@ -174,7 +173,7 @@ type TestJobFileInfo struct {
} }
func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config) { func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config) {
fmt.Printf("::group::%s\n", j.workflowPath) t.Log("::group::%s\n", j.workflowPath)
log.SetLevel(logLevel) log.SetLevel(logLevel)
@@ -218,7 +217,7 @@ func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config
} }
} }
fmt.Println("::endgroup::") t.Log("::endgroup::")
} }
type TestConfig struct { type TestConfig struct {
@@ -739,7 +738,7 @@ func TestMaskValues(t *testing.T) {
assertNoSecret := func(text string, _ string) { assertNoSecret := func(text string, _ string) {
found := strings.Contains(text, "composite secret") found := strings.Contains(text, "composite secret")
if found { if found {
fmt.Printf("\nFound Secret in the given text:\n%s\n", text) t.Logf("\nFound Secret in the given text:\n%s\n", text)
} }
assert.NotContains(t, text, "composite secret") assert.NotContains(t, text, "composite secret")
} }

View File

@@ -110,10 +110,7 @@ func runStepExecutor(step step, stage stepStage, executor common.Executor) commo
rc.StepResults[rc.CurrentStep] = stepResult rc.StepResults[rc.CurrentStep] = stepResult
} }
err := setupEnv(ctx, step) setupEnv(ctx, step)
if err != nil {
return err
}
cctx := common.JobCancelContext(ctx) cctx := common.JobCancelContext(ctx)
rc.Cancelled = cctx != nil && cctx.Err() != nil rc.Cancelled = cctx != nil && cctx.Err() != nil
@@ -241,7 +238,7 @@ func evaluateStepTimeout(ctx context.Context, exprEval ExpressionEvaluator, step
return ctx, func() {} return ctx, func() {}
} }
func setupEnv(ctx context.Context, step step) error { func setupEnv(ctx context.Context, step step) {
rc := step.getRunContext() rc := step.getRunContext()
mergeEnv(ctx, step) mergeEnv(ctx, step)
@@ -264,8 +261,6 @@ func setupEnv(ctx context.Context, step step) error {
} }
common.Logger(ctx).Debugf("setupEnv => %v", *step.getEnv()) common.Logger(ctx).Debugf("setupEnv => %v", *step.getEnv())
return nil
} }
func mergeEnv(ctx context.Context, step step) { func mergeEnv(ctx context.Context, step step) {

View File

@@ -237,7 +237,7 @@ func TestStepActionRemote(t *testing.T) {
err = sar.main()(ctx) err = sar.main()(ctx)
} }
assert.ErrorIs(t, err, tt.runError) require.ErrorIs(t, err, tt.runError)
assert.Equal(t, sar.RunContext.StepResults["step"], tt.result) assert.Equal(t, sar.RunContext.StepResults["step"], tt.result)
sarm.AssertExpectations(t) sarm.AssertExpectations(t)

View File

@@ -205,7 +205,7 @@ func (sr *stepRun) setupShell(ctx context.Context) {
func (sr *stepRun) setupWorkingDirectory(ctx context.Context) { func (sr *stepRun) setupWorkingDirectory(ctx context.Context) {
rc := sr.RunContext rc := sr.RunContext
step := sr.Step step := sr.Step
workingdirectory := "" var workingdirectory string
if step.WorkingDirectory == "" { if step.WorkingDirectory == "" {
workingdirectory = rc.Run.Job().Defaults.Run.WorkingDirectory workingdirectory = rc.Run.Job().Defaults.Run.WorkingDirectory

View File

@@ -152,8 +152,7 @@ func TestSetupEnv(t *testing.T) {
sm.On("getStepModel").Return(step) sm.On("getStepModel").Return(step)
sm.On("getEnv").Return(&env) sm.On("getEnv").Return(&env)
err := setupEnv(context.Background(), sm) setupEnv(context.Background(), sm)
require.NoError(t, err)
// These are commit or system specific // These are commit or system specific
delete((env), "GITHUB_REF") delete((env), "GITHUB_REF")