diff --git a/.golangci.yml b/.golangci.yml index f972999d..b2ba3ec2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -59,6 +59,9 @@ linters: - common-false-positives - legacy - std-error-handling + rules: + - linters: [revive] + text: avoid meaningless package names paths: - report - third_party$ diff --git a/cmd/graph.go b/cmd/graph.go index 35620856..902867d6 100644 --- a/cmd/graph.go +++ b/cmd/graph.go @@ -7,7 +7,7 @@ import ( "gitea.com/gitea/act_runner/pkg/model" ) -func drawGraph(plan *model.Plan) error { +func drawGraph(plan *model.Plan) { drawings := make([]*common.Drawing, 0) jobPen := common.NewPen(common.StyleSingleLine, 96) @@ -34,5 +34,4 @@ func drawGraph(plan *model.Plan) error { for _, d := range drawings { d.Draw(os.Stdout, maxWidth) } - return nil } diff --git a/cmd/list.go b/cmd/list.go index 260a05da..b8a95f0f 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -2,13 +2,14 @@ package cmd import ( "fmt" + "os" "strconv" "strings" "gitea.com/gitea/act_runner/pkg/model" ) -func printList(plan *model.Plan) error { +func printList(plan *model.Plan) { type lineInfoDef struct { jobID string jobName string @@ -82,7 +83,7 @@ func printList(plan *model.Plan) error { 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, @@ -91,7 +92,7 @@ func printList(plan *model.Plan) error { -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, @@ -101,7 +102,6 @@ func printList(plan *model.Plan) error { ) } 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") } - return nil } diff --git a/cmd/root.go b/cmd/root.go index 56337200..d2e9fe06 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -237,7 +237,7 @@ func bugReport(ctx context.Context, version string) error { info, err := container.GetHostInfo(ctx) if err != nil { - fmt.Println(report) + fmt.Fprintln(os.Stdout, report) return err } @@ -265,11 +265,11 @@ func bugReport(ctx context.Context, version string) error { } report += reportSb252.String() - fmt.Println(report) + fmt.Fprintln(os.Stdout, report) return nil } -func generateManPage(cmd *cobra.Command) error { +func generateManPage(cmd *cobra.Command) { header := &doc.GenManHeader{ Title: "act", Section: "1", @@ -277,8 +277,7 @@ func generateManPage(cmd *cobra.Command) error { } buf := new(bytes.Buffer) cobra.CheckErr(doc.GenMan(cmd, header, buf)) - fmt.Print(buf.String()) - return nil + fmt.Fprint(os.Stdout, buf.String()) } func listOptions(cmd *cobra.Command) error { @@ -287,7 +286,7 @@ func listOptions(cmd *cobra.Command) error { flags = append(flags, Flag{Name: f.Name, Default: f.DefValue, Description: f.Usage, Type: f.Value.Type()}) }) a, err := json.Marshal(flags) - fmt.Println(string(a)) + fmt.Fprintln(os.Stdout, string(a)) return err } @@ -409,7 +408,8 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str return bugReport(ctx, cmd.Version) } if ok, _ := cmd.Flags().GetBool("man-page"); ok { - return generateManPage(cmd) + generateManPage(cmd) + return nil } if input.listOptions { return listOptions(cmd) @@ -540,18 +540,12 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str } if list { - err = printList(filterPlan) - if err != nil { - return err - } + printList(filterPlan) return plannerErr } if graph { - err = drawGraph(filterPlan) - if err != nil { - return err - } + drawGraph(filterPlan) return plannerErr } diff --git a/cmd/secrets.go b/cmd/secrets.go index 3e053974..7567f158 100644 --- a/cmd/secrets.go +++ b/cmd/secrets.go @@ -24,9 +24,9 @@ func newSecrets(secretList []string) secrets { } 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) diff --git a/go.mod b/go.mod index 7ee2bd36..3af0b91f 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( code.gitea.io/actions-proto-go v0.4.1 code.gitea.io/gitea-vet v0.2.3 connectrpc.com/connect v1.19.1 - github.com/actions-oss/act-cli v0.0.0 // will be replaced github.com/avast/retry-go/v4 v4.7.0 github.com/docker/docker v28.5.1+incompatible github.com/joho/godotenv v1.5.1 @@ -56,7 +55,6 @@ require ( cyphar.com/go-pathrs v0.2.3 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/ProtonMail/go-crypto v1.3.0 // indirect - github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cloudflare/circl v1.6.3 // indirect github.com/containerd/errdefs/pkg v0.3.0 // indirect @@ -83,10 +81,12 @@ require ( github.com/mattn/go-colorable v0.1.14 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect github.com/moby/docker-image-spec v1.3.1 // indirect + github.com/moby/sys/atomicwriter v0.1.0 // indirect github.com/moby/sys/sequential v0.6.0 // indirect github.com/moby/sys/user v0.4.0 // indirect github.com/moby/sys/userns v0.1.0 // indirect github.com/moby/term v0.5.2 // indirect + github.com/morikuni/aec v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/pjbgf/sha1cd v0.5.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect @@ -101,15 +101,16 @@ require ( go.opentelemetry.io/auto/sdk v1.2.1 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.65.0 // indirect go.opentelemetry.io/otel v1.40.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 // indirect go.opentelemetry.io/otel/metric v1.40.0 // indirect go.opentelemetry.io/otel/trace v1.40.0 // indirect - go.opentelemetry.io/proto/otlp v1.0.0 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect + golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect golang.org/x/net v0.50.0 // indirect golang.org/x/sys v0.41.0 // indirect golang.org/x/text v0.34.0 // indirect golang.org/x/tools v0.42.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect ) diff --git a/go.sum b/go.sum index b5db33e6..044e42e0 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,6 @@ cyphar.com/go-pathrs v0.2.3 h1:0pH8gep37wB0BgaXrEaN1OtZhUMeS7VvaejSr6i822o= cyphar.com/go-pathrs v0.2.3/go.mod h1:y8f1EMG7r+hCuFf/rXsKqMJrJAUoADZGNh5/vZPKcGc= dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8= dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA= -gitea.com/actions-oss/act-cli v0.4.2-0.20260220200604-40ee0f3ef6fc h1:KXg17X1FZhnUM4J0bVG3gVS6jQCtkR6U5aV2ch0tJYA= -gitea.com/actions-oss/act-cli v0.4.2-0.20260220200604-40ee0f3ef6fc/go.mod h1:tl2dPJQRui7za899nfJIhPqP3a8ii+ySEvzL18mjC0U= github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8afgbRMd7mFxO99hRNu+6tazq8nFF9lIwo9JFroBk= github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ= @@ -21,6 +19,7 @@ github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF0 github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= +github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w= github.com/ProtonMail/go-crypto v1.3.0 h1:ILq8+Sf5If5DCpHQp4PbZdS1J7HDFRXz/+xKBiRGFrw= github.com/ProtonMail/go-crypto v1.3.0/go.mod h1:9whxjD8Rbs29b4XWbB8irEcE8KHMqaR2e7GWU1R+/PE= @@ -36,8 +35,8 @@ github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHS github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY= github.com/avast/retry-go/v4 v4.7.0 h1:yjDs35SlGvKwRNSykujfjdMxMhMQQM0TnIjJaHB+Zio= github.com/avast/retry-go/v4 v4.7.0/go.mod h1:ZMPDa3sY2bKgpLtap9JRUgk2yTAba7cgiFhqxY2Sg6Q= -github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= -github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= +github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg8= @@ -103,8 +102,9 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaU github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= +github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog= github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= @@ -172,7 +172,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= -github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI= @@ -226,8 +225,8 @@ go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.65.0 h1:7iP2uCb go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.65.0/go.mod h1:c7hN3ddxs/z6q9xwvfLPk+UHlWRQyaeR1LdgfL/66l0= go.opentelemetry.io/otel v1.40.0 h1:oA5YeOcpRTXq6NN7frwmwFR0Cn3RhTVZvXsP4duvCms= go.opentelemetry.io/otel v1.40.0/go.mod h1:IMb+uXZUKkMXdPddhwAHm6UfOwJyh4ct1ybIlV14J0g= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 h1:cl5P5/GIfFh4t6xyruOgJP5QiA1pw4fYYdv6nc6CBWw= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0/go.mod h1:zgBdWWAu7oEEMC06MMKc5NLbA/1YDXV1sMpSqEeLQLg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 h1:j9+03ymgYhPKmeXGk5Zu+cIZOlVzd9Zv7QIiyItjFBU= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0/go.mod h1:Y5+XiUG4Emn1hTfciPzGPJaSI+RpDts6BnCIir0SLqk= go.opentelemetry.io/otel/metric v1.40.0 h1:rcZe317KPftE2rstWIBitCdVp89A2HqjkxR3c11+p9g= @@ -238,8 +237,8 @@ go.opentelemetry.io/otel/sdk/metric v1.40.0 h1:mtmdVqgQkeRxHgRv4qhyJduP3fYJRMX4A go.opentelemetry.io/otel/sdk/metric v1.40.0/go.mod h1:4Z2bGMf0KSK3uRjlczMOeMhKU2rhUqdWNoKcYrtcBPg= go.opentelemetry.io/otel/trace v1.40.0 h1:WA4etStDttCSYuhwvEa8OP8I5EWu24lkOzp+ZYblVjw= go.opentelemetry.io/otel/trace v1.40.0/go.mod h1:zeAhriXecNGP/s2SEG3+Y8X9ujcJOTqQ5RgdEJcawiA= -go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= -go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= +go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= +go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= go.yaml.in/yaml/v4 v4.0.0-rc.3 h1:3h1fjsh1CTAPjW7q/EMe+C8shx5d8ctzZTrLcs/j8Go= diff --git a/internal/app/cmd/cache-server.go b/internal/app/cmd/cache-server.go index e35232b9..2d2d0bf9 100644 --- a/internal/app/cmd/cache-server.go +++ b/internal/app/cmd/cache-server.go @@ -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) diff --git a/internal/app/cmd/cmd.go b/internal/app/cmd/cmd.go index 9ef30c36..514084c7 100644 --- a/internal/app/cmd/cmd.go +++ b/internal/app/cmd/cmd.go @@ -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) }, }) diff --git a/internal/app/cmd/daemon.go b/internal/app/cmd/daemon.go index b63d9557..93e56824 100644 --- a/internal/app/cmd/daemon.go +++ b/internal/app/cmd/daemon.go @@ -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) diff --git a/internal/app/cmd/exec.go b/internal/app/cmd/exec.go index b02469ef..6c9e5b7b 100644 --- a/internal/app/cmd/exec.go +++ b/internal/app/cmd/exec.go @@ -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 }) diff --git a/internal/app/cmd/register.go b/internal/app/cmd/register.go index 15fd2291..ada1dc0e 100644 --- a/internal/app/cmd/register.go +++ b/internal/app/cmd/register.go @@ -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 diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go index c2d4d014..84bcf0bd 100644 --- a/internal/app/run/runner.go +++ b/internal/app/run/runner.go @@ -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 diff --git a/internal/app/run/workflow.go b/internal/app/run/workflow.go index 3a7678c3..3e3fd591 100644 --- a/internal/app/run/workflow.go +++ b/internal/app/run/workflow.go @@ -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 } diff --git a/internal/app/run/workflow_test.go b/internal/app/run/workflow_test.go index e40ba17b..56f35b86 100644 --- a/internal/app/run/workflow_test.go +++ b/internal/app/run/workflow_test.go @@ -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) { diff --git a/internal/templateeval/evaluate.go b/internal/templateeval/evaluate.go index 9acaf2b2..858e51ab 100644 --- a/internal/templateeval/evaluate.go +++ b/internal/templateeval/evaluate.go @@ -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 } } diff --git a/pkg/artifactcache/handler.go b/pkg/artifactcache/handler.go index a756b7be..4161bb49 100644 --- a/pkg/artifactcache/handler.go +++ b/pkg/artifactcache/handler.go @@ -437,7 +437,7 @@ func findCache(db *bolthold.Store, keys []string, version string) (*Cache, error } return cache, nil } - return nil, nil + return nil, nil //nolint:nilnil } func insertCache(db *bolthold.Store, cache *Cache) error { diff --git a/pkg/artifactcache/handler_test.go b/pkg/artifactcache/handler_test.go index d1030f9e..cee95ea8 100644 --- a/pkg/artifactcache/handler_test.go +++ b/pkg/artifactcache/handler_test.go @@ -41,7 +41,10 @@ func TestHandler(t *testing.T) { require.NoError(t, handler.Close()) assert.Nil(t, handler.server) assert.Nil(t, handler.listener) - _, err := http.Post(fmt.Sprintf("%s/caches/%d", base, 1), "", nil) + resp, err := http.Post(fmt.Sprintf("%s/caches/%d", base, 1), "", nil) + if resp != nil { + defer resp.Body.Close() + } require.Error(t, err) }) }() @@ -51,6 +54,7 @@ func TestHandler(t *testing.T) { version := "c19da02a2bd7e77277f1ac29ab45c09b7d46a4ee758284e26bb3045ad11d9d20" resp, err := http.Get(fmt.Sprintf("%s/cache?keys=%s&version=%s", base, key, version)) require.NoError(t, err) + defer resp.Body.Close() require.Equal(t, 204, resp.StatusCode) }) @@ -66,6 +70,7 @@ func TestHandler(t *testing.T) { t.Run("clean", func(t *testing.T) { resp, err := http.Post(base+"/clean", "", nil) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) }) @@ -74,6 +79,7 @@ func TestHandler(t *testing.T) { require.NoError(t, err) resp, err := http.Post(base+"/caches", "application/json", bytes.NewReader(body)) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 400, resp.StatusCode) }) @@ -92,6 +98,7 @@ func TestHandler(t *testing.T) { require.NoError(t, err) resp, err := http.Post(base+"/caches", "application/json", bytes.NewReader(body)) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) require.NoError(t, json.NewDecoder(resp.Body).Decode(&first)) @@ -106,6 +113,7 @@ func TestHandler(t *testing.T) { require.NoError(t, err) resp, err := http.Post(base+"/caches", "application/json", bytes.NewReader(body)) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) require.NoError(t, json.NewDecoder(resp.Body).Decode(&second)) @@ -123,6 +131,7 @@ func TestHandler(t *testing.T) { req.Header.Set("Content-Range", "bytes 0-99/*") resp, err := http.DefaultClient.Do(req) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 400, resp.StatusCode) }) @@ -134,6 +143,7 @@ func TestHandler(t *testing.T) { req.Header.Set("Content-Range", "bytes 0-99/*") resp, err := http.DefaultClient.Do(req) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 400, resp.StatusCode) }) @@ -153,6 +163,7 @@ func TestHandler(t *testing.T) { require.NoError(t, err) resp, err := http.Post(base+"/caches", "application/json", bytes.NewReader(body)) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) got := struct { @@ -169,11 +180,13 @@ func TestHandler(t *testing.T) { req.Header.Set("Content-Range", "bytes 0-99/*") resp, err := http.DefaultClient.Do(req) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) } { resp, err := http.Post(fmt.Sprintf("%s/caches/%d", base, id), "", nil) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) } { @@ -184,6 +197,7 @@ func TestHandler(t *testing.T) { req.Header.Set("Content-Range", "bytes 0-99/*") resp, err := http.DefaultClient.Do(req) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 400, resp.StatusCode) } }) @@ -204,6 +218,7 @@ func TestHandler(t *testing.T) { require.NoError(t, err) resp, err := http.Post(base+"/caches", "application/json", bytes.NewReader(body)) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) got := struct { @@ -220,6 +235,7 @@ func TestHandler(t *testing.T) { req.Header.Set("Content-Range", "bytes xx-99/*") resp, err := http.DefaultClient.Do(req) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 400, resp.StatusCode) } }) @@ -228,6 +244,7 @@ func TestHandler(t *testing.T) { { resp, err := http.Post(base+"/caches/invalid_id", "", nil) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 400, resp.StatusCode) } }) @@ -236,6 +253,7 @@ func TestHandler(t *testing.T) { { resp, err := http.Post(fmt.Sprintf("%s/caches/%d", base, 100), "", nil) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 400, resp.StatusCode) } }) @@ -256,6 +274,7 @@ func TestHandler(t *testing.T) { require.NoError(t, err) resp, err := http.Post(base+"/caches", "application/json", bytes.NewReader(body)) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) got := struct { @@ -272,16 +291,19 @@ func TestHandler(t *testing.T) { req.Header.Set("Content-Range", "bytes 0-99/*") resp, err := http.DefaultClient.Do(req) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) } { resp, err := http.Post(fmt.Sprintf("%s/caches/%d", base, id), "", nil) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) } { resp, err := http.Post(fmt.Sprintf("%s/caches/%d", base, id), "", nil) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 400, resp.StatusCode) } }) @@ -302,6 +324,7 @@ func TestHandler(t *testing.T) { require.NoError(t, err) resp, err := http.Post(base+"/caches", "application/json", bytes.NewReader(body)) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) got := struct { @@ -318,11 +341,13 @@ func TestHandler(t *testing.T) { req.Header.Set("Content-Range", "bytes 0-59/*") resp, err := http.DefaultClient.Do(req) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) } { resp, err := http.Post(fmt.Sprintf("%s/caches/%d", base, id), "", nil) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 500, resp.StatusCode) } }) @@ -330,18 +355,21 @@ func TestHandler(t *testing.T) { t.Run("get with bad id", func(t *testing.T) { resp, err := http.Get(base + "/artifacts/invalid_id") require.NoError(t, err) + defer resp.Body.Close() require.Equal(t, 400, resp.StatusCode) }) t.Run("get with not exist id", func(t *testing.T) { resp, err := http.Get(fmt.Sprintf("%s/artifacts/%d", base, 100)) require.NoError(t, err) + defer resp.Body.Close() require.Equal(t, 404, resp.StatusCode) }) t.Run("get with not exist id", func(t *testing.T) { resp, err := http.Get(fmt.Sprintf("%s/artifacts/%d", base, 100)) require.NoError(t, err) + defer resp.Body.Close() require.Equal(t, 404, resp.StatusCode) }) @@ -373,6 +401,7 @@ func TestHandler(t *testing.T) { resp, err := http.Get(fmt.Sprintf("%s/cache?keys=%s&version=%s", base, reqKeys, version)) require.NoError(t, err) + defer resp.Body.Close() require.Equal(t, 200, resp.StatusCode) /* @@ -393,6 +422,7 @@ func TestHandler(t *testing.T) { contentResp, err := http.Get(got.ArchiveLocation) require.NoError(t, err) + defer contentResp.Body.Close() require.Equal(t, 200, contentResp.StatusCode) content, err := io.ReadAll(contentResp.Body) require.NoError(t, err) @@ -411,6 +441,7 @@ func TestHandler(t *testing.T) { reqKey := key + "_aBc" resp, err := http.Get(fmt.Sprintf("%s/cache?keys=%s&version=%s", base, reqKey, version)) require.NoError(t, err) + defer resp.Body.Close() require.Equal(t, 200, resp.StatusCode) got := struct { Result string `json:"result"` @@ -450,6 +481,7 @@ func TestHandler(t *testing.T) { resp, err := http.Get(fmt.Sprintf("%s/cache?keys=%s&version=%s", base, reqKeys, version)) require.NoError(t, err) + defer resp.Body.Close() require.Equal(t, 200, resp.StatusCode) /* @@ -468,6 +500,7 @@ func TestHandler(t *testing.T) { contentResp, err := http.Get(got.ArchiveLocation) require.NoError(t, err) + defer contentResp.Body.Close() require.Equal(t, 200, contentResp.StatusCode) content, err := io.ReadAll(contentResp.Body) require.NoError(t, err) @@ -502,6 +535,7 @@ func TestHandler(t *testing.T) { resp, err := http.Get(fmt.Sprintf("%s/cache?keys=%s&version=%s", base, reqKeys, version)) require.NoError(t, err) + defer resp.Body.Close() require.Equal(t, 200, resp.StatusCode) /* @@ -521,6 +555,7 @@ func TestHandler(t *testing.T) { contentResp, err := http.Get(got.ArchiveLocation) require.NoError(t, err) + defer contentResp.Body.Close() require.Equal(t, 200, contentResp.StatusCode) content, err := io.ReadAll(contentResp.Body) require.NoError(t, err) @@ -528,7 +563,7 @@ func TestHandler(t *testing.T) { }) } -func uploadCacheNormally(t *testing.T, base, key, version string, content []byte) { +func uploadCacheNormally(t *testing.T, base, key, version string, content []byte) { //nolint:unparam var id uint64 { body, err := json.Marshal(&Request{ @@ -539,6 +574,7 @@ func uploadCacheNormally(t *testing.T, base, key, version string, content []byte require.NoError(t, err) resp, err := http.Post(base+"/caches", "application/json", bytes.NewReader(body)) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) got := struct { @@ -555,17 +591,20 @@ func uploadCacheNormally(t *testing.T, base, key, version string, content []byte req.Header.Set("Content-Range", "bytes 0-99/*") resp, err := http.DefaultClient.Do(req) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) } { resp, err := http.Post(fmt.Sprintf("%s/caches/%d", base, id), "", nil) require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) } var archiveLocation string { resp, err := http.Get(fmt.Sprintf("%s/cache?keys=%s&version=%s", base, key, version)) require.NoError(t, err) + defer resp.Body.Close() require.Equal(t, 200, resp.StatusCode) got := struct { Result string `json:"result"` @@ -580,6 +619,7 @@ func uploadCacheNormally(t *testing.T, base, key, version string, content []byte { resp, err := http.Get(archiveLocation) //nolint:gosec require.NoError(t, err) + defer resp.Body.Close() require.Equal(t, 200, resp.StatusCode) got, err := io.ReadAll(resp.Body) require.NoError(t, err) diff --git a/pkg/common/auth_test.go b/pkg/common/auth_test.go index a0e1b80a..6d642ee0 100644 --- a/pkg/common/auth_test.go +++ b/pkg/common/auth_test.go @@ -28,7 +28,7 @@ func TestCreateAuthorizationToken(t *testing.T) { assert.Contains(t, scp, "Actions.Results:1:2") taskIDClaim, ok := claims["TaskID"] assert.True(t, ok, "Has TaskID claim in jwt token") - assert.Equal(t, float64(taskID), taskIDClaim, "Supplied taskid must match stored one") + assert.InDelta(t, float64(taskID), taskIDClaim, 0, "Supplied taskid must match stored one") acClaim, ok := claims["ac"] assert.True(t, ok, "Has ac claim in jwt token") ac, ok := acClaim.(string) diff --git a/pkg/common/file.go b/pkg/common/file.go index 09c21029..ca092e02 100644 --- a/pkg/common/file.go +++ b/pkg/common/file.go @@ -1,9 +1,10 @@ package common import ( - "fmt" "io" "os" + + log "github.com/sirupsen/logrus" ) // CopyFile copy file @@ -59,13 +60,13 @@ func CopyDir(source string, dest string) (err error) { // create sub-directories - recursively err = CopyDir(sourcefilepointer, destinationfilepointer) if err != nil { - fmt.Println(err) + log.Error(err) } } else { // perform copy err = CopyFile(sourcefilepointer, destinationfilepointer) if err != nil { - fmt.Println(err) + log.Error(err) } } } diff --git a/pkg/common/git/git.go b/pkg/common/git/git.go index 87f105e1..7ff21756 100644 --- a/pkg/common/git/git.go +++ b/pkg/common/git/git.go @@ -170,8 +170,8 @@ func FindGithubRepo(ctx context.Context, file, githubInstance, remoteName string if err != nil { return "", err } - _, slug, err := findGitSlug(url, githubInstance) - return slug, err + _, slug := findGitSlug(url, githubInstance) + return slug, nil } func findGitRemoteURL(_ context.Context, file, remoteName string) (string, error) { @@ -213,23 +213,23 @@ func matchesRegex(url string, matchers ...findStringSubmatcher) []string { } // TODO deprecate and remove githubInstance parameter -func findGitSlug(url string, _ /* githubInstance */ string) (string, string, error) { +func findGitSlug(url string, _ /* githubInstance */ string) (string, string) { if matches := matchesRegex(url, codeCommitHTTPRegex, codeCommitSSHRegex); matches != nil { - return "CodeCommit", matches[2], nil + return "CodeCommit", matches[2] } if matches := matchesRegex(url, githubHTTPRegex, githubSSHRegex); matches != nil { - return "GitHub", fmt.Sprintf("%s/%s", matches[1], matches[2]), nil + return "GitHub", fmt.Sprintf("%s/%s", matches[1], matches[2]) } if matches := matchesRegex(url, regexp.MustCompile(`^https?://(?:[^/]+)/([^/]+)/([^/]+)(?:.git)?$`), regexp.MustCompile(`([^/]+)[:/]([^/]+)/([^/]+)(?:.git)?$`), ); matches != nil { - return "GitHubEnterprise", fmt.Sprintf("%s/%s", matches[1], matches[2]), nil + return "GitHubEnterprise", fmt.Sprintf("%s/%s", matches[1], matches[2]) } - return "", url, nil + return "", url } // NewGitCloneExecutorInput the input for the NewGitCloneExecutor diff --git a/pkg/common/git/git_test.go b/pkg/common/git/git_test.go index efb68757..0c952de9 100644 --- a/pkg/common/git/git_test.go +++ b/pkg/common/git/git_test.go @@ -38,19 +38,15 @@ func TestFindGitSlug(t *testing.T) { } for _, tt := range slugTests { - provider, slug, err := findGitSlug(tt.url, "github.com") + provider, slug := findGitSlug(tt.url, "github.com") - require.NoError(t, err) assert.Equal(tt.provider, provider) assert.Equal(tt.slug, slug) } } func testDir(t *testing.T) string { - basedir, err := os.MkdirTemp("", "act-test") - require.NoError(t, err) - t.Cleanup(func() { _ = os.RemoveAll(basedir) }) - return basedir + return t.TempDir() } func cleanGitHooks(dir string) error { diff --git a/pkg/container/docker_cli.go b/pkg/container/docker_cli.go index fc5a11a9..10c2861c 100644 --- a/pkg/container/docker_cli.go +++ b/pkg/container/docker_cli.go @@ -7,7 +7,7 @@ // See DOCKER_LICENSE for the full license text. // -//nolint:unparam,errcheck,depguard,deadcode,unused +//nolint:errcheck,depguard,unused package container import ( diff --git a/pkg/container/docker_cli_test.go b/pkg/container/docker_cli_test.go index 568fdb29..942c229e 100644 --- a/pkg/container/docker_cli_test.go +++ b/pkg/container/docker_cli_test.go @@ -6,7 +6,7 @@ // See DOCKER_LICENSE for the full license text. // -//nolint:unparam,whitespace,depguard,dupl,gocritic +//nolint:whitespace,depguard,dupl,gocritic package container import ( diff --git a/pkg/container/host_environment_test.go b/pkg/container/host_environment_test.go index acf2639c..035f206a 100644 --- a/pkg/container/host_environment_test.go +++ b/pkg/container/host_environment_test.go @@ -17,9 +17,7 @@ import ( var _ ExecutionsEnvironment = &HostEnvironment{} func TestCopyDir(t *testing.T) { - dir, err := os.MkdirTemp("", "test-host-env-*") - require.NoError(t, err) - defer os.RemoveAll(dir) + dir := t.TempDir() ctx := context.Background() e := &HostEnvironment{ Path: filepath.Join(dir, "path"), @@ -33,7 +31,7 @@ func TestCopyDir(t *testing.T) { _ = os.MkdirAll(e.TmpDir, 0700) _ = os.MkdirAll(e.ToolCache, 0700) _ = os.MkdirAll(e.ActPath, 0700) - err = e.CopyDir(e.Workdir, e.Path, true)(ctx) + err := e.CopyDir(e.Workdir, e.Path, true)(ctx) require.NoError(t, err) } diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index 346efcf5..4f709d83 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -610,7 +610,7 @@ func (s *Step) GetEnv() map[string]string { // ShellCommand returns the command for the shell func (s *Step) ShellCommand() string { - shellCommand := "" + var shellCommand string //Reference: https://github.com/actions/runner/blob/8109c962f09d9acc473d92c595ff43afceddb347/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs#L9-L17 switch s.Shell { diff --git a/pkg/runner/action_cache_test.go b/pkg/runner/action_cache_test.go index 6806a26b..e318612c 100644 --- a/pkg/runner/action_cache_test.go +++ b/pkg/runner/action_cache_test.go @@ -53,20 +53,17 @@ func TestActionCache(t *testing.T) { }, } for _, c := range refs { - t.Run(c.Name, func(_ *testing.T) { + t.Run(c.Name, func(t *testing.T) { sha, err := cache.Fetch(ctx, c.CacheDir, c.Repo, c.Ref, "") - if !a.NoError(err) || !a.NotEmpty(sha) { - return - } + require.NoError(t, err) + require.NotEmpty(t, sha) atar, err := cache.GetTarArchive(ctx, c.CacheDir, sha, "js") - if !a.NoError(err) || !a.NotEmpty(atar) { - return - } + require.NoError(t, err) + require.NotEmpty(t, atar) mytar := tar.NewReader(atar) th, err := mytar.Next() - if !a.NoError(err) || !a.NotEqual(0, th.Size) { - return - } + require.NoError(t, err) + require.NotEqual(t, 0, th.Size) buf := &bytes.Buffer{} // G110: Potential DoS vulnerability via decompression bomb (gosec) _, err = io.Copy(buf, mytar) diff --git a/pkg/runner/expression.go b/pkg/runner/expression.go index 32c0929c..39dc1f0f 100644 --- a/pkg/runner/expression.go +++ b/pkg/runner/expression.go @@ -253,7 +253,7 @@ func (ee expressionEvaluator) evaluateScalarYamlNode(ctx context.Context, node * return nil, err } if !strings.Contains(in, "${{") || !strings.Contains(in, "}}") { - return nil, nil + return nil, nil //nolint:nilnil } expr, _ := rewriteSubExpression(ctx, in, false) res, err := ee.evaluate(ctx, expr, exprparser.DefaultStatusCheckNone) @@ -366,7 +366,7 @@ func (ee expressionEvaluator) evaluateYamlNodeInternal(ctx context.Context, node case yaml.SequenceNode: return ee.evaluateSequenceYamlNode(ctx, node) default: - return nil, nil + return nil, nil //nolint:nilnil } } @@ -432,7 +432,7 @@ func rewriteSubExpression(ctx context.Context, in string, forceFormat bool) (str if strStart > -1 { matches := strPattern.FindStringIndex(in[pos:]) if matches == nil { - return "", errors.New("unclosed string.") + return "", errors.New("unclosed string") } strStart = -1 diff --git a/pkg/runner/expression_test.go b/pkg/runner/expression_test.go index a241b830..cb55242a 100644 --- a/pkg/runner/expression_test.go +++ b/pkg/runner/expression_test.go @@ -150,7 +150,7 @@ func TestEvaluateRunContext(t *testing.T) { } assertObject.Equal(table.out, out, table.in) } else { - assertObject.Error(err, table.in) + require.Error(t, err, table.in) assertObject.Equal(table.errMesg, err.Error(), table.in) } }) diff --git a/pkg/runner/job_executor_test.go b/pkg/runner/job_executor_test.go index f4756387..e44a035a 100644 --- a/pkg/runner/job_executor_test.go +++ b/pkg/runner/job_executor_test.go @@ -239,7 +239,7 @@ func TestNewJobExecutor(t *testing.T) { for _, tt := range table { t.Run(tt.name, func(t *testing.T) { - t.Log("::group::%s\n", tt.name) + t.Logf("::group::%s\n", tt.name) ctx := common.WithJobErrorContainer(context.Background()) jim := &jobInfoMock{} diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 5ed648d4..127bf6cf 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -469,7 +469,7 @@ func (rc *RunContext) prepareServiceContainers(ctx context.Context, logger logru return networkName, createAndDeleteNetwork, nil } -func (rc *RunContext) execJobContainer(cmd []string, env map[string]string, user, workdir string) common.Executor { +func (rc *RunContext) execJobContainer(cmd []string, env map[string]string, user, workdir string) common.Executor { //nolint:unparam return func(ctx context.Context) error { return rc.JobContainer.Exec(cmd, env, user, workdir)(ctx) } diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index 1c38d347..a3900edf 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -99,7 +99,7 @@ func TestGraphMissingFirst(t *testing.T) { require.NoError(t, err) plan, err := planner.PlanEvent("push") - assert.EqualError(t, err, "unable to build dependency graph for no first (no-first.yml)") + require.EqualError(t, err, "unable to build dependency graph for no first (no-first.yml)") assert.NotNil(t, plan) assert.Empty(t, plan.Stages) } @@ -173,7 +173,7 @@ type TestJobFileInfo struct { } func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config) { - t.Log("::group::%s\n", j.workflowPath) + t.Logf("::group::%s\n", j.workflowPath) log.SetLevel(logLevel) diff --git a/pkg/workflowpattern/trace_writer.go b/pkg/workflowpattern/trace_writer.go index 675aa187..46e59594 100644 --- a/pkg/workflowpattern/trace_writer.go +++ b/pkg/workflowpattern/trace_writer.go @@ -1,6 +1,9 @@ package workflowpattern -import "fmt" +import ( + "fmt" + "os" +) type TraceWriter interface { Info(string, ...any) @@ -14,5 +17,5 @@ func (*EmptyTraceWriter) Info(string, ...any) { type StdOutTraceWriter struct{} func (*StdOutTraceWriter) Info(format string, args ...any) { - fmt.Printf(format+"\n", args...) + fmt.Fprintf(os.Stdout, format+"\n", args...) }