Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: update formatting for go code and add CI check #12040

Merged
merged 5 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/magician/cmd/scheduled_pr_reminders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions .ci/magician/cmd/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion .ci/magician/cmd/test_tgc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions .ci/magician/cmd/test_tpg.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package cmd

import (
"fmt"
"github.com/spf13/cobra"
"magician/github"
"os"
"github.com/spf13/cobra"
)

type ttGithub interface {
Expand Down Expand Up @@ -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
}
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/gofmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: gofmt

permissions:
contents: read

on:
pull_request:
paths:
- "**/*.go"

jobs:
run_gofmt:
ScottSuarez marked this conversation as resolved.
Show resolved Hide resolved
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
wyardley marked this conversation as resolved.
Show resolved Hide resolved
exit 1
fi
echo "gofmt-output=gofmt success" >> "$GITHUB_OUTPUT"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ var resourceConfigRemovingAResourceTestCases = []resourceInventoryTestCase{
new: nil,
wantViolations: true,
},
}
}
2 changes: 1 addition & 1 deletion tools/diff-processor/cmd/breaking_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion tools/diff-processor/cmd/breaking_changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
6 changes: 3 additions & 3 deletions tpgtools/property_helpers.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 3 additions & 3 deletions tpgtools/serializable/serializable.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 4 additions & 4 deletions tpgtools/serializable/serializable_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tpgtools/serialization_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions tpgtools/type.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Loading