From c12c47f09d677fdeda6478ad1f66d3aa61657b4e Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Fri, 28 Apr 2023 13:57:32 -0400 Subject: [PATCH] Merge pull request #12380 from hashicorp/bump-go-1.20 Bump Go tooling to version 1.20 --- .github/workflows/go-test.yml | 23 ++++++++++++-- .github/workflows/go-validate.yml | 31 +++++++++++++++---- .go-version | 2 +- Makefile | 2 +- command/build_cancellation_test.go | 1 + command/configtype_enumer.go | 1 - config_test.go | 4 ++- go.mod | 2 +- hcl2template/addrs/plugin.go | 7 +++-- hcl2template/docs.go | 1 - hcl2template/functions.go | 1 - hcl2template/types.source.go | 11 ++++--- internal/hcp/api/mock_service.go | 12 +++---- internal/hcp/registry/types.iterations.go | 6 ++-- packer/fixconfigmode_enumer.go | 1 - packer/plugin-getter/plugins.go | 2 +- .../powershell/executionpolicy_enumer.go | 1 - provisioner/windows-shell/provisioner.go | 2 +- scripts/generate-plugins.go | 8 ++--- 19 files changed, 77 insertions(+), 41 deletions(-) diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 04d8159ae..d729b257a 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@v2 - uses: actions/setup-go@v2 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@v2 - uses: actions/setup-go@v2 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@v2 - uses: actions/setup-go@v2 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 878f7a223..ce6e72d78 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@v2 - - uses: actions/setup-go@v2 + - 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@v2 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@v2 - uses: actions/setup-go@v2 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@v2 - uses: actions/setup-go@v2 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 a81c057db..4301c80d3 100644 --- a/command/build_cancellation_test.go +++ b/command/build_cancellation_test.go @@ -50,6 +50,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 9224b259c..aaa58c698 100644 --- a/config_test.go +++ b/config_test.go @@ -185,7 +185,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 6d2796b16..4337fe427 100644 --- a/go.mod +++ b/go.mod @@ -255,4 +255,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 8fae62620..a7d79c8c2 100644 --- a/hcl2template/addrs/plugin.go +++ b/hcl2template/addrs/plugin.go @@ -94,9 +94,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 cce348abd..e45b65409 100644 --- a/hcl2template/docs.go +++ b/hcl2template/docs.go @@ -4,5 +4,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 33da10257..b608ad27c 100644 --- a/hcl2template/functions.go +++ b/hcl2template/functions.go @@ -24,7 +24,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 6c8d7bd9c..9abffd4da 100644 --- a/hcl2template/types.source.go +++ b/hcl2template/types.source.go @@ -64,11 +64,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 8ab149f3b..2967ec9cc 100644 --- a/internal/hcp/api/mock_service.go +++ b/internal/hcp/api/mock_service.go @@ -13,9 +13,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 @@ -36,9 +36,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 aafd62059..b0e853c8c 100644 --- a/internal/hcp/registry/types.iterations.go +++ b/internal/hcp/registry/types.iterations.go @@ -97,12 +97,12 @@ func GetGitFingerprint(opts IterationOptions) (string, error) { return ref.Hash().String(), 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 { @@ -117,7 +117,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 a94823692..7733f4b06 100644 --- a/packer/plugin-getter/plugins.go +++ b/packer/plugin-getter/plugins.go @@ -383,8 +383,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 0e21c6cb9..36e7ac9f0 100644 --- a/provisioner/windows-shell/provisioner.go +++ b/provisioner/windows-shell/provisioner.go @@ -25,7 +25,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 d2e69c5af..50eaaa0db 100755 --- a/scripts/generate-plugins.go +++ b/scripts/generate-plugins.go @@ -96,10 +96,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 := ""