From 416677ef116a094554ccbcbc56fbd76b866e9169 Mon Sep 17 00:00:00 2001 From: appleboy Date: Sun, 19 May 2024 11:21:38 +0800 Subject: [PATCH] refactor: refactor codebase and update GitHub workflow ### - Update golangci-lint-action from v4 to v6 in GitHub workflow - Refactor long usage strings in main.go for better readability - Rename function parameter from `Environment` to `envs` in plugin.go - Add nolint directive to Exec function in plugin.go to suppress gocyclo lint warning Signed-off-by: appleboy ### --- .github/workflows/lint.yml | 2 +- main.go | 21 +++++++++++++-------- plugin.go | 6 +++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e897eaf..d4e087d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -15,7 +15,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - name: Setup golangci-lint - uses: golangci/golangci-lint-action@v4 + uses: golangci/golangci-lint-action@v6 with: version: latest args: --verbose diff --git a/main.go b/main.go index 85100bd..caaa342 100644 --- a/main.go +++ b/main.go @@ -72,8 +72,9 @@ func main() { EnvVars: []string{"PLUGIN_REVERSION_ID", "REVERSION_ID", "INPUT_REVERSION_ID"}, }, &cli.StringFlag{ - Name: "s3-bucket", - Usage: "An Amazon S3 bucket in the same AWS Region as your function. The bucket can be in a different AWS account.", + Name: "s3-bucket", + Usage: "An Amazon S3 bucket in the same AWS Region as your function. " + + "The bucket can be in a different AWS account.", EnvVars: []string{"PLUGIN_S3_BUCKET", "S3_BUCKET", "INPUT_S3_BUCKET"}, }, &cli.StringFlag{ @@ -97,8 +98,9 @@ func main() { EnvVars: []string{"PLUGIN_SOURCE", "SOURCE", "INPUT_SOURCE"}, }, &cli.BoolFlag{ - Name: "dry-run", - Usage: "Set to true to validate the request parameters and access permissions without modifying the function code.", + Name: "dry-run", + Usage: "Set to true to validate the request parameters and " + + "access permissions without modifying the function code.", EnvVars: []string{"PLUGIN_DRY_RUN", "DRY_RUN", "INPUT_DRY_RUN"}, }, &cli.BoolFlag{ @@ -112,13 +114,16 @@ func main() { EnvVars: []string{"PLUGIN_PUBLISH", "PUBLISH", "INPUT_PUBLISH"}, }, &cli.Int64Flag{ - Name: "memory-size", - Usage: "The amount of memory that your function has access to. Increasing the function's memory also increases its CPU allocation. The default value is 128 MB. The value must be a multiple of 64 MB.", + Name: "memory-size", + Usage: "The amount of memory that your function has access to. " + + "Increasing the function's memory also increases its CPU allocation. " + + "The default value is 128 MB. The value must be a multiple of 64 MB.", EnvVars: []string{"PLUGIN_MEMORY_SIZE", "MEMORY_SIZE", "INPUT_MEMORY_SIZE"}, }, &cli.Int64Flag{ - Name: "timeout", - Usage: "The amount of time that Lambda allows a function to run before stopping it. The default is 3 seconds. The maximum allowed value is 900 seconds.", + Name: "timeout", + Usage: "The amount of time that Lambda allows a function to run before stopping it. " + + "The default is 3 seconds. The maximum allowed value is 900 seconds.", EnvVars: []string{"PLUGIN_TIMEOUT", "TIMEOUT", "INPUT_TIMEOUT"}, }, &cli.StringFlag{ diff --git a/plugin.go b/plugin.go index 5054722..f22a266 100644 --- a/plugin.go +++ b/plugin.go @@ -64,9 +64,9 @@ type ( } ) -func getEnvironment(Environment []string) map[string]string { +func getEnvironment(envs []string) map[string]string { output := make(map[string]string) - for _, e := range Environment { + for _, e := range envs { pair := strings.SplitN(e, "=", 2) if len(pair) != 2 { continue @@ -83,7 +83,7 @@ func (p Plugin) loadEnvironment(envs []string) *lambda.Environment { } // Exec executes the plugin. -func (p Plugin) Exec() error { +func (p Plugin) Exec() error { //nolint:gocyclo p.dump(p.Config) if p.Config.FunctionName == "" {