From 9ec8b67392a8e458d802d8245ddb1fc9efea7b51 Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Fri, 14 Feb 2020 11:42:29 -0500 Subject: [PATCH] Add golangci-lint to project (#8686) * Add golangci-lint as linting tool * Disable failing staticchecks to start; GitHub issue to handle coming soon * Run `goimports -w` to repair all source files that have improperly formatted imports * makefile: Add ci-lint target to run on travis This change adds a new make target for running golangci-lint on newly added Go files only. This target is expected to run during Packer ci builds. * .github/contributing: Add code linting instructions * travis: Update job configuration to run parallel builds --- .github/CONTRIBUTING.md | 22 ++++ .golangci.yml | 124 ++++++++++++++++++ .travis.yml | 21 +-- Makefile | 23 +++- builder/amazon/chroot/builder.go | 2 +- builder/amazon/chroot/step_mount_device.go | 2 +- builder/amazon/chroot/step_prepare_device.go | 2 +- .../common/interpolate_build_info_test.go | 2 +- .../common/step_modify_ami_attributes.go | 1 + builder/amazon/ebs/builder.go | 1 + builder/amazon/ebssurrogate/builder.go | 1 + builder/amazon/ebssurrogate/builder_test.go | 3 +- builder/amazon/instance/builder.go | 2 +- builder/generated_data_test.go | 3 +- builder/lxc/step_provision.go | 2 +- builder/lxd/step_provision.go | 2 +- builder/osc/chroot/step_chroot_provision.go | 2 +- builder/parallels/common/ssh_config.go | 3 +- builder/parallels/common/ssh_config_test.go | 5 +- builder/qemu/step_http_ip_discover.go | 1 + builder/qemu/step_http_ip_discover_test.go | 3 +- .../vmware/common/step_http_ip_discover.go | 3 +- .../common/step_http_ip_discover_test.go | 3 +- builder/vsphere/clone/builder.go | 1 + builder/vsphere/clone/builder_acc_test.go | 5 +- builder/vsphere/clone/builder_test.go | 3 +- builder/vsphere/clone/step_clone.go | 1 + builder/vsphere/common/step_config_params.go | 1 + builder/vsphere/common/step_connect.go | 1 + builder/vsphere/common/step_hardware.go | 1 + builder/vsphere/common/step_run.go | 3 +- builder/vsphere/common/step_shutdown.go | 5 +- builder/vsphere/common/step_snapshot.go | 1 + builder/vsphere/common/step_template.go | 1 + builder/vsphere/common/step_wait_for_ip.go | 5 +- builder/vsphere/common/testing/utility.go | 7 +- builder/vsphere/driver/datastore.go | 1 + builder/vsphere/driver/driver.go | 5 +- builder/vsphere/driver/folder.go | 1 + builder/vsphere/driver/resource_pool.go | 1 + builder/vsphere/driver/vm.go | 7 +- builder/vsphere/driver/vm_cdrom.go | 1 + builder/vsphere/driver/vm_keyboard.go | 5 +- builder/vsphere/examples/driver/main.go | 1 + builder/vsphere/iso/builder_acc_test.go | 7 +- builder/vsphere/iso/step_add_cdrom.go | 1 + builder/vsphere/iso/step_add_floppy.go | 1 + builder/vsphere/iso/step_boot_command.go | 13 +- builder/vsphere/iso/step_remote_upload.go | 3 +- builder/vsphere/iso/step_remove_cdrom.go | 1 + builder/vsphere/iso/step_remove_floppy.go | 1 + command/build_parallel_test.go | 3 +- common/shell-local/config.go | 1 - ...r_amazon_temporary_security_group_cidrs.go | 3 +- helper/ssh/tunnel_test.go | 3 +- plugin/example/main.go | 2 +- post-processor/vagrant/util.go | 2 +- template/interpolate/i.go | 3 +- 58 files changed, 271 insertions(+), 63 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 33f9c3f64..930ddba4a 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -259,6 +259,28 @@ localized code generation. Say you are working on the Amazon builder: running `go generate ./builder/amazon/...` will do that for you. Make sure that the latest code generation tool is installed by running `make install-gen-deps`. +#### Code linting + +Packer relies on [golangci-lint](https://github.com/golangci/golangci-lint) for linting its Go code base, excluding any generated code created by `go generate`. Linting is executed on new files during Travis builds via `make ci`; the linting of existing code base is only executed when running `make lint`. Linting a large project like Packer is an iterative process so existing code base will have issues that are actively being fixed; pull-requests that fix existing linting issues are always welcomed :smile:. + +The main configuration for golangci-lint is the `.golangci.yml` in the project root. See `golangci-lint --help` for a list of flags that can be used to override the default configuration. + +Run golangci-lint on the entire Packer code base. +``` +make lint +``` + +Run golangci-lint on a single pkg or directory; PKG_NAME expands to /builder/amazon/... +``` +make lint PKG_NAME=builder/amazon +``` + +Note: linting on Travis uses the `--new-from-rev=origin/master` flag to only lint new files added within a branch or pull-request. To run this check locally you can use the `ci-lint` make target. See [golangci-lint in CI](https://github.com/golangci/golangci-lint#faq) for more information. + +``` +make ci-lint +``` + #### Running Unit Tests You can run tests for individual packages using commands like this: diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..a6e07e91f --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,124 @@ +issues: + # List of regexps of issue texts to exclude, empty list by default. + # But independently from this option we use default exclude patterns, + # it can be disabled by `exclude-use-default: false`. To list all + # excluded by default patterns execute `golangci-lint run --help` + + exclude-rules: + # Exclude gosimple bool check + - linters: + - gosimple + text: "S(1002|1008|1021)" + # Exclude failing staticchecks for now + - linters: + - staticcheck + text: "SA(1006|1019|4006|4010|4017|5007|6005|9004):" + # Exclude lll issues for long lines with go:generate + - linters: + - lll + source: "^//go:generate " + + # Maximum issues count per one linter. Set to 0 to disable. Default is 50. + max-issues-per-linter: 0 + + # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. + max-same-issues: 0 + +linters: + disable-all: true + enable: + - deadcode + - errcheck + - goimports + - gosimple + - govet + - ineffassign + - staticcheck + - unconvert + - unused + - varcheck + fast: true + +# options for analysis running +run: + # default concurrency is a available CPU number + concurrency: 4 + + # timeout for analysis, e.g. 30s, 5m, default is 1m + timeout: 10m + + # exit code when at least one issue was found, default is 1 + issues-exit-code: 1 + + # include test files or not, default is true + tests: true + + # list of build tags, all linters use it. Default is empty list. + #build-tags: + # - mytag + + # which dirs to skip: issues from them won't be reported; + # can use regexp here: generated.*, regexp is applied on full path; + # default value is empty list, but default dirs are skipped independently + # from this option's value (see skip-dirs-use-default). + #skip-dirs: + # - src/external_libs + # - autogenerated_by_my_lib + + # default is true. Enables skipping of directories: + # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + skip-dirs-use-default: true + + # which files to skip: they will be analyzed, but issues from them + # won't be reported. Default value is empty list, but there is + # no need to include all autogenerated files, we confidently recognize + # autogenerated files. If it's not please let us know. + skip-files: + - ".*\\.hcl2spec\\.go$" + # - lib/bad.go + + # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": + # If invoked with -mod=readonly, the go command is disallowed from the implicit + # automatic updating of go.mod described above. Instead, it fails when any changes + # to go.mod are needed. This setting is most useful to check that go.mod does + # not need updates, such as in a continuous integration and testing system. + # If invoked with -mod=vendor, the go command assumes that the vendor + # directory holds the correct copies of dependencies and ignores + # the dependency descriptions in go.mod. + modules-download-mode: vendor + + +# output configuration options +output: + # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" + format: colored-line-number + + # print lines of code with issue, default is true + print-issued-lines: true + + # print linter name in the end of issue text, default is true + print-linter-name: true + + # make issues output unique by line, default is true + uniq-by-line: true + + +# all available settings of specific linters +linters-settings: + errcheck: + # report about not checking of errors in type assetions: `a := b.(MyStruct)`; + # default is false: such cases aren't reported by default. + check-type-assertions: false + + # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; + # default is false: such cases aren't reported by default. + check-blank: false + + # [deprecated] comma-separated list of pairs of the form pkg:regex + # the regex is used to ignore names within pkg. (default "fmt:.*"). + # see https://github.com/kisielk/errcheck#the-deprecated-method for details + ignore: fmt:.*,io/ioutil:^Read.*,io:Close + + # path to a file containing a list of functions to exclude from checking + # see https://github.com/kisielk/errcheck#excluding-functions for details + #exclude: /path/to/file.txt diff --git a/.travis.yml b/.travis.yml index 83218bf8b..987dcdc71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,20 +4,21 @@ env: os: - osx -sudo: false - language: go -go: - - 1.13.x - -script: - - df -h - - travis_wait make ci - branches: only: - master -matrix: +jobs: fast_finish: true + include: + - go: "1.13.x" + name: "go test" + script: + - df -h + - travis_wait make ci + - go: "1.13.x" + name: "go lint" + script: travis_wait make ci-lint + diff --git a/Makefile b/Makefile index 888648c25..7a5fd9fb8 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,8 @@ GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) export GOLDFLAGS -.PHONY: bin checkversion ci default install-build-deps install-gen-deps fmt fmt-docs fmt-examples generate releasebin test testacc testrace +.PHONY: bin checkversion ci ci-lint default install-build-deps install-gen-deps fmt fmt-docs fmt-examples generate install-lint-deps lint \ + releasebin test testacc testrace default: install-build-deps install-gen-deps generate testrace dev releasebin package dev fmt fmt-check mode-check fmt-docs fmt-examples @@ -49,12 +50,16 @@ install-gen-deps: ## Install dependencies for code generation # dir. `go get` will change our deps and the following deps are not part of # out code dependencies; so a go mod tidy will remove them again. `go # install` seems to install the last tagged version and we want to install - # master. + # master. @(cd $(TEMPDIR) && GO111MODULE=on go get github.com/mna/pigeon@master) @(cd $(TEMPDIR) && GO111MODULE=on go get github.com/alvaroloes/enumer@master) @go install ./cmd/struct-markdown @go install ./cmd/mapstructure-to-hcl2 +install-lint-deps: ## Install linter dependencies + @echo "==> Updating linter dependencies..." + @curl -sSfL -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.23.1 + dev: ## Build and install a development build @grep 'const VersionPrerelease = ""' version/version.go > /dev/null ; if [ $$? -eq 0 ]; then \ echo "ERROR: You must add prerelease tags to version/version.go prior to making a dev build."; \ @@ -66,6 +71,20 @@ dev: ## Build and install a development build @cp $(GOPATH)/bin/packer bin/packer @cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH) +lint: install-lint-deps ## Lint Go code + @if [ ! -z $(PKG_NAME) ]; then \ + echo "golangci-lint run ./$(PKG_NAME)/..."; \ + golangci-lint run ./$(PKG_NAME)/...; \ + else \ + echo "golangci-lint run"; \ + golangci-lint run; \ + fi + +ci-lint: install-lint-deps ## On ci only lint newly added Go source files + @echo "==> Running linter on newly added Go source files..." + GO111MODULE=on golangci-lint run --new-from-rev=origin/master + + fmt: ## Format Go code @go fmt ./... diff --git a/builder/amazon/chroot/builder.go b/builder/amazon/chroot/builder.go index 7b1fd70b9..ed60b5e95 100644 --- a/builder/amazon/chroot/builder.go +++ b/builder/amazon/chroot/builder.go @@ -10,11 +10,11 @@ package chroot import ( "context" "errors" - "github.com/hashicorp/packer/builder" "runtime" "github.com/aws/aws-sdk-go/service/ec2" "github.com/hashicorp/hcl/v2/hcldec" + "github.com/hashicorp/packer/builder" awscommon "github.com/hashicorp/packer/builder/amazon/common" "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/common/chroot" diff --git a/builder/amazon/chroot/step_mount_device.go b/builder/amazon/chroot/step_mount_device.go index 262789620..dffd35854 100644 --- a/builder/amazon/chroot/step_mount_device.go +++ b/builder/amazon/chroot/step_mount_device.go @@ -4,13 +4,13 @@ import ( "bytes" "context" "fmt" - "github.com/hashicorp/packer/builder" "log" "os" "path/filepath" "strings" "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/packer/builder" "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" diff --git a/builder/amazon/chroot/step_prepare_device.go b/builder/amazon/chroot/step_prepare_device.go index cbc40d0f6..098d83858 100644 --- a/builder/amazon/chroot/step_prepare_device.go +++ b/builder/amazon/chroot/step_prepare_device.go @@ -3,10 +3,10 @@ package chroot import ( "context" "fmt" - "github.com/hashicorp/packer/builder" "log" "os" + "github.com/hashicorp/packer/builder" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) diff --git a/builder/amazon/common/interpolate_build_info_test.go b/builder/amazon/common/interpolate_build_info_test.go index 7f72f82ea..e85e167d6 100644 --- a/builder/amazon/common/interpolate_build_info_test.go +++ b/builder/amazon/common/interpolate_build_info_test.go @@ -1,12 +1,12 @@ package common import ( - "github.com/hashicorp/packer/builder" "reflect" "testing" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/packer/builder" "github.com/hashicorp/packer/helper/multistep" ) diff --git a/builder/amazon/common/step_modify_ami_attributes.go b/builder/amazon/common/step_modify_ami_attributes.go index ba34037af..057650a51 100644 --- a/builder/amazon/common/step_modify_ami_attributes.go +++ b/builder/amazon/common/step_modify_ami_attributes.go @@ -3,6 +3,7 @@ package common import ( "context" "fmt" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index a76454616..6d3e7f89a 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -11,6 +11,7 @@ package ebs import ( "context" "fmt" + "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/iam" "github.com/hashicorp/hcl/v2/hcldec" diff --git a/builder/amazon/ebssurrogate/builder.go b/builder/amazon/ebssurrogate/builder.go index 6007d3fa8..1a94b7c28 100644 --- a/builder/amazon/ebssurrogate/builder.go +++ b/builder/amazon/ebssurrogate/builder.go @@ -9,6 +9,7 @@ import ( "context" "errors" "fmt" + "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/iam" "github.com/hashicorp/hcl/v2/hcldec" diff --git a/builder/amazon/ebssurrogate/builder_test.go b/builder/amazon/ebssurrogate/builder_test.go index 9f914de28..663ea422c 100644 --- a/builder/amazon/ebssurrogate/builder_test.go +++ b/builder/amazon/ebssurrogate/builder_test.go @@ -1,9 +1,10 @@ package ebssurrogate import ( - "github.com/hashicorp/packer/builder/amazon/common" "testing" + "github.com/hashicorp/packer/builder/amazon/common" + "github.com/hashicorp/packer/packer" ) diff --git a/builder/amazon/instance/builder.go b/builder/amazon/instance/builder.go index 9fc9d3d30..763960150 100644 --- a/builder/amazon/instance/builder.go +++ b/builder/amazon/instance/builder.go @@ -9,13 +9,13 @@ import ( "context" "errors" "fmt" - "github.com/hashicorp/packer/builder" "os" "strings" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/iam" "github.com/hashicorp/hcl/v2/hcldec" + "github.com/hashicorp/packer/builder" awscommon "github.com/hashicorp/packer/builder/amazon/common" "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/communicator" diff --git a/builder/generated_data_test.go b/builder/generated_data_test.go index 998569237..09f673cc1 100644 --- a/builder/generated_data_test.go +++ b/builder/generated_data_test.go @@ -1,8 +1,9 @@ package builder import ( - "github.com/hashicorp/packer/helper/multistep" "testing" + + "github.com/hashicorp/packer/helper/multistep" ) func TestGeneratedData_Put(t *testing.T) { diff --git a/builder/lxc/step_provision.go b/builder/lxc/step_provision.go index e1ba2874d..fe9f3264b 100644 --- a/builder/lxc/step_provision.go +++ b/builder/lxc/step_provision.go @@ -2,9 +2,9 @@ package lxc import ( "context" - "github.com/hashicorp/packer/common" "log" + "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) diff --git a/builder/lxd/step_provision.go b/builder/lxd/step_provision.go index ec6da8a22..79f43b21a 100644 --- a/builder/lxd/step_provision.go +++ b/builder/lxd/step_provision.go @@ -2,9 +2,9 @@ package lxd import ( "context" - "github.com/hashicorp/packer/common" "log" + "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) diff --git a/builder/osc/chroot/step_chroot_provision.go b/builder/osc/chroot/step_chroot_provision.go index 25afd6edd..e621f2fb6 100644 --- a/builder/osc/chroot/step_chroot_provision.go +++ b/builder/osc/chroot/step_chroot_provision.go @@ -2,9 +2,9 @@ package chroot import ( "context" - "github.com/hashicorp/packer/common" "log" + "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) diff --git a/builder/parallels/common/ssh_config.go b/builder/parallels/common/ssh_config.go index c8b4d35f0..0c75be360 100644 --- a/builder/parallels/common/ssh_config.go +++ b/builder/parallels/common/ssh_config.go @@ -1,9 +1,10 @@ package common import ( + "time" + "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/template/interpolate" - "time" ) // SSHConfig contains the configuration for SSH communicator. diff --git a/builder/parallels/common/ssh_config_test.go b/builder/parallels/common/ssh_config_test.go index f49cafb97..f5adb0bd9 100644 --- a/builder/parallels/common/ssh_config_test.go +++ b/builder/parallels/common/ssh_config_test.go @@ -1,12 +1,13 @@ package common import ( - "github.com/hashicorp/packer/helper/communicator" - "github.com/hashicorp/packer/template/interpolate" "io/ioutil" "os" "testing" "time" + + "github.com/hashicorp/packer/helper/communicator" + "github.com/hashicorp/packer/template/interpolate" ) func testSSHConfig() *SSHConfig { diff --git a/builder/qemu/step_http_ip_discover.go b/builder/qemu/step_http_ip_discover.go index d8cbb2250..a20fb4886 100644 --- a/builder/qemu/step_http_ip_discover.go +++ b/builder/qemu/step_http_ip_discover.go @@ -2,6 +2,7 @@ package qemu import ( "context" + "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" ) diff --git a/builder/qemu/step_http_ip_discover_test.go b/builder/qemu/step_http_ip_discover_test.go index 9ee510b17..32c737ef7 100644 --- a/builder/qemu/step_http_ip_discover_test.go +++ b/builder/qemu/step_http_ip_discover_test.go @@ -2,9 +2,10 @@ package qemu import ( "context" + "testing" + "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" - "testing" ) func TestStepHTTPIPDiscover_Run(t *testing.T) { diff --git a/builder/vmware/common/step_http_ip_discover.go b/builder/vmware/common/step_http_ip_discover.go index 8d813480f..8a192a62c 100644 --- a/builder/vmware/common/step_http_ip_discover.go +++ b/builder/vmware/common/step_http_ip_discover.go @@ -3,10 +3,11 @@ package common import ( "context" "fmt" + "log" + "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" - "log" ) // Step to discover the http ip diff --git a/builder/vmware/common/step_http_ip_discover_test.go b/builder/vmware/common/step_http_ip_discover_test.go index 724da984b..ee147b8a2 100644 --- a/builder/vmware/common/step_http_ip_discover_test.go +++ b/builder/vmware/common/step_http_ip_discover_test.go @@ -3,9 +3,10 @@ package common import ( "context" "errors" + "testing" + "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" - "testing" ) func TestStepHTTPIPDiscover_Run(t *testing.T) { diff --git a/builder/vsphere/clone/builder.go b/builder/vsphere/clone/builder.go index bb3f9c574..a74bb4559 100644 --- a/builder/vsphere/clone/builder.go +++ b/builder/vsphere/clone/builder.go @@ -2,6 +2,7 @@ package clone import ( "context" + "github.com/hashicorp/hcl/v2/hcldec" "github.com/hashicorp/packer/builder/vsphere/common" "github.com/hashicorp/packer/builder/vsphere/driver" diff --git a/builder/vsphere/clone/builder_acc_test.go b/builder/vsphere/clone/builder_acc_test.go index ec988ed83..22bb345ab 100644 --- a/builder/vsphere/clone/builder_acc_test.go +++ b/builder/vsphere/clone/builder_acc_test.go @@ -1,13 +1,14 @@ package clone import ( + "os" + "testing" + "github.com/hashicorp/packer/builder/vsphere/common" commonT "github.com/hashicorp/packer/builder/vsphere/common/testing" builderT "github.com/hashicorp/packer/helper/builder/testing" "github.com/hashicorp/packer/packer" "github.com/vmware/govmomi/vim25/types" - "os" - "testing" ) func TestCloneBuilderAcc_default(t *testing.T) { diff --git a/builder/vsphere/clone/builder_test.go b/builder/vsphere/clone/builder_test.go index 788e0e245..5f57eb7ad 100644 --- a/builder/vsphere/clone/builder_test.go +++ b/builder/vsphere/clone/builder_test.go @@ -1,8 +1,9 @@ package clone import ( - "github.com/hashicorp/packer/packer" "testing" + + "github.com/hashicorp/packer/packer" ) func TestCloneBuilder_ImplementsBuilder(t *testing.T) { diff --git a/builder/vsphere/clone/step_clone.go b/builder/vsphere/clone/step_clone.go index 3c7ffb0c3..22c3059c7 100644 --- a/builder/vsphere/clone/step_clone.go +++ b/builder/vsphere/clone/step_clone.go @@ -6,6 +6,7 @@ package clone import ( "context" "fmt" + "github.com/hashicorp/packer/builder/vsphere/common" "github.com/hashicorp/packer/builder/vsphere/driver" "github.com/hashicorp/packer/helper/multistep" diff --git a/builder/vsphere/common/step_config_params.go b/builder/vsphere/common/step_config_params.go index ba81194da..65aa91789 100644 --- a/builder/vsphere/common/step_config_params.go +++ b/builder/vsphere/common/step_config_params.go @@ -6,6 +6,7 @@ package common import ( "context" "fmt" + "github.com/hashicorp/packer/builder/vsphere/driver" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" diff --git a/builder/vsphere/common/step_connect.go b/builder/vsphere/common/step_connect.go index 85136a8d4..b651eda06 100644 --- a/builder/vsphere/common/step_connect.go +++ b/builder/vsphere/common/step_connect.go @@ -6,6 +6,7 @@ package common import ( "context" "fmt" + "github.com/hashicorp/packer/builder/vsphere/driver" "github.com/hashicorp/packer/helper/multistep" ) diff --git a/builder/vsphere/common/step_hardware.go b/builder/vsphere/common/step_hardware.go index 20d67d080..e7025208a 100644 --- a/builder/vsphere/common/step_hardware.go +++ b/builder/vsphere/common/step_hardware.go @@ -6,6 +6,7 @@ package common import ( "context" "fmt" + "github.com/hashicorp/packer/builder/vsphere/driver" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" diff --git a/builder/vsphere/common/step_run.go b/builder/vsphere/common/step_run.go index 34fcc0c77..e18c4ee4a 100644 --- a/builder/vsphere/common/step_run.go +++ b/builder/vsphere/common/step_run.go @@ -5,10 +5,11 @@ package common import ( "context" + "strings" + "github.com/hashicorp/packer/builder/vsphere/driver" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" - "strings" ) type RunConfig struct { diff --git a/builder/vsphere/common/step_shutdown.go b/builder/vsphere/common/step_shutdown.go index c2124e84d..98142d421 100644 --- a/builder/vsphere/common/step_shutdown.go +++ b/builder/vsphere/common/step_shutdown.go @@ -7,11 +7,12 @@ import ( "bytes" "context" "fmt" + "log" + "time" + "github.com/hashicorp/packer/builder/vsphere/driver" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" - "log" - "time" ) type ShutdownConfig struct { diff --git a/builder/vsphere/common/step_snapshot.go b/builder/vsphere/common/step_snapshot.go index 4f7cd7604..c577cf035 100644 --- a/builder/vsphere/common/step_snapshot.go +++ b/builder/vsphere/common/step_snapshot.go @@ -2,6 +2,7 @@ package common import ( "context" + "github.com/hashicorp/packer/builder/vsphere/driver" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" diff --git a/builder/vsphere/common/step_template.go b/builder/vsphere/common/step_template.go index 42a2573e1..fad2b9470 100644 --- a/builder/vsphere/common/step_template.go +++ b/builder/vsphere/common/step_template.go @@ -2,6 +2,7 @@ package common import ( "context" + "github.com/hashicorp/packer/builder/vsphere/driver" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" diff --git a/builder/vsphere/common/step_wait_for_ip.go b/builder/vsphere/common/step_wait_for_ip.go index 51593b1f2..d5f0db772 100644 --- a/builder/vsphere/common/step_wait_for_ip.go +++ b/builder/vsphere/common/step_wait_for_ip.go @@ -6,11 +6,12 @@ package common import ( "context" "fmt" + "log" + "time" + "github.com/hashicorp/packer/builder/vsphere/driver" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" - "log" - "time" ) type WaitIpConfig struct { diff --git a/builder/vsphere/common/testing/utility.go b/builder/vsphere/common/testing/utility.go index 22a0d2e86..af10c4b10 100644 --- a/builder/vsphere/common/testing/utility.go +++ b/builder/vsphere/common/testing/utility.go @@ -3,13 +3,14 @@ package testing import ( "encoding/json" "fmt" - "github.com/hashicorp/packer/builder/vsphere/common" - "github.com/hashicorp/packer/builder/vsphere/driver" - "github.com/hashicorp/packer/packer" "math/rand" "os" "testing" "time" + + "github.com/hashicorp/packer/builder/vsphere/common" + "github.com/hashicorp/packer/builder/vsphere/driver" + "github.com/hashicorp/packer/packer" ) func NewVMName() string { diff --git a/builder/vsphere/driver/datastore.go b/builder/vsphere/driver/datastore.go index e553e9c3c..6a87f9a36 100644 --- a/builder/vsphere/driver/datastore.go +++ b/builder/vsphere/driver/datastore.go @@ -2,6 +2,7 @@ package driver import ( "fmt" + "github.com/vmware/govmomi/object" "github.com/vmware/govmomi/vim25/mo" "github.com/vmware/govmomi/vim25/soap" diff --git a/builder/vsphere/driver/driver.go b/builder/vsphere/driver/driver.go index e93fbe47b..8c8cca5bd 100644 --- a/builder/vsphere/driver/driver.go +++ b/builder/vsphere/driver/driver.go @@ -3,14 +3,15 @@ package driver import ( "context" "fmt" + "net/url" + "time" + "github.com/vmware/govmomi" "github.com/vmware/govmomi/find" "github.com/vmware/govmomi/object" "github.com/vmware/govmomi/session" "github.com/vmware/govmomi/vim25" "github.com/vmware/govmomi/vim25/soap" - "net/url" - "time" ) type Driver struct { diff --git a/builder/vsphere/driver/folder.go b/builder/vsphere/driver/folder.go index 7fdf40ed1..6349a0e04 100644 --- a/builder/vsphere/driver/folder.go +++ b/builder/vsphere/driver/folder.go @@ -2,6 +2,7 @@ package driver import ( "fmt" + "github.com/vmware/govmomi/object" "github.com/vmware/govmomi/vim25/mo" "github.com/vmware/govmomi/vim25/types" diff --git a/builder/vsphere/driver/resource_pool.go b/builder/vsphere/driver/resource_pool.go index 001e836d7..c81f1c23f 100644 --- a/builder/vsphere/driver/resource_pool.go +++ b/builder/vsphere/driver/resource_pool.go @@ -2,6 +2,7 @@ package driver import ( "fmt" + "github.com/vmware/govmomi/object" "github.com/vmware/govmomi/vim25/mo" "github.com/vmware/govmomi/vim25/types" diff --git a/builder/vsphere/driver/vm.go b/builder/vsphere/driver/vm.go index d177b20ba..06edbdfbd 100644 --- a/builder/vsphere/driver/vm.go +++ b/builder/vsphere/driver/vm.go @@ -4,12 +4,13 @@ import ( "context" "errors" "fmt" - "github.com/vmware/govmomi/object" - "github.com/vmware/govmomi/vim25/mo" - "github.com/vmware/govmomi/vim25/types" "log" "strings" "time" + + "github.com/vmware/govmomi/object" + "github.com/vmware/govmomi/vim25/mo" + "github.com/vmware/govmomi/vim25/types" ) type VirtualMachine struct { diff --git a/builder/vsphere/driver/vm_cdrom.go b/builder/vsphere/driver/vm_cdrom.go index d33b75829..264e87d10 100644 --- a/builder/vsphere/driver/vm_cdrom.go +++ b/builder/vsphere/driver/vm_cdrom.go @@ -2,6 +2,7 @@ package driver import ( "errors" + "github.com/vmware/govmomi/vim25/types" ) diff --git a/builder/vsphere/driver/vm_keyboard.go b/builder/vsphere/driver/vm_keyboard.go index 481639fc1..616ec958c 100644 --- a/builder/vsphere/driver/vm_keyboard.go +++ b/builder/vsphere/driver/vm_keyboard.go @@ -1,11 +1,12 @@ package driver import ( + "strings" + "unicode" + "github.com/vmware/govmomi/vim25/methods" "github.com/vmware/govmomi/vim25/types" "golang.org/x/mobile/event/key" - "strings" - "unicode" ) type KeyInput struct { diff --git a/builder/vsphere/examples/driver/main.go b/builder/vsphere/examples/driver/main.go index 486304158..3f0235e9e 100644 --- a/builder/vsphere/examples/driver/main.go +++ b/builder/vsphere/examples/driver/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/hashicorp/packer/builder/vsphere/driver" ) diff --git a/builder/vsphere/iso/builder_acc_test.go b/builder/vsphere/iso/builder_acc_test.go index 0857d53ec..56de2818d 100644 --- a/builder/vsphere/iso/builder_acc_test.go +++ b/builder/vsphere/iso/builder_acc_test.go @@ -2,13 +2,14 @@ package iso import ( "fmt" + "io/ioutil" + "os" + "testing" + commonT "github.com/hashicorp/packer/builder/vsphere/common/testing" builderT "github.com/hashicorp/packer/helper/builder/testing" "github.com/hashicorp/packer/packer" "github.com/vmware/govmomi/vim25/types" - "io/ioutil" - "os" - "testing" ) func TestISOBuilderAcc_default(t *testing.T) { diff --git a/builder/vsphere/iso/step_add_cdrom.go b/builder/vsphere/iso/step_add_cdrom.go index f5742c0f8..068d9ce4c 100644 --- a/builder/vsphere/iso/step_add_cdrom.go +++ b/builder/vsphere/iso/step_add_cdrom.go @@ -6,6 +6,7 @@ package iso import ( "context" "fmt" + "github.com/hashicorp/packer/builder/vsphere/driver" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" diff --git a/builder/vsphere/iso/step_add_floppy.go b/builder/vsphere/iso/step_add_floppy.go index 51e987a63..caefff19d 100644 --- a/builder/vsphere/iso/step_add_floppy.go +++ b/builder/vsphere/iso/step_add_floppy.go @@ -6,6 +6,7 @@ package iso import ( "context" "fmt" + "github.com/hashicorp/packer/builder/vsphere/driver" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" diff --git a/builder/vsphere/iso/step_boot_command.go b/builder/vsphere/iso/step_boot_command.go index cb1154fbd..316325814 100644 --- a/builder/vsphere/iso/step_boot_command.go +++ b/builder/vsphere/iso/step_boot_command.go @@ -3,18 +3,19 @@ package iso import ( "context" "fmt" - "github.com/hashicorp/packer/builder/vsphere/driver" - packerCommon "github.com/hashicorp/packer/common" - "github.com/hashicorp/packer/helper/multistep" - "github.com/hashicorp/packer/packer" - "github.com/hashicorp/packer/template/interpolate" - "golang.org/x/mobile/event/key" "log" "net" "os" "strings" "time" "unicode/utf8" + + "github.com/hashicorp/packer/builder/vsphere/driver" + packerCommon "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/helper/multistep" + "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/template/interpolate" + "golang.org/x/mobile/event/key" ) type BootConfig struct { diff --git a/builder/vsphere/iso/step_remote_upload.go b/builder/vsphere/iso/step_remote_upload.go index ac395a66b..9eca285dc 100644 --- a/builder/vsphere/iso/step_remote_upload.go +++ b/builder/vsphere/iso/step_remote_upload.go @@ -3,10 +3,11 @@ package iso import ( "context" "fmt" + "path/filepath" + "github.com/hashicorp/packer/builder/vsphere/driver" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" - "path/filepath" ) type StepRemoteUpload struct { diff --git a/builder/vsphere/iso/step_remove_cdrom.go b/builder/vsphere/iso/step_remove_cdrom.go index 508676575..de943e675 100644 --- a/builder/vsphere/iso/step_remove_cdrom.go +++ b/builder/vsphere/iso/step_remove_cdrom.go @@ -5,6 +5,7 @@ package iso import ( "context" + "github.com/hashicorp/packer/builder/vsphere/driver" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" diff --git a/builder/vsphere/iso/step_remove_floppy.go b/builder/vsphere/iso/step_remove_floppy.go index 3844b8063..221ff9659 100644 --- a/builder/vsphere/iso/step_remove_floppy.go +++ b/builder/vsphere/iso/step_remove_floppy.go @@ -2,6 +2,7 @@ package iso import ( "context" + "github.com/hashicorp/packer/builder/vsphere/driver" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" diff --git a/command/build_parallel_test.go b/command/build_parallel_test.go index b6e4ceb8c..d4802de43 100644 --- a/command/build_parallel_test.go +++ b/command/build_parallel_test.go @@ -4,11 +4,12 @@ import ( "bytes" "context" "fmt" - "github.com/hashicorp/hcl/v2/hcldec" "path/filepath" "sync" "testing" + "github.com/hashicorp/hcl/v2/hcldec" + "golang.org/x/sync/errgroup" "github.com/hashicorp/packer/builder/file" diff --git a/common/shell-local/config.go b/common/shell-local/config.go index 37c2605f8..cc819ae30 100644 --- a/common/shell-local/config.go +++ b/common/shell-local/config.go @@ -5,7 +5,6 @@ package shell_local import ( "errors" "fmt" - // "log" "os" "path/filepath" "runtime" diff --git a/fix/fixer_amazon_temporary_security_group_cidrs.go b/fix/fixer_amazon_temporary_security_group_cidrs.go index c48a28011..0a420aecb 100644 --- a/fix/fixer_amazon_temporary_security_group_cidrs.go +++ b/fix/fixer_amazon_temporary_security_group_cidrs.go @@ -1,8 +1,9 @@ package fix import ( - "github.com/mitchellh/mapstructure" "strings" + + "github.com/mitchellh/mapstructure" ) type FixerAmazonTemporarySecurityCIDRs struct{} diff --git a/helper/ssh/tunnel_test.go b/helper/ssh/tunnel_test.go index 79c015e84..447a71ef3 100644 --- a/helper/ssh/tunnel_test.go +++ b/helper/ssh/tunnel_test.go @@ -1,8 +1,9 @@ package ssh import ( - "github.com/hashicorp/packer/communicator/ssh" "testing" + + "github.com/hashicorp/packer/communicator/ssh" ) const ( diff --git a/plugin/example/main.go b/plugin/example/main.go index 7f4edf6c4..416728260 100644 --- a/plugin/example/main.go +++ b/plugin/example/main.go @@ -17,7 +17,7 @@ package main import ( "github.com/hashicorp/packer/builder/amazon/chroot" "github.com/hashicorp/packer/packer/plugin" - "github.com/hashicorp/packer/post-processor/docker-push" + dockerpush "github.com/hashicorp/packer/post-processor/docker-push" "github.com/hashicorp/packer/provisioner/powershell" ) diff --git a/post-processor/vagrant/util.go b/post-processor/vagrant/util.go index 476136122..21f3398eb 100644 --- a/post-processor/vagrant/util.go +++ b/post-processor/vagrant/util.go @@ -5,7 +5,6 @@ import ( "compress/flate" "encoding/json" "fmt" - "github.com/hashicorp/packer/packer/tmp" "io" "log" "os" @@ -13,6 +12,7 @@ import ( "runtime" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" "github.com/klauspost/pgzip" ) diff --git a/template/interpolate/i.go b/template/interpolate/i.go index 54d1e516e..852f7f116 100644 --- a/template/interpolate/i.go +++ b/template/interpolate/i.go @@ -2,10 +2,11 @@ package interpolate import ( "bytes" - "github.com/google/uuid" "regexp" "strings" "text/template" + + "github.com/google/uuid" ) // Context is the context that an interpolation is done in. This defines