diff --git a/.ci/magician/cmd/scheduled_pr_reminders_test.go b/.ci/magician/cmd/scheduled_pr_reminders_test.go index 760cf6e9fb60..8b4dfff458a4 100644 --- a/.ci/magician/cmd/scheduled_pr_reminders_test.go +++ b/.ci/magician/cmd/scheduled_pr_reminders_test.go @@ -805,7 +805,7 @@ func TestFormatReminderComment(t *testing.T) { &github.User{Login: github.String("other-reviewer")}, }, }, - state: waitingForMerge, + state: waitingForMerge, sinceDays: 5, expectedStrings: []string{ "waiting for merge for 1 week", diff --git a/.ci/magician/cmd/templates_test.go b/.ci/magician/cmd/templates_test.go index 2de0e832daaf..503eb90fb49e 100644 --- a/.ci/magician/cmd/templates_test.go +++ b/.ci/magician/cmd/templates_test.go @@ -24,16 +24,16 @@ func TestColor(t *testing.T) { want: "🟡 Test text", }, { - name: "green", + name: "green", color: "green", - text: "Test text", - want: "🟢 Test text", + text: "Test text", + want: "🟢 Test text", }, { - name: "unsupported color", + name: "unsupported color", color: "mauve", - text: "Test text", - want: "Test text", + text: "Test text", + want: "Test text", }, { name: "empty color", diff --git a/.ci/magician/cmd/test_tgc_test.go b/.ci/magician/cmd/test_tgc_test.go index 5e67dcca8e59..e3f89fb98445 100644 --- a/.ci/magician/cmd/test_tgc_test.go +++ b/.ci/magician/cmd/test_tgc_test.go @@ -28,7 +28,7 @@ func TestExecTestTGC(t *testing.T) { execTestTGC("sha1", "pr1", gh) method := "CreateWorkflowDispatchEvent" - expected := [][]any{{"test-tgc.yml", map[string]any{"tpgb-branch": "auto-pr-pr1", "tgc-branch": "auto-pr-pr1", "pr-number":"pr1", "owner": "modular-magician", "repo": "terraform-google-conversion", "sha": "sha1"}}} + expected := [][]any{{"test-tgc.yml", map[string]any{"tpgb-branch": "auto-pr-pr1", "tgc-branch": "auto-pr-pr1", "pr-number": "pr1", "owner": "modular-magician", "repo": "terraform-google-conversion", "sha": "sha1"}}} if calls, ok := gh.calledMethods[method]; !ok { t.Fatal("Workflow dispatch event not created") } else if !reflect.DeepEqual(calls, expected) { diff --git a/.ci/magician/cmd/test_tpg.go b/.ci/magician/cmd/test_tpg.go index 12c0b12c441c..8468aa490c50 100644 --- a/.ci/magician/cmd/test_tpg.go +++ b/.ci/magician/cmd/test_tpg.go @@ -17,9 +17,9 @@ package cmd import ( "fmt" + "github.com/spf13/cobra" "magician/github" "os" - "github.com/spf13/cobra" ) type ttGithub interface { @@ -73,7 +73,7 @@ func execTestTPG(version, commit, pr string, gh ttGithub) error { commitShaOrBranchUpstream := string(content) - if commitShaOrBranchUpstream == ""{ + if commitShaOrBranchUpstream == "" { // fall back to branch if commit SHA can't be found commitShaOrBranchUpstream = "auto-pr-" + pr } diff --git a/.github/workflows/gofmt.yml b/.github/workflows/gofmt.yml new file mode 100644 index 000000000000..be8ce984c6c4 --- /dev/null +++ b/.github/workflows/gofmt.yml @@ -0,0 +1,41 @@ +name: gofmt + +permissions: + contents: read + +on: + pull_request: + paths: + - "**/*.go" + +jobs: + run-gofmt: + runs-on: ubuntu-22.04 + steps: + - name: Checkout Repository + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + with: + fetch-depth: 0 + - name: Merge base branch + id: pull_request + run: | + git config user.name "modular-magician" + git config user.email "magic-modules@google.com" + git fetch origin ${{ github.base_ref }} # Fetch the base branch + git merge --no-ff origin/${{ github.base_ref }} # Merge with the base branch + - name: Set up Go + uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 + with: + cache: false + go-version: '^1.21' + - name: gofmt + run: | + GOFMT_OUTPUT="$(gofmt -l .)" + # Currently no simple way to get a non-0 exit code directly from + # gofmt + if [ -n "$GOFMT_OUTPUT" ]; then + echo "The following files are not formatted properly:" >&2 + echo "$GOFMT_OUTPUT" >&2 + exit 1 + fi + echo "gofmt-output=gofmt success" >> "$GITHUB_OUTPUT" diff --git a/tools/diff-processor/breaking_changes/resource_config_diff.go b/tools/diff-processor/breaking_changes/resource_config_diff.go index 95eb5526c754..9edea8de0a48 100644 --- a/tools/diff-processor/breaking_changes/resource_config_diff.go +++ b/tools/diff-processor/breaking_changes/resource_config_diff.go @@ -10,7 +10,7 @@ import ( // structure for rules regarding resource config changes type ResourceConfigDiffRule struct { Identifier string - Messages func(resource string, resourceConfigDiff diff.ResourceConfigDiff) []string + Messages func(resource string, resourceConfigDiff diff.ResourceConfigDiff) []string } // ResourceConfigDiffRules is a list of ResourceConfigDiffRule diff --git a/tools/diff-processor/breaking_changes/resource_config_diff_test.go b/tools/diff-processor/breaking_changes/resource_config_diff_test.go index 6a8e25607a05..83d278b50c52 100644 --- a/tools/diff-processor/breaking_changes/resource_config_diff_test.go +++ b/tools/diff-processor/breaking_changes/resource_config_diff_test.go @@ -44,4 +44,4 @@ var resourceConfigRemovingAResourceTestCases = []resourceInventoryTestCase{ new: nil, wantViolations: true, }, -} \ No newline at end of file +} diff --git a/tools/diff-processor/cmd/breaking_changes.go b/tools/diff-processor/cmd/breaking_changes.go index 72d14cdb95bb..bd16d705f67c 100644 --- a/tools/diff-processor/cmd/breaking_changes.go +++ b/tools/diff-processor/cmd/breaking_changes.go @@ -10,8 +10,8 @@ import ( "os" "sort" - "github.com/GoogleCloudPlatform/magic-modules/tools/diff-processor/diff" "github.com/GoogleCloudPlatform/magic-modules/tools/diff-processor/breaking_changes" + "github.com/GoogleCloudPlatform/magic-modules/tools/diff-processor/diff" "github.com/spf13/cobra" ) diff --git a/tools/diff-processor/cmd/breaking_changes_test.go b/tools/diff-processor/cmd/breaking_changes_test.go index a4c7f37a8f57..e9e7ac20a64e 100644 --- a/tools/diff-processor/cmd/breaking_changes_test.go +++ b/tools/diff-processor/cmd/breaking_changes_test.go @@ -5,8 +5,8 @@ import ( "encoding/json" "testing" - "github.com/GoogleCloudPlatform/magic-modules/tools/diff-processor/diff" "github.com/GoogleCloudPlatform/magic-modules/tools/diff-processor/breaking_changes" + "github.com/GoogleCloudPlatform/magic-modules/tools/diff-processor/diff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) diff --git a/tpgtools/property_helpers.go b/tpgtools/property_helpers.go index 459d815ff509..bb81101fe0f5 100644 --- a/tpgtools/property_helpers.go +++ b/tpgtools/property_helpers.go @@ -1,11 +1,11 @@ // Copyright 2021 Google LLC. All Rights Reserved. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/tpgtools/serializable/serializable.go b/tpgtools/serializable/serializable.go index 43ef251d219a..01b29133090f 100644 --- a/tpgtools/serializable/serializable.go +++ b/tpgtools/serializable/serializable.go @@ -1,11 +1,11 @@ // Copyright 2021 Google LLC. All Rights Reserved. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/tpgtools/serializable/serializable_test.go b/tpgtools/serializable/serializable_test.go index cb9000c0a0ea..73fa51816be7 100644 --- a/tpgtools/serializable/serializable_test.go +++ b/tpgtools/serializable/serializable_test.go @@ -1,11 +1,11 @@ // Copyright 2021 Google LLC. All Rights Reserved. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,7 +18,7 @@ import ( "testing" ) -func TestListOfResources(t *testing.T) { +func TestListOfResources(t *testing.T) { services, err := ListOfResources("test_specs") if err != nil { t.Errorf("received error: %v", err) diff --git a/tpgtools/serialization_helpers.go b/tpgtools/serialization_helpers.go index 4be1b3800d45..e362def5319d 100644 --- a/tpgtools/serialization_helpers.go +++ b/tpgtools/serialization_helpers.go @@ -7,8 +7,8 @@ import ( "strings" cloudresourcemanager "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudresourcemanager" - cloudresourcemanagerBeta "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudresourcemanager/beta" cloudresourcemanagerAlpha "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudresourcemanager/alpha" + cloudresourcemanagerBeta "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudresourcemanager/beta" ) func serializeAlphaProjectToHCL(r cloudresourcemanagerAlpha.Project, hasGAEquivalent bool) (string, error) { diff --git a/tpgtools/type.go b/tpgtools/type.go index cb31f0a7c562..0e1a43a4342c 100644 --- a/tpgtools/type.go +++ b/tpgtools/type.go @@ -1,11 +1,11 @@ // Copyright 2021 Google LLC. All Rights Reserved. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.