summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBo-Yi Wu <appleboy.tw@gmail.com>2023-07-13 03:10:54 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2023-07-13 03:10:54 +0200
commitdb662b36906a3aa0bd1211cee64e4ce73288f485 (patch)
treea61fbd5a283807a960f93e6ea37efe4a4bfc43b2
parentrefactor(register): refactor registration functions and improve logging (#288) (diff)
downloadforgejo-runner-db662b36906a3aa0bd1211cee64e4ce73288f485.tar.xz
forgejo-runner-db662b36906a3aa0bd1211cee64e4ce73288f485.zip
ci(lint): refactor code for clarity and linting compliance (#289)
- Removed `deadcode`, `structcheck`, and `varcheck` linters from `.golangci.yml` - Fixed a typo in a comment in `daemon.go` - Renamed `defaultActionsUrl` to `defaultActionsURL` in `exec.go` - Removed unnecessary else clause in `exec.go` and `runner.go` - Simplified variable initialization in `exec.go` - Changed function name from `getHttpClient` to `getHTTPClient` in `http.go` - Removed unnecessary else clause in `labels_test.go` Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> Reviewed-on: https://gitea.com/gitea/act_runner/pulls/289 Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com> Co-committed-by: Bo-Yi Wu <appleboy.tw@gmail.com>
-rw-r--r--.golangci.yml7
-rw-r--r--internal/app/cmd/daemon.go2
-rw-r--r--internal/app/cmd/exec.go18
-rw-r--r--internal/app/run/runner.go5
-rw-r--r--internal/pkg/client/http.go6
-rw-r--r--internal/pkg/labels/labels_test.go3
6 files changed, 16 insertions, 25 deletions
diff --git a/.golangci.yml b/.golangci.yml
index 8505828..41f9683 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -1,14 +1,11 @@
linters:
enable:
- gosimple
- - deadcode
- typecheck
- govet
- errcheck
- staticcheck
- unused
- - structcheck
- - varcheck
- dupl
#- gocyclo # The cyclomatic complexety of a lot of functions is too high, we should refactor those another time.
- gofmt
@@ -112,7 +109,6 @@ issues:
- gocritic
- linters:
- unused
- - deadcode
text: "swagger"
- path: contrib/pr/checkout.go
linters:
@@ -154,9 +150,6 @@ issues:
- path: cmd/dump.go
linters:
- dupl
- - path: services/webhook/webhook.go
- linters:
- - structcheck
- text: "commentFormatting: put a space between `//` and comment text"
linters:
- gocritic
diff --git a/internal/app/cmd/daemon.go b/internal/app/cmd/daemon.go
index d579739..ec02e08 100644
--- a/internal/app/cmd/daemon.go
+++ b/internal/app/cmd/daemon.go
@@ -79,7 +79,7 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command,
cfg.Container.DockerHost = dockerSocketPath
}
// check the scheme, if the scheme is not npipe or unix
- // set cfg.Container.DockerHost to "-" because it can't be mounted to the job conatiner
+ // set cfg.Container.DockerHost to "-" because it can't be mounted to the job container
if protoIndex := strings.Index(cfg.Container.DockerHost, "://"); protoIndex != -1 {
scheme := cfg.Container.DockerHost[:protoIndex]
if !strings.EqualFold(scheme, "npipe") && !strings.EqualFold(scheme, "unix") {
diff --git a/internal/app/cmd/exec.go b/internal/app/cmd/exec.go
index 9317701..9a28170 100644
--- a/internal/app/cmd/exec.go
+++ b/internal/app/cmd/exec.go
@@ -39,7 +39,7 @@ type executeArgs struct {
envs []string
envfile string
secrets []string
- defaultActionsUrl string
+ defaultActionsURL string
insecureSecrets bool
privileged bool
usernsMode string
@@ -252,7 +252,7 @@ func runExecList(ctx context.Context, planner model.WorkflowPlanner, execArgs *e
var filterPlan *model.Plan
// Determine the event name to be filtered
- var filterEventName string = ""
+ var filterEventName string
if len(execArgs.event) > 0 {
log.Infof("Using chosed event for filtering: %s", execArgs.event)
@@ -289,7 +289,7 @@ func runExecList(ctx context.Context, planner model.WorkflowPlanner, execArgs *e
}
}
- printList(filterPlan)
+ _ = printList(filterPlan)
return nil
}
@@ -359,11 +359,11 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command
execArgs.cacheHandler = handler
if len(execArgs.artifactServerAddr) == 0 {
- if ip := common.GetOutboundIP(); ip == nil {
+ ip := common.GetOutboundIP()
+ if ip == nil {
return fmt.Errorf("unable to determine outbound IP address")
- } else {
- execArgs.artifactServerAddr = ip.String()
}
+ execArgs.artifactServerAddr = ip.String()
}
if len(execArgs.artifactServerPath) == 0 {
@@ -407,7 +407,7 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command
ContainerNamePrefix: fmt.Sprintf("GITEA-ACTIONS-TASK-%s", eventName),
ContainerMaxLifetime: maxLifetime,
ContainerNetworkMode: container.NetworkMode(execArgs.network),
- DefaultActionInstance: execArgs.defaultActionsUrl,
+ DefaultActionInstance: execArgs.defaultActionsURL,
PlatformPicker: func(_ []string) string {
return execArgs.image
},
@@ -423,7 +423,7 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command
}
if !execArgs.debug {
- logLevel := log.Level(log.InfoLevel)
+ logLevel := log.InfoLevel
config.JobLoggerLevel = &logLevel
}
@@ -480,7 +480,7 @@ func loadExecCmd(ctx context.Context) *cobra.Command {
execCmd.PersistentFlags().StringVarP(&execArg.artifactServerPath, "artifact-server-path", "", ".", "Defines the path where the artifact server stores uploads and retrieves downloads from. If not specified the artifact server will not start.")
execCmd.PersistentFlags().StringVarP(&execArg.artifactServerAddr, "artifact-server-addr", "", "", "Defines the address where the artifact server listens")
execCmd.PersistentFlags().StringVarP(&execArg.artifactServerPort, "artifact-server-port", "", "34567", "Defines the port where the artifact server listens (will only bind to localhost).")
- execCmd.PersistentFlags().StringVarP(&execArg.defaultActionsUrl, "default-actions-url", "", "https://github.com", "Defines the default url of action instance.")
+ execCmd.PersistentFlags().StringVarP(&execArg.defaultActionsURL, "default-actions-url", "", "https://github.com", "Defines the default url of action instance.")
execCmd.PersistentFlags().BoolVarP(&execArg.noSkipCheckout, "no-skip-checkout", "", false, "Do not skip actions/checkout")
execCmd.PersistentFlags().BoolVarP(&execArg.debug, "debug", "d", false, "enable debug log")
execCmd.PersistentFlags().BoolVarP(&execArg.dryrun, "dryrun", "n", false, "dryrun mode")
diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go
index d6be102..c9f5f3e 100644
--- a/internal/app/run/runner.go
+++ b/internal/app/run/runner.go
@@ -91,10 +91,9 @@ func NewRunner(cfg *config.Config, reg *config.Registration, cli client.Client)
func (r *Runner) Run(ctx context.Context, task *runnerv1.Task) error {
if _, ok := r.runningTasks.Load(task.Id); ok {
return fmt.Errorf("task %d is already running", task.Id)
- } else {
- r.runningTasks.Store(task.Id, struct{}{})
- defer r.runningTasks.Delete(task.Id)
}
+ r.runningTasks.Store(task.Id, struct{}{})
+ defer r.runningTasks.Delete(task.Id)
ctx, cancel := context.WithTimeout(ctx, r.cfg.Runner.Timeout)
defer cancel()
diff --git a/internal/pkg/client/http.go b/internal/pkg/client/http.go
index bcd74ae..9f659df 100644
--- a/internal/pkg/client/http.go
+++ b/internal/pkg/client/http.go
@@ -14,7 +14,7 @@ import (
"github.com/bufbuild/connect-go"
)
-func getHttpClient(endpoint string, insecure bool) *http.Client {
+func getHTTPClient(endpoint string, insecure bool) *http.Client {
if strings.HasPrefix(endpoint, "https://") && insecure {
return &http.Client{
Transport: &http.Transport{
@@ -49,12 +49,12 @@ func New(endpoint string, insecure bool, uuid, token, version string, opts ...co
return &HTTPClient{
PingServiceClient: pingv1connect.NewPingServiceClient(
- getHttpClient(endpoint, insecure),
+ getHTTPClient(endpoint, insecure),
baseURL,
opts...,
),
RunnerServiceClient: runnerv1connect.NewRunnerServiceClient(
- getHttpClient(endpoint, insecure),
+ getHTTPClient(endpoint, insecure),
baseURL,
opts...,
),
diff --git a/internal/pkg/labels/labels_test.go b/internal/pkg/labels/labels_test.go
index dbef1ef..e46a27b 100644
--- a/internal/pkg/labels/labels_test.go
+++ b/internal/pkg/labels/labels_test.go
@@ -55,9 +55,8 @@ func TestParse(t *testing.T) {
if tt.wantErr {
require.Error(t, err)
return
- } else {
- require.NoError(t, err)
}
+ require.NoError(t, err)
assert.DeepEqual(t, got, tt.want)
})
}