diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index eed4da1..c5ab3af 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -22,5 +22,5 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.51.1 + version: v1.54.2 args: --timeout=5m diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ac0d289..2f3a0fc 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -39,7 +39,7 @@ jobs: fail-fast: false matrix: terraform: - - 1.5.0 + - 1.5.5 - 1.4.6 - 1.3.9 - 0.12.31 diff --git a/.go-version b/.go-version index 5fb5a6b..d2ab029 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.20 +1.21 diff --git a/Dockerfile b/Dockerfile index 85001bf..72daf78 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ ARG TERRAFORM_VERSION=latest FROM hashicorp/terraform:$TERRAFORM_VERSION AS terraform -FROM golang:1.20-alpine3.17 +FROM golang:1.21-alpine3.18 RUN apk --no-cache add make git bash COPY --from=terraform /bin/terraform /usr/local/bin/ WORKDIR /work diff --git a/README.md b/README.md index 20c303e..5147bd0 100644 --- a/README.md +++ b/README.md @@ -276,7 +276,7 @@ https://github.com/minamijoyo/tfmigrate/releases ### Source -If you have Go 1.20+ development environment: +If you have Go 1.21+ development environment: ``` $ git clone https://github.com/minamijoyo/tfmigrate diff --git a/go.mod b/go.mod index bfd2aaa..bd87f76 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/minamijoyo/tfmigrate -go 1.20 +go 1.21 require ( cloud.google.com/go/storage v1.25.0 diff --git a/history/controller_test.go b/history/controller_test.go index e86b09f..defc6a3 100644 --- a/history/controller_test.go +++ b/history/controller_test.go @@ -540,12 +540,14 @@ func TestControllerAddRecord(t *testing.T) { for _, tc := range cases { t.Run(tc.desc, func(t *testing.T) { + currentTC := tc + c := &Controller{ migrations: tc.migrations, history: tc.history, } - c.AddRecord(tc.filename, tc.migrationType, tc.name, &tc.appliedAt) + c.AddRecord(tc.filename, tc.migrationType, currentTC.name, ¤tTC.appliedAt) got := tc.history if diff := cmp.Diff(got, tc.want, cmp.AllowUnexported(got)); diff != "" { t.Errorf("got = %#v, want = %#v, diff = %s", got, tc.want, diff) diff --git a/storage/gcs/storage_test.go b/storage/gcs/storage_test.go index e3dd619..4623dbc 100644 --- a/storage/gcs/storage_test.go +++ b/storage/gcs/storage_test.go @@ -13,11 +13,11 @@ type mockClient struct { err error } -func (c *mockClient) Read(ctx context.Context) ([]byte, error) { +func (c *mockClient) Read(_ context.Context) ([]byte, error) { return c.dataToRead, c.err } -func (c *mockClient) Write(ctx context.Context, b []byte) error { +func (c *mockClient) Write(_ context.Context, _ []byte) error { return c.err } diff --git a/storage/local/storage.go b/storage/local/storage.go index 9319c18..b798f6e 100644 --- a/storage/local/storage.go +++ b/storage/local/storage.go @@ -27,7 +27,7 @@ func NewStorage(config *Config) (*Storage, error) { } // Write writes migration history data to storage. -func (s *Storage) Write(ctx context.Context, b []byte) error { +func (s *Storage) Write(_ context.Context, b []byte) error { // nolint gosec // G306: Expect WriteFile permissions to be 0600 or less // We ignore it because a history file doesn't contains sensitive data. @@ -38,7 +38,7 @@ func (s *Storage) Write(ctx context.Context, b []byte) error { // Read reads migration history data from storage. // If the key does not exist, it is assumed to be uninitialized and returns // an empty array instead of an error. -func (s *Storage) Read(ctx context.Context) ([]byte, error) { +func (s *Storage) Read(_ context.Context) ([]byte, error) { if _, err := os.Stat(s.config.Path); os.IsNotExist(err) { // If the key does not exist return []byte{}, nil diff --git a/storage/mock/storage.go b/storage/mock/storage.go index afa15d7..fe2a964 100644 --- a/storage/mock/storage.go +++ b/storage/mock/storage.go @@ -33,7 +33,7 @@ func (s *Storage) Data() string { } // Write writes migration history data to storage. -func (s *Storage) Write(ctx context.Context, b []byte) error { +func (s *Storage) Write(_ context.Context, b []byte) error { if s.config.WriteError { return fmt.Errorf("failed to write mock storage: writeError = %t", s.config.WriteError) } @@ -42,7 +42,7 @@ func (s *Storage) Write(ctx context.Context, b []byte) error { } // Read reads migration history data from storage. -func (s *Storage) Read(ctx context.Context) ([]byte, error) { +func (s *Storage) Read(_ context.Context) ([]byte, error) { if s.config.ReadError { return nil, fmt.Errorf("failed to read mock storage: readError = %t", s.config.ReadError) } diff --git a/storage/s3/storage_test.go b/storage/s3/storage_test.go index b6d3335..ea11d74 100644 --- a/storage/s3/storage_test.go +++ b/storage/s3/storage_test.go @@ -20,12 +20,12 @@ type mockClient struct { } // PutObjectWithContext returns a mocked response. -func (c *mockClient) PutObjectWithContext(ctx aws.Context, input *s3.PutObjectInput, opts ...request.Option) (*s3.PutObjectOutput, error) { +func (c *mockClient) PutObjectWithContext(_ aws.Context, _ *s3.PutObjectInput, _ ...request.Option) (*s3.PutObjectOutput, error) { return c.putOutput, c.err } // GetObjectWithContext returns a mocked response. -func (c *mockClient) GetObjectWithContext(ctx aws.Context, input *s3.GetObjectInput, opts ...request.Option) (*s3.GetObjectOutput, error) { +func (c *mockClient) GetObjectWithContext(_ aws.Context, _ *s3.GetObjectInput, _ ...request.Option) (*s3.GetObjectOutput, error) { return c.getOutput, c.err } diff --git a/tfexec/executor_test.go b/tfexec/executor_test.go index 8f8f0b9..e76c730 100644 --- a/tfexec/executor_test.go +++ b/tfexec/executor_test.go @@ -16,7 +16,7 @@ func mockEcho(args ...string) int { return 0 } -func mockFalse(args ...string) int { +func mockFalse(_ ...string) int { return 1 } diff --git a/tfexec/test_helper.go b/tfexec/test_helper.go index fa32695..3c0b304 100644 --- a/tfexec/test_helper.go +++ b/tfexec/test_helper.go @@ -34,7 +34,7 @@ func NewMockExecutor(mockCommands []*mockCommand) Executor { } // NewCommandContext builds and returns an instance of Command. -func (e *mockExecutor) NewCommandContext(ctx context.Context, name string, args ...string) (Command, error) { +func (e *mockExecutor) NewCommandContext(_ context.Context, name string, args ...string) (Command, error) { cmd := e.mockCommands[e.newCommnadContextCalls] e.newCommnadContextCalls++ // store called args to pass runFunc callback. @@ -70,7 +70,7 @@ func (e *mockExecutor) Dir() string { } // AppendEnv appends an environment variable. -func (e *mockExecutor) AppendEnv(key string, value string) { +func (e *mockExecutor) AppendEnv(_ string, _ string) { // no op. } diff --git a/tfmigrate/mock_migrator.go b/tfmigrate/mock_migrator.go index 022ecd0..dc01fe0 100644 --- a/tfmigrate/mock_migrator.go +++ b/tfmigrate/mock_migrator.go @@ -20,7 +20,7 @@ type MockMigratorConfig struct { var _ MigratorConfig = (*MockMigratorConfig)(nil) // NewMigrator returns a new instance of MockMigrator. -func (c *MockMigratorConfig) NewMigrator(o *MigratorOption) (Migrator, error) { +func (c *MockMigratorConfig) NewMigrator(_ *MigratorOption) (Migrator, error) { return NewMockMigrator(c.PlanError, c.ApplyError), nil } @@ -45,7 +45,7 @@ func NewMockMigrator(planError bool, applyError bool) *MockMigrator { // plan computes a new state by applying state migration operations to a temporary state. // It does nothing, but can return an error. -func (m *MockMigrator) plan(ctx context.Context) (*tfexec.State, error) { +func (m *MockMigrator) plan(_ context.Context) (*tfexec.State, error) { if m.planError { return nil, fmt.Errorf("failed to plan mock migrator: planError = %t", m.planError) }