diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f44ef14..19ed4442 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,3 +47,26 @@ jobs: uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} + + generate: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Delete old generated files + run: find . -name 'zz_*.go' -delete + + - name: Run go generate + run: go generate ./... + + - name: Check uncommitted changes + run: git diff --exit-code + + - if: failure() + run: echo "::error::Check failed, please run 'go generate ./...' and commit the changes." diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2803f703..71a9bda5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -128,3 +128,9 @@ Additional Commands: set-rdns Change reverse DNS of a Server ssh Spawn an SSH connection for the server ``` + +### Generated files + +Generated files (that are created by running `go generate`) should be prefixed with `zz_`. This is to group them +together in the file list and to easily identify them as generated files. Also, it allows the CI to check if the +generated files are up-to-date. diff --git a/internal/hcapi2/mock/mock_gen.go b/internal/hcapi2/mock/mock_gen.go index cbf54914..09abb6d4 100644 --- a/internal/hcapi2/mock/mock_gen.go +++ b/internal/hcapi2/mock/mock_gen.go @@ -1,20 +1,20 @@ package hcapi2_mock -//go:generate mockgen -package hcapi2_mock -destination zz_action_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 ActionClient -//go:generate mockgen -package hcapi2_mock -destination zz_certificate_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 CertificateClient -//go:generate mockgen -package hcapi2_mock -destination zz_datacenter_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 DatacenterClient -//go:generate mockgen -package hcapi2_mock -destination zz_image_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 ImageClient -//go:generate mockgen -package hcapi2_mock -destination zz_iso_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 ISOClient -//go:generate mockgen -package hcapi2_mock -destination zz_firewall_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 FirewallClient -//go:generate mockgen -package hcapi2_mock -destination zz_floating_ip_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 FloatingIPClient -//go:generate mockgen -package hcapi2_mock -destination zz_primary_ip_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 PrimaryIPClient -//go:generate mockgen -package hcapi2_mock -destination zz_location_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 LocationClient -//go:generate mockgen -package hcapi2_mock -destination zz_loadbalancer_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 LoadBalancerClient -//go:generate mockgen -package hcapi2_mock -destination zz_loadbalancer_type_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 LoadBalancerTypeClient -//go:generate mockgen -package hcapi2_mock -destination zz_network_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 NetworkClient -//go:generate mockgen -package hcapi2_mock -destination zz_server_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 ServerClient -//go:generate mockgen -package hcapi2_mock -destination zz_server_type_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 ServerTypeClient -//go:generate mockgen -package hcapi2_mock -destination zz_ssh_key_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 SSHKeyClient -//go:generate mockgen -package hcapi2_mock -destination zz_volume_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 VolumeClient -//go:generate mockgen -package hcapi2_mock -destination zz_placement_group_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 PlacementGroupClient -//go:generate mockgen -package hcapi2_mock -destination zz_rdns_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 RDNSClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_action_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 ActionClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_certificate_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 CertificateClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_datacenter_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 DatacenterClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_image_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 ImageClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_iso_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 ISOClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_firewall_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 FirewallClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_floating_ip_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 FloatingIPClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_primary_ip_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 PrimaryIPClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_location_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 LocationClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_loadbalancer_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 LoadBalancerClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_loadbalancer_type_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 LoadBalancerTypeClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_network_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 NetworkClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_server_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 ServerClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_server_type_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 ServerTypeClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_ssh_key_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 SSHKeyClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_volume_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 VolumeClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_placement_group_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 PlacementGroupClient +//go:generate go run github.com/golang/mock/mockgen -package hcapi2_mock -destination zz_rdns_client_mock.go github.com/hetznercloud/cli/internal/hcapi2 RDNSClient diff --git a/internal/state/command_helpers.go b/internal/state/command_helpers.go index 6cd9f751..97c08c51 100644 --- a/internal/state/command_helpers.go +++ b/internal/state/command_helpers.go @@ -8,7 +8,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) -//go:generate mockgen -package state -destination command_helper_mocks.go . ActionWaiter,TokenEnsurer +//go:generate go run github.com/golang/mock/mockgen -package state -destination zz_command_helper_mock.go . ActionWaiter,TokenEnsurer type ActionWaiter interface { ActionProgress(*cobra.Command, context.Context, *hcloud.Action) error diff --git a/internal/state/config/config.go b/internal/state/config/config.go index f0c7108d..a145fd18 100644 --- a/internal/state/config/config.go +++ b/internal/state/config/config.go @@ -8,7 +8,7 @@ import ( toml "github.com/pelletier/go-toml/v2" ) -//go:generate mockgen -package config -destination zz_config_mock.go github.com/hetznercloud/cli/internal/state/config Config +//go:generate go run github.com/golang/mock/mockgen -package config -destination zz_config_mock.go github.com/hetznercloud/cli/internal/state/config Config type Config interface { Write() error diff --git a/internal/state/config/zz_config_mock.go b/internal/state/config/zz_config_mock.go index b74faab2..8de33a54 100644 --- a/internal/state/config/zz_config_mock.go +++ b/internal/state/config/zz_config_mock.go @@ -47,34 +47,6 @@ func (mr *MockConfigMockRecorder) ActiveContext() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ActiveContext", reflect.TypeOf((*MockConfig)(nil).ActiveContext)) } -// ContextByName mocks base method. -func (m *MockConfig) ContextByName(arg0 string) *Context { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ContextByName", arg0) - ret0, _ := ret[0].(*Context) - return ret0 -} - -// ContextByName indicates an expected call of ContextByName. -func (mr *MockConfigMockRecorder) ContextByName(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContextByName", reflect.TypeOf((*MockConfig)(nil).ContextByName), arg0) -} - -// ContextNames mocks base method. -func (m *MockConfig) ContextNames() []string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ContextNames") - ret0, _ := ret[0].([]string) - return ret0 -} - -// ContextNames indicates an expected call of ContextNames. -func (mr *MockConfigMockRecorder) ContextNames() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContextNames", reflect.TypeOf((*MockConfig)(nil).ContextNames)) -} - // Contexts mocks base method. func (m *MockConfig) Contexts() []*Context { m.ctrl.T.Helper() @@ -103,18 +75,6 @@ func (mr *MockConfigMockRecorder) Endpoint() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Endpoint", reflect.TypeOf((*MockConfig)(nil).Endpoint)) } -// RemoveContext mocks base method. -func (m *MockConfig) RemoveContext(arg0 *Context) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "RemoveContext", arg0) -} - -// RemoveContext indicates an expected call of RemoveContext. -func (mr *MockConfigMockRecorder) RemoveContext(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveContext", reflect.TypeOf((*MockConfig)(nil).RemoveContext), arg0) -} - // SetActiveContext mocks base method. func (m *MockConfig) SetActiveContext(arg0 *Context) { m.ctrl.T.Helper() diff --git a/internal/state/command_helper_mocks.go b/internal/state/zz_command_helper_mock.go similarity index 100% rename from internal/state/command_helper_mocks.go rename to internal/state/zz_command_helper_mock.go