From fef922e92a6c9c45b874da824f1946c654ed61a4 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 15 Jan 2024 07:06:52 +0000 Subject: [PATCH] format via gofumpt (#123) format code ;) Reviewed-on: https://codeberg.org/woodpecker-plugins/docker-buildx/pulls/123 Reviewed-by: qwerty287 Co-authored-by: 6543 <6543@obermui.de> Co-committed-by: 6543 <6543@obermui.de> --- .ecrc | 11 +++++++++++ .editorconfig | 19 +++++++++++++++++++ .woodpecker.yml | 17 +++++++++++++++++ Makefile | 12 ++++++++++++ cmd/docker-buildx/main.go | 2 +- go.mod | 2 +- go.sum | 8 -------- plugin/docker_test.go | 11 ++++------- plugin/ecr.go | 21 ++++++++++----------- 9 files changed, 75 insertions(+), 28 deletions(-) create mode 100644 .ecrc create mode 100644 .editorconfig diff --git a/.ecrc b/.ecrc new file mode 100644 index 0000000..ed9f777 --- /dev/null +++ b/.ecrc @@ -0,0 +1,11 @@ +{ + "Exclude": [ + ".git", + "go.mod", "go.sum", + "vendor", + "LICENSE", + "node_modules", + "_test.go", + "Makefile" + ] +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..34f6015 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +tab_width = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.go] +indent_style = tab + +[*.md] +trim_trailing_whitespace = false + +[Makefile] +indent_style = tab diff --git a/.woodpecker.yml b/.woodpecker.yml index cf319d2..d91ab73 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -34,10 +34,24 @@ steps: test: image: *golang + depends_on: vendor commands: go test -cover ./... + lint-editorconfig: + image: docker.io/mstruebing/editorconfig-checker:2.7.2 + when: + event: pull_request + + lint-format: + image: *golang + depends_on: vendor + commands: make formatcheck + when: + event: pull_request + publish-dryrun: image: *build_plugin + depends_on: test pull: true settings: <<: *base_buildx_settings @@ -51,6 +65,7 @@ steps: publish: image: *build_plugin + depends_on: test settings: <<: *base_buildx_settings logins: *login_setting @@ -60,6 +75,7 @@ steps: publish_pr_image: image: *build_plugin + depends_on: test settings: <<: *base_buildx_settings tag: pull_${CI_COMMIT_PULL_REQUEST} @@ -71,6 +87,7 @@ steps: # TODO: replace by plugin-ready-release-go once it supports gitea gitea-release: image: "woodpeckerci/plugin-gitea-release:0.3.1" + depends_on: test settings: base_url: https://codeberg.org title: ${CI_COMMIT_TAG} diff --git a/Makefile b/Makefile index 1af273c..f7351c3 100644 --- a/Makefile +++ b/Makefile @@ -2,5 +2,17 @@ TARGETOS ?= linux TARGETARCH ?= amd64 LDFLAGS := -s -w -extldflags "-static" +.PHONY: build build: CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -v -a -tags netgo -o plugin-docker-buildx ./cmd/docker-buildx + +format: install-tools + gofumpt -extra -w . + +formatcheck: install-tools + @([ -z "$(shell gofumpt -d . | head)" ]) || (echo "Source is unformatted"; exit 1) + +install-tools: ## Install development tools + @hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ + go install mvdan.cc/gofumpt@latest; \ + fi diff --git a/cmd/docker-buildx/main.go b/cmd/docker-buildx/main.go index 5531f44..6fceb2f 100644 --- a/cmd/docker-buildx/main.go +++ b/cmd/docker-buildx/main.go @@ -19,7 +19,7 @@ func main() { if _, err := os.Stat("/run/drone/env"); err == nil { godotenv.Overload("/run/drone/env") } - + if envFile, set := os.LookupEnv("PLUGIN_ENV_FILE"); set { godotenv.Overload(envFile) } diff --git a/go.mod b/go.mod index 123bd44..de51ec6 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/aws/aws-sdk-go v1.49.17 github.com/drone-plugins/drone-plugin-lib v0.4.2 github.com/joho/godotenv v1.5.1 + github.com/pelletier/go-toml/v2 v2.1.1 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.8.4 github.com/urfave/cli/v2 v2.27.1 @@ -20,7 +21,6 @@ require ( github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect - github.com/pelletier/go-toml/v2 v2.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect diff --git a/go.sum b/go.sum index 03e57a2..742a7c7 100644 --- a/go.sum +++ b/go.sum @@ -4,10 +4,6 @@ github.com/6543/go-version v1.3.1 h1:HvOp+Telns7HWJ2Xo/05YXQSB2bE0WmVgbHqwMPZT4U github.com/6543/go-version v1.3.1/go.mod h1:oqFAHCwtLVUTLdhQmVZWYvaHXTdsbB4SY85at64SQEo= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= -github.com/aws/aws-sdk-go v1.47.4 h1:IyhNbmPt+5ldi5HNzv7ZnXiqSglDMaJiZlzj4Yq3qnk= -github.com/aws/aws-sdk-go v1.47.4/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= -github.com/aws/aws-sdk-go v1.49.16 h1:KAQwhLg296hfffRdh+itA9p7Nx/3cXS/qOa3uF9ssig= -github.com/aws/aws-sdk-go v1.49.16/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/aws/aws-sdk-go v1.49.17 h1:Cc+7LgPjKeJkF2SdNo1IkpQ5Dfl9HCZEVw9OP3CPuEI= github.com/aws/aws-sdk-go v1.49.17/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= @@ -39,10 +35,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/urfave/cli/v2 v2.26.0 h1:3f3AMg3HpThFNT4I++TKOejZO8yU55t3JnnSr4S4QEI= -github.com/urfave/cli/v2 v2.26.0/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= -github.com/urfave/cli/v2 v2.27.0 h1:uNs1K8JwTFL84X68j5Fjny6hfANh9nTlJ6dRtZAFAHY= -github.com/urfave/cli/v2 v2.27.0/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho= github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= diff --git a/plugin/docker_test.go b/plugin/docker_test.go index 8be3298..f2b13d1 100644 --- a/plugin/docker_test.go +++ b/plugin/docker_test.go @@ -10,14 +10,13 @@ import ( ) func TestCommandBuilder(t *testing.T) { - tests := []struct { Name string Daemon Daemon Input string WantedLen int Skip bool - Excuse string + Excuse string }{ { Name: "Single driver-opt value", @@ -29,15 +28,14 @@ func TestCommandBuilder(t *testing.T) { Name: "Single driver-opt value with comma", Input: "no_proxy=.mydomain,.sub.domain.com", WantedLen: 1, - Skip: true, - Excuse: "Can be enabled whenever #94 is fixed.", - + Skip: true, + Excuse: "Can be enabled whenever #94 is fixed.", }, } for _, test := range tests { t.Run(test.Name, func(t *testing.T) { - if (test.Skip) { + if test.Skip { t.Skip(fmt.Printf("%v skipped. %v", test.Name, test.Excuse)) } // prepare test values to mock plugin call with settings @@ -68,5 +66,4 @@ func TestCommandBuilder(t *testing.T) { assert.Len(t, test.Daemon.BuildkitDriverOpt.Value(), test.WantedLen) }) } - } diff --git a/plugin/ecr.go b/plugin/ecr.go index 7579d21..5409898 100644 --- a/plugin/ecr.go +++ b/plugin/ecr.go @@ -17,14 +17,15 @@ import ( const DefaultRegion = "us-east-1" -var repo string -var assumeRole string -var externalID string -var ecr_login Login -var aws_region string +var ( + repo string + assumeRole string + externalID string + ecr_login Login + aws_region string +) func (p *Plugin) EcrInit() { - // create a standalone Login object to account for single repo and multi-repo case if len(p.settings.Logins) >= 1 { for _, login := range p.settings.Logins { @@ -81,7 +82,6 @@ func (p *Plugin) EcrInit() { svc := getECRClient(sess, assumeRole, externalID) username, password, registry, err := getAuthInfo(svc) - if err != nil { log.Fatalf("error getting ECR auth: %v", err) } @@ -135,7 +135,6 @@ func (p *Plugin) EcrInit() { p.settings.DefaultLogin.Password = password p.settings.DefaultLogin.Registry = registry } - } func trimHostname(repo, registry string) string { @@ -168,7 +167,7 @@ func updateImageScannningConfig(svc *ecr.ECR, name string, scanOnPush bool) (err return err } -func uploadLifeCyclePolicy(svc *ecr.ECR, lifecyclePolicy string, name string) (err error) { +func uploadLifeCyclePolicy(svc *ecr.ECR, lifecyclePolicy, name string) (err error) { input := &ecr.PutLifecyclePolicyInput{} input.SetLifecyclePolicyText(lifecyclePolicy) input.SetRepositoryName(name) @@ -177,7 +176,7 @@ func uploadLifeCyclePolicy(svc *ecr.ECR, lifecyclePolicy string, name string) (e return err } -func uploadRepositoryPolicy(svc *ecr.ECR, repositoryPolicy string, name string) (err error) { +func uploadRepositoryPolicy(svc *ecr.ECR, repositoryPolicy, name string) (err error) { input := &ecr.SetRepositoryPolicyInput{} input.SetPolicyText(repositoryPolicy) input.SetRepositoryName(name) @@ -209,7 +208,7 @@ func getAuthInfo(svc *ecr.ECR) (username, password, registry string, err error) return } -func getECRClient(sess *session.Session, role string, externalId string) *ecr.ECR { +func getECRClient(sess *session.Session, role, externalId string) *ecr.ECR { if role == "" { return ecr.New(sess) }