diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 4a74d6e0c..dbd387fa0 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -18,30 +18,47 @@ permissions: contents: read jobs: + get-go-version: + runs-on: ubuntu-latest + outputs: + go-version: ${{ steps.get-go-version.outputs.go-version }} + steps: + - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0 + - name: 'Determine Go version' + id: get-go-version + run: | + echo "Found Go $(cat .go-version)" + echo "go-version=$(cat .go-version)" >> $GITHUB_OUTPUT linux-go-tests: + needs: + - get-go-version runs-on: ubuntu-latest name: Linux go tests steps: - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 with: - go-version: '1.18' + go-version: ${{ needs.get-go-version.outputs.go-version }} - run: TESTARGS="-coverprofile=coverage.txt -covermode=atomic" make ci darwin-go-tests: + needs: + - get-go-version runs-on: macos-latest name: Darwin go tests steps: - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 with: - go-version: '1.18' + go-version: ${{ needs.get-go-version.outputs.go-version }} - run: go test ./... -coverprofile=coverage.txt -covermode=atomic windows-go-tests: + needs: + - get-go-version runs-on: windows-latest name: Windows go tests steps: - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 with: - go-version: '1.18' + go-version: ${{ needs.get-go-version.outputs.go-version }} - run: go test ./... -coverprofile=coverage.txt -covermode=atomic diff --git a/.github/workflows/go-validate.yml b/.github/workflows/go-validate.yml index ae87a6da7..c3aa5408b 100644 --- a/.github/workflows/go-validate.yml +++ b/.github/workflows/go-validate.yml @@ -14,16 +14,31 @@ permissions: contents: read jobs: + get-go-version: + runs-on: ubuntu-latest + outputs: + go-version: ${{ steps.get-go-version.outputs.go-version }} + steps: + - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0 + - name: 'Determine Go version' + id: get-go-version + run: | + echo "Found Go $(cat .go-version)" + echo "go-version=$(cat .go-version)" >> $GITHUB_OUTPUT check-mod-tidy: + needs: + - get-go-version runs-on: ubuntu-latest name: Go Mod Tidy steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 + - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0 - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 with: - go-version: '1.18' + go-version: ${{ needs.get-go-version.outputs.go-version }} - run: go mod tidy check-lint: + needs: + - get-go-version runs-on: ubuntu-latest name: Lint steps: @@ -32,26 +47,30 @@ jobs: fetch-depth: 0 - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 with: - go-version: '1.18' + go-version: ${{ needs.get-go-version.outputs.go-version }} - run: echo "$GITHUB_SHA" - run: git fetch --all - run: echo $(git merge-base origin/main $GITHUB_SHA) - run: make ci-lint check-fmt: + needs: + - get-go-version runs-on: ubuntu-latest name: Fmt check steps: - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 with: - go-version: '1.18' + go-version: ${{ needs.get-go-version.outputs.go-version }} - run: make fmt-check check-generate: + needs: + - get-go-version runs-on: ubuntu-latest name: Generate check steps: - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 with: - go-version: '1.18' + go-version: ${{ needs.get-go-version.outputs.go-version }} - run: make generate-check diff --git a/.go-version b/.go-version index cafc0b7ad..f5b00dc26 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.18.9 +1.20.3 diff --git a/Makefile b/Makefile index 13102b044..ad6cfd3a2 100644 --- a/Makefile +++ b/Makefile @@ -57,7 +57,7 @@ install-gen-deps: ## Install dependencies for code generation 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.46.0 + @curl -sSfL -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.52.0 dev: ## Build and install a development build @grep 'const VersionPrerelease = ""' version/version.go > /dev/null ; if [ $$? -eq 0 ]; then \ diff --git a/command/build_cancellation_test.go b/command/build_cancellation_test.go index 809fd53bf..348b1d918 100644 --- a/command/build_cancellation_test.go +++ b/command/build_cancellation_test.go @@ -53,6 +53,7 @@ func TestBuildCommand_RunContext_CtxCancel(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() b := NewParallelTestBuilder(tt.parallelPassingTests) diff --git a/command/configtype_enumer.go b/command/configtype_enumer.go index 5d02f0358..c7a5cf52a 100644 --- a/command/configtype_enumer.go +++ b/command/configtype_enumer.go @@ -1,6 +1,5 @@ // Code generated by "enumer -type configType -trimprefix ConfigType -transform snake"; DO NOT EDIT. -// package command import ( diff --git a/config_test.go b/config_test.go index b744a274b..772fea4fe 100644 --- a/config_test.go +++ b/config_test.go @@ -188,7 +188,9 @@ func generateFakePlugins(dirname string, pluginNames []string) (string, []string return dir, plugins, cleanUpFunc, nil } -/* generateFakePackerConfigData creates a collection of mock plugins along with a basic packerconfig. +/* + generateFakePackerConfigData creates a collection of mock plugins along with a basic packerconfig. + The return packerConfigData is a valid packerconfig file that can be used for configuring external plugins, cleanUpFunc is a function that should be called for cleaning up any generated mock data. This function will only clean up if there is an error, on successful runs the caller is responsible for cleaning up the data via cleanUpFunc(). diff --git a/go.mod b/go.mod index d1e0e8dcb..915aadccb 100644 --- a/go.mod +++ b/go.mod @@ -250,4 +250,4 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -go 1.18 +go 1.20 diff --git a/hcl2template/addrs/plugin.go b/hcl2template/addrs/plugin.go index 8c4c3485d..8b4891044 100644 --- a/hcl2template/addrs/plugin.go +++ b/hcl2template/addrs/plugin.go @@ -97,9 +97,10 @@ func IsPluginPartNormalized(str string) (bool, error) { // This is intended primarily to parse the FQN-like strings // // The following are valid source string formats: -// name -// namespace/name -// hostname/namespace/name +// +// name +// namespace/name +// hostname/namespace/name func ParsePluginSourceString(str string) (*Plugin, hcl.Diagnostics) { ret := &Plugin{ Hostname: "", diff --git a/hcl2template/docs.go b/hcl2template/docs.go index d1ad307cc..2b19f42b0 100644 --- a/hcl2template/docs.go +++ b/hcl2template/docs.go @@ -7,5 +7,4 @@ // // Checkout the files in testdata/complete/ to see what a packer config could // look like. -// package hcl2template diff --git a/hcl2template/functions.go b/hcl2template/functions.go index 5876acb0d..cc144940c 100644 --- a/hcl2template/functions.go +++ b/hcl2template/functions.go @@ -27,7 +27,6 @@ import ( // basedir is used with file functions and allows a user to reference a file // using local path. Usually basedir is the directory in which the config file // is located -// func Functions(basedir string) map[string]function.Function { funcs := map[string]function.Function{ diff --git a/hcl2template/types.source.go b/hcl2template/types.source.go index 49b0316f6..1ea939d01 100644 --- a/hcl2template/types.source.go +++ b/hcl2template/types.source.go @@ -67,11 +67,12 @@ func (b *SourceUseBlock) ctyValues() map[string]cty.Value { } // decodeBuildSource reads a used source block from a build: -// build { -// source "type.example" { -// name = "local_name" -// } -// } +// +// build { +// source "type.example" { +// name = "local_name" +// } +// } func (p *Parser) decodeBuildSource(block *hcl.Block) (SourceUseBlock, hcl.Diagnostics) { ref := sourceRefFromString(block.Labels[0]) out := SourceUseBlock{SourceRef: ref} diff --git a/internal/hcp/api/mock_service.go b/internal/hcp/api/mock_service.go index 9bd8e706e..9a126346e 100644 --- a/internal/hcp/api/mock_service.go +++ b/internal/hcp/api/mock_service.go @@ -16,9 +16,9 @@ import ( "google.golang.org/grpc/status" ) -//MockPackerClientService represents a basic mock of the Cloud Packer Service. -//Upon calling a service method a boolean is set to true to indicate that a method has been called. -//To skip the setting of these booleans set TrackCalledServiceMethods to false; defaults to true in NewMockPackerClientService(). +// MockPackerClientService represents a basic mock of the Cloud Packer Service. +// Upon calling a service method a boolean is set to true to indicate that a method has been called. +// To skip the setting of these booleans set TrackCalledServiceMethods to false; defaults to true in NewMockPackerClientService(). type MockPackerClientService struct { CreateBucketCalled, UpdateBucketCalled, BucketAlreadyExist bool CreateIterationCalled, GetIterationCalled, IterationAlreadyExist, IterationCompleted bool @@ -39,9 +39,9 @@ type MockPackerClientService struct { packerSvc.ClientService } -//NewMockPackerClientService returns a basic mock of the Cloud Packer Service. -//Upon calling a service method a boolean is set to true to indicate that a method has been called. -//To skip the setting of these booleans set TrackCalledServiceMethods to false. By default it is true. +// NewMockPackerClientService returns a basic mock of the Cloud Packer Service. +// Upon calling a service method a boolean is set to true to indicate that a method has been called. +// To skip the setting of these booleans set TrackCalledServiceMethods to false. By default it is true. func NewMockPackerClientService() *MockPackerClientService { m := MockPackerClientService{ ExistingBuilds: make([]string, 0), diff --git a/internal/hcp/registry/types.iterations.go b/internal/hcp/registry/types.iterations.go index 8997491c2..b9ffc2322 100644 --- a/internal/hcp/registry/types.iterations.go +++ b/internal/hcp/registry/types.iterations.go @@ -64,12 +64,12 @@ func (i *Iteration) Initialize() error { return nil } -//StoreBuild stores a build for buildName to an active iteration. +// StoreBuild stores a build for buildName to an active iteration. func (i *Iteration) StoreBuild(buildName string, build *Build) { i.builds.Store(buildName, build) } -//Build gets the store build associated with buildName in the active iteration. +// Build gets the store build associated with buildName in the active iteration. func (i *Iteration) Build(buildName string) (*Build, error) { build, ok := i.builds.Load(buildName) if !ok { @@ -84,7 +84,7 @@ func (i *Iteration) Build(buildName string) (*Build, error) { return b, nil } -//HasBuild checks if iteration has a stored build associated with buildName. +// HasBuild checks if iteration has a stored build associated with buildName. func (i *Iteration) HasBuild(buildName string) bool { _, ok := i.builds.Load(buildName) diff --git a/packer/fixconfigmode_enumer.go b/packer/fixconfigmode_enumer.go index 82b09a633..715fa73f5 100644 --- a/packer/fixconfigmode_enumer.go +++ b/packer/fixconfigmode_enumer.go @@ -1,6 +1,5 @@ // Code generated by "enumer -type FixConfigMode"; DO NOT EDIT. -// package packer import ( diff --git a/packer/plugin-getter/plugins.go b/packer/plugin-getter/plugins.go index 2ef5d80f9..09acf7052 100644 --- a/packer/plugin-getter/plugins.go +++ b/packer/plugin-getter/plugins.go @@ -386,8 +386,8 @@ func (e ChecksumFileEntry) Os() string { return e.os } func (e ChecksumFileEntry) Arch() string { return e.arch } // a file inside will look like so: -// packer-plugin-comment_v0.2.12_x5.0_freebsd_amd64.zip // +// packer-plugin-comment_v0.2.12_x5.0_freebsd_amd64.zip func (e *ChecksumFileEntry) init(req *Requirement) (err error) { filename := e.Filename res := strings.TrimPrefix(filename, req.FilenamePrefix()) diff --git a/provisioner/powershell/executionpolicy_enumer.go b/provisioner/powershell/executionpolicy_enumer.go index b8157b9cf..eac957360 100644 --- a/provisioner/powershell/executionpolicy_enumer.go +++ b/provisioner/powershell/executionpolicy_enumer.go @@ -1,6 +1,5 @@ // Code generated by "enumer -transform snake -trimprefix ExecutionPolicy -type ExecutionPolicy"; DO NOT EDIT. -// package powershell import ( diff --git a/provisioner/windows-shell/provisioner.go b/provisioner/windows-shell/provisioner.go index ab263d359..c6f22a3e7 100644 --- a/provisioner/windows-shell/provisioner.go +++ b/provisioner/windows-shell/provisioner.go @@ -28,7 +28,7 @@ import ( "github.com/hashicorp/packer-plugin-sdk/tmp" ) -//FIXME query remote host or use %SYSTEMROOT%, %TEMP% and more creative filename +// FIXME query remote host or use %SYSTEMROOT%, %TEMP% and more creative filename const DefaultRemotePath = "c:/Windows/Temp/script.bat" type Config struct { diff --git a/scripts/generate-plugins.go b/scripts/generate-plugins.go index 35f83c2d3..e52c063b3 100755 --- a/scripts/generate-plugins.go +++ b/scripts/generate-plugins.go @@ -99,10 +99,10 @@ type plugin struct { // makeMap creates a map named Name with type packer.Name that looks something // like this: // -// var Builders = map[string]packersdk.Builder{ -// "amazon-chroot": new(chroot.Builder), -// "amazon-ebs": new(ebs.Builder), -// "amazon-instance": new(instance.Builder), +// var Builders = map[string]packersdk.Builder{ +// "amazon-chroot": new(chroot.Builder), +// "amazon-ebs": new(ebs.Builder), +// "amazon-instance": new(instance.Builder), func makeMap(varName, varType string, items []plugin) string { output := ""