From 8d6beb6cc4921d3b4ccb21b9aad834a06966653e Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Thu, 29 May 2025 14:07:11 +0900 Subject: [PATCH 01/10] Fix import grouping by make lint/go FIX=true Signed-off-by: Shinnosuke Sawada-Dazai --- pkg/app/pipedv1/plugin/kubernetes/deployment/apply.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/deployment/baseline.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/deployment/canary.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/deployment/determine.go | 5 +++-- .../pipedv1/plugin/kubernetes/deployment/determine_test.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/deployment/misc.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/deployment/plugin.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/deployment/primary.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/deployment/primary_test.go | 5 +++-- pkg/app/pipedv1/plugin/kubernetes/deployment/rollback.go | 3 ++- .../pipedv1/plugin/kubernetes/deployment/rollback_test.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/deployment/sync.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/deployment/sync_test.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/deployment/traffic.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/livestate/plugin.go | 5 +++-- pkg/app/pipedv1/plugin/kubernetes/livestate/plugin_test.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/main.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/provider/helm_test.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/provider/kustomize_test.go | 3 ++- pkg/app/pipedv1/plugin/kubernetes/provider/loader_test.go | 3 ++- .../plugin/kubernetes_multicluster/deployment/apply.go | 3 ++- .../plugin/kubernetes_multicluster/deployment/determine.go | 5 +++-- .../kubernetes_multicluster/deployment/determine_test.go | 3 ++- .../plugin/kubernetes_multicluster/deployment/misc.go | 3 ++- .../plugin/kubernetes_multicluster/deployment/plugin.go | 3 ++- .../plugin/kubernetes_multicluster/deployment/rollback.go | 3 ++- .../kubernetes_multicluster/deployment/rollback_test.go | 3 ++- .../plugin/kubernetes_multicluster/deployment/sync.go | 3 ++- .../plugin/kubernetes_multicluster/deployment/sync_test.go | 3 ++- .../plugin/kubernetes_multicluster/livestate/plugin.go | 5 +++-- .../plugin/kubernetes_multicluster/livestate/plugin_test.go | 5 +++-- pkg/app/pipedv1/plugin/kubernetes_multicluster/main.go | 3 ++- .../plugin/kubernetes_multicluster/provider/helm_test.go | 3 ++- .../kubernetes_multicluster/provider/kustomize_test.go | 3 ++- .../plugin/kubernetes_multicluster/provider/loader_test.go | 3 ++- tool/actions-plan-preview/main.go | 2 +- tool/actions-plan-preview/planpreview.go | 3 ++- 37 files changed, 79 insertions(+), 43 deletions(-) diff --git a/pkg/app/pipedv1/plugin/kubernetes/deployment/apply.go b/pkg/app/pipedv1/plugin/kubernetes/deployment/apply.go index 59412ff94b..71475cf08a 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/deployment/apply.go +++ b/pkg/app/pipedv1/plugin/kubernetes/deployment/apply.go @@ -18,8 +18,9 @@ import ( "context" "errors" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" sdk "github.com/pipe-cd/piped-plugin-sdk-go" + + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" ) type applier interface { diff --git a/pkg/app/pipedv1/plugin/kubernetes/deployment/baseline.go b/pkg/app/pipedv1/plugin/kubernetes/deployment/baseline.go index d607b74d52..7fbf7dbfe7 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/deployment/baseline.go +++ b/pkg/app/pipedv1/plugin/kubernetes/deployment/baseline.go @@ -17,8 +17,9 @@ package deployment import ( "context" - kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" sdk "github.com/pipe-cd/piped-plugin-sdk-go" + + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" ) func (p *Plugin) executeK8sBaselineRolloutStage(_ context.Context, input *sdk.ExecuteStageInput[kubeconfig.KubernetesApplicationSpec], _ []*sdk.DeployTarget[kubeconfig.KubernetesDeployTargetConfig]) sdk.StageStatus { diff --git a/pkg/app/pipedv1/plugin/kubernetes/deployment/canary.go b/pkg/app/pipedv1/plugin/kubernetes/deployment/canary.go index 0771ba160a..58523584af 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/deployment/canary.go +++ b/pkg/app/pipedv1/plugin/kubernetes/deployment/canary.go @@ -17,8 +17,9 @@ package deployment import ( "context" - kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" sdk "github.com/pipe-cd/piped-plugin-sdk-go" + + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" ) func (p *Plugin) executeK8sCanaryRolloutStage(_ context.Context, input *sdk.ExecuteStageInput[kubeconfig.KubernetesApplicationSpec], _ []*sdk.DeployTarget[kubeconfig.KubernetesDeployTargetConfig]) sdk.StageStatus { diff --git a/pkg/app/pipedv1/plugin/kubernetes/deployment/determine.go b/pkg/app/pipedv1/plugin/kubernetes/deployment/determine.go index 53443c87eb..d9965b1818 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/deployment/determine.go +++ b/pkg/app/pipedv1/plugin/kubernetes/deployment/determine.go @@ -21,10 +21,11 @@ import ( "go.uber.org/zap" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" sdk "github.com/pipe-cd/piped-plugin-sdk-go" "github.com/pipe-cd/piped-plugin-sdk-go/diff" + + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" ) type containerImage struct { diff --git a/pkg/app/pipedv1/plugin/kubernetes/deployment/determine_test.go b/pkg/app/pipedv1/plugin/kubernetes/deployment/determine_test.go index a0068173cf..c86fcde874 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/deployment/determine_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes/deployment/determine_test.go @@ -24,9 +24,10 @@ import ( "go.uber.org/zap" "sigs.k8s.io/yaml" + sdk "github.com/pipe-cd/piped-plugin-sdk-go" + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" - sdk "github.com/pipe-cd/piped-plugin-sdk-go" ) func mustUnmarshalYAML[T any](t *testing.T, data []byte) T { diff --git a/pkg/app/pipedv1/plugin/kubernetes/deployment/misc.go b/pkg/app/pipedv1/plugin/kubernetes/deployment/misc.go index 5b989f549b..44678d7387 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/deployment/misc.go +++ b/pkg/app/pipedv1/plugin/kubernetes/deployment/misc.go @@ -24,8 +24,9 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" sdk "github.com/pipe-cd/piped-plugin-sdk-go" + + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" ) func ensureVariantSelectorInWorkload(m provider.Manifest, variantLabel, variant string) error { diff --git a/pkg/app/pipedv1/plugin/kubernetes/deployment/plugin.go b/pkg/app/pipedv1/plugin/kubernetes/deployment/plugin.go index ca6c373c18..38bf44f15d 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/deployment/plugin.go +++ b/pkg/app/pipedv1/plugin/kubernetes/deployment/plugin.go @@ -20,10 +20,11 @@ import ( "go.uber.org/zap" + sdk "github.com/pipe-cd/piped-plugin-sdk-go" + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/toolregistry" - sdk "github.com/pipe-cd/piped-plugin-sdk-go" ) // Plugin implements the sdk.DeploymentPlugin interface. diff --git a/pkg/app/pipedv1/plugin/kubernetes/deployment/primary.go b/pkg/app/pipedv1/plugin/kubernetes/deployment/primary.go index 808a546ec6..4a3d2055b6 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/deployment/primary.go +++ b/pkg/app/pipedv1/plugin/kubernetes/deployment/primary.go @@ -21,10 +21,11 @@ import ( "fmt" "time" + sdk "github.com/pipe-cd/piped-plugin-sdk-go" + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/toolregistry" - sdk "github.com/pipe-cd/piped-plugin-sdk-go" ) func (p *Plugin) executeK8sPrimaryRolloutStage(ctx context.Context, input *sdk.ExecuteStageInput[kubeconfig.KubernetesApplicationSpec], dts []*sdk.DeployTarget[kubeconfig.KubernetesDeployTargetConfig]) sdk.StageStatus { diff --git a/pkg/app/pipedv1/plugin/kubernetes/deployment/primary_test.go b/pkg/app/pipedv1/plugin/kubernetes/deployment/primary_test.go index e4058ab42b..641e2e6203 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/deployment/primary_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes/deployment/primary_test.go @@ -27,11 +27,12 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" schema "k8s.io/apimachinery/pkg/runtime/schema" - kubeConfigPkg "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" sdk "github.com/pipe-cd/piped-plugin-sdk-go" "github.com/pipe-cd/piped-plugin-sdk-go/logpersister/logpersistertest" "github.com/pipe-cd/piped-plugin-sdk-go/toolregistry/toolregistrytest" + + kubeConfigPkg "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" ) func TestPlugin_executeK8sPrimaryRolloutStage(t *testing.T) { diff --git a/pkg/app/pipedv1/plugin/kubernetes/deployment/rollback.go b/pkg/app/pipedv1/plugin/kubernetes/deployment/rollback.go index 80d0bc7cb1..7971beeba4 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/deployment/rollback.go +++ b/pkg/app/pipedv1/plugin/kubernetes/deployment/rollback.go @@ -18,10 +18,11 @@ import ( "cmp" "context" + sdk "github.com/pipe-cd/piped-plugin-sdk-go" + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/toolregistry" - sdk "github.com/pipe-cd/piped-plugin-sdk-go" ) func (p *Plugin) executeK8sRollbackStage(ctx context.Context, input *sdk.ExecuteStageInput[kubeconfig.KubernetesApplicationSpec], dts []*sdk.DeployTarget[kubeconfig.KubernetesDeployTargetConfig]) sdk.StageStatus { diff --git a/pkg/app/pipedv1/plugin/kubernetes/deployment/rollback_test.go b/pkg/app/pipedv1/plugin/kubernetes/deployment/rollback_test.go index 40fce69c32..2fd7e22bff 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/deployment/rollback_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes/deployment/rollback_test.go @@ -24,10 +24,11 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" - kubeConfigPkg "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" sdk "github.com/pipe-cd/piped-plugin-sdk-go" "github.com/pipe-cd/piped-plugin-sdk-go/logpersister/logpersistertest" "github.com/pipe-cd/piped-plugin-sdk-go/toolregistry/toolregistrytest" + + kubeConfigPkg "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" ) func TestPlugin_executeK8sRollbackStage_NoPreviousDeployment(t *testing.T) { diff --git a/pkg/app/pipedv1/plugin/kubernetes/deployment/sync.go b/pkg/app/pipedv1/plugin/kubernetes/deployment/sync.go index 8be60c5db4..39d4ca04c6 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/deployment/sync.go +++ b/pkg/app/pipedv1/plugin/kubernetes/deployment/sync.go @@ -20,10 +20,11 @@ import ( "encoding/json" "time" + sdk "github.com/pipe-cd/piped-plugin-sdk-go" + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/toolregistry" - sdk "github.com/pipe-cd/piped-plugin-sdk-go" ) func (p *Plugin) executeK8sSyncStage(ctx context.Context, input *sdk.ExecuteStageInput[kubeconfig.KubernetesApplicationSpec], dts []*sdk.DeployTarget[kubeconfig.KubernetesDeployTargetConfig]) sdk.StageStatus { diff --git a/pkg/app/pipedv1/plugin/kubernetes/deployment/sync_test.go b/pkg/app/pipedv1/plugin/kubernetes/deployment/sync_test.go index c9ff6ebccc..d2acf91a30 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/deployment/sync_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes/deployment/sync_test.go @@ -26,10 +26,11 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" - kubeConfigPkg "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" sdk "github.com/pipe-cd/piped-plugin-sdk-go" "github.com/pipe-cd/piped-plugin-sdk-go/logpersister/logpersistertest" "github.com/pipe-cd/piped-plugin-sdk-go/toolregistry/toolregistrytest" + + kubeConfigPkg "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" ) func TestPlugin_executeK8sSyncStage(t *testing.T) { diff --git a/pkg/app/pipedv1/plugin/kubernetes/deployment/traffic.go b/pkg/app/pipedv1/plugin/kubernetes/deployment/traffic.go index 2eede1799e..47e9b45495 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/deployment/traffic.go +++ b/pkg/app/pipedv1/plugin/kubernetes/deployment/traffic.go @@ -17,8 +17,9 @@ package deployment import ( "context" - kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" sdk "github.com/pipe-cd/piped-plugin-sdk-go" + + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" ) func (p *Plugin) executeK8sTrafficRoutingStage(_ context.Context, input *sdk.ExecuteStageInput[kubeconfig.KubernetesApplicationSpec], _ []*sdk.DeployTarget[kubeconfig.KubernetesDeployTargetConfig]) sdk.StageStatus { diff --git a/pkg/app/pipedv1/plugin/kubernetes/livestate/plugin.go b/pkg/app/pipedv1/plugin/kubernetes/livestate/plugin.go index cdf23677b3..b83866c670 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/livestate/plugin.go +++ b/pkg/app/pipedv1/plugin/kubernetes/livestate/plugin.go @@ -22,11 +22,12 @@ import ( "go.uber.org/zap" + sdk "github.com/pipe-cd/piped-plugin-sdk-go" + "github.com/pipe-cd/piped-plugin-sdk-go/diff" + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/toolregistry" - sdk "github.com/pipe-cd/piped-plugin-sdk-go" - "github.com/pipe-cd/piped-plugin-sdk-go/diff" ) type Plugin struct{} diff --git a/pkg/app/pipedv1/plugin/kubernetes/livestate/plugin_test.go b/pkg/app/pipedv1/plugin/kubernetes/livestate/plugin_test.go index 2e6ea6b4c9..e365ac31fb 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/livestate/plugin_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes/livestate/plugin_test.go @@ -21,9 +21,10 @@ import ( "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" sdk "github.com/pipe-cd/piped-plugin-sdk-go" "github.com/pipe-cd/piped-plugin-sdk-go/diff" + + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/provider" ) func makeTestManifest(t *testing.T, yaml string) provider.Manifest { diff --git a/pkg/app/pipedv1/plugin/kubernetes/main.go b/pkg/app/pipedv1/plugin/kubernetes/main.go index 4c4161cbf3..f9991cef46 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/main.go +++ b/pkg/app/pipedv1/plugin/kubernetes/main.go @@ -17,9 +17,10 @@ package main import ( "log" + sdk "github.com/pipe-cd/piped-plugin-sdk-go" + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/deployment" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/livestate" - sdk "github.com/pipe-cd/piped-plugin-sdk-go" ) func main() { diff --git a/pkg/app/pipedv1/plugin/kubernetes/provider/helm_test.go b/pkg/app/pipedv1/plugin/kubernetes/provider/helm_test.go index 5598e8d191..5371bcd0d0 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/provider/helm_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes/provider/helm_test.go @@ -23,8 +23,9 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/toolregistry" "github.com/pipe-cd/piped-plugin-sdk-go/toolregistry/toolregistrytest" + + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/toolregistry" ) func TestTemplateLocalChart(t *testing.T) { diff --git a/pkg/app/pipedv1/plugin/kubernetes/provider/kustomize_test.go b/pkg/app/pipedv1/plugin/kubernetes/provider/kustomize_test.go index 5466cf7f6a..576d4313f6 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/provider/kustomize_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes/provider/kustomize_test.go @@ -22,8 +22,9 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/toolregistry" "github.com/pipe-cd/piped-plugin-sdk-go/toolregistry/toolregistrytest" + + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/toolregistry" ) func TestKustomizeTemplate(t *testing.T) { diff --git a/pkg/app/pipedv1/plugin/kubernetes/provider/loader_test.go b/pkg/app/pipedv1/plugin/kubernetes/provider/loader_test.go index a2d4363000..3c532e04df 100644 --- a/pkg/app/pipedv1/plugin/kubernetes/provider/loader_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes/provider/loader_test.go @@ -26,9 +26,10 @@ import ( "go.uber.org/zap" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "github.com/pipe-cd/piped-plugin-sdk-go/toolregistry/toolregistrytest" + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/config" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/toolregistry" - "github.com/pipe-cd/piped-plugin-sdk-go/toolregistry/toolregistrytest" ) func mustParseManifests(t *testing.T, data string) []Manifest { diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/apply.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/apply.go index 38c34359a4..e255466004 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/apply.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/apply.go @@ -18,8 +18,9 @@ import ( "context" "errors" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider" sdk "github.com/pipe-cd/piped-plugin-sdk-go" + + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider" ) type applier interface { diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/determine.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/determine.go index b3249ceba4..746b0dd85e 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/determine.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/determine.go @@ -21,10 +21,11 @@ import ( "go.uber.org/zap" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/config" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider" sdk "github.com/pipe-cd/piped-plugin-sdk-go" "github.com/pipe-cd/piped-plugin-sdk-go/diff" + + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/config" + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider" ) type containerImage struct { diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/determine_test.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/determine_test.go index 01d3026410..bb82de9673 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/determine_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/determine_test.go @@ -24,9 +24,10 @@ import ( "go.uber.org/zap" "sigs.k8s.io/yaml" + sdk "github.com/pipe-cd/piped-plugin-sdk-go" + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/config" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider" - sdk "github.com/pipe-cd/piped-plugin-sdk-go" ) func mustUnmarshalYAML[T any](t *testing.T, data []byte) T { diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/misc.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/misc.go index fbd7d256c3..8611338f32 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/misc.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/misc.go @@ -18,8 +18,9 @@ import ( "context" "errors" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider" sdk "github.com/pipe-cd/piped-plugin-sdk-go" + + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider" ) func ensureVariantSelectorInWorkload(m provider.Manifest, variantLabel, variant string) error { diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/plugin.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/plugin.go index 0288fa5422..8122c78779 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/plugin.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/plugin.go @@ -20,10 +20,11 @@ import ( "go.uber.org/zap" + sdk "github.com/pipe-cd/piped-plugin-sdk-go" + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/config" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/toolregistry" - sdk "github.com/pipe-cd/piped-plugin-sdk-go" ) // Plugin implements the sdk.DeploymentPlugin interface. diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/rollback.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/rollback.go index 50ae963d00..5b8ded8911 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/rollback.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/rollback.go @@ -19,10 +19,11 @@ import ( "context" "sync" + sdk "github.com/pipe-cd/piped-plugin-sdk-go" + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/config" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/toolregistry" - sdk "github.com/pipe-cd/piped-plugin-sdk-go" ) func (p *Plugin) executeK8sMultiRollbackStage(ctx context.Context, input *sdk.ExecuteStageInput[kubeconfig.KubernetesApplicationSpec], dts []*sdk.DeployTarget[kubeconfig.KubernetesDeployTargetConfig]) sdk.StageStatus { diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/rollback_test.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/rollback_test.go index 03cd035ba5..3c3f7901d0 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/rollback_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/rollback_test.go @@ -26,10 +26,11 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" - kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/config" sdk "github.com/pipe-cd/piped-plugin-sdk-go" "github.com/pipe-cd/piped-plugin-sdk-go/logpersister/logpersistertest" "github.com/pipe-cd/piped-plugin-sdk-go/toolregistry/toolregistrytest" + + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/config" ) func TestPlugin_executeK8sMultiRollbackStage_compatibility_k8sPlugin_NoPreviousDeployment(t *testing.T) { diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/sync.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/sync.go index 52cbb668bb..e2a7c67dd0 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/sync.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/sync.go @@ -23,10 +23,11 @@ import ( "golang.org/x/sync/errgroup" + sdk "github.com/pipe-cd/piped-plugin-sdk-go" + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/config" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/toolregistry" - sdk "github.com/pipe-cd/piped-plugin-sdk-go" ) func (p *Plugin) executeK8sMultiSyncStage(ctx context.Context, input *sdk.ExecuteStageInput[kubeconfig.KubernetesApplicationSpec], dts []*sdk.DeployTarget[kubeconfig.KubernetesDeployTargetConfig]) sdk.StageStatus { diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/sync_test.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/sync_test.go index 6a064d6480..11c0fcbcbe 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/sync_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/sync_test.go @@ -27,10 +27,11 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" - kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/config" sdk "github.com/pipe-cd/piped-plugin-sdk-go" "github.com/pipe-cd/piped-plugin-sdk-go/logpersister/logpersistertest" "github.com/pipe-cd/piped-plugin-sdk-go/toolregistry/toolregistrytest" + + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/config" ) func TestPlugin_executeK8sMultiSyncStage(t *testing.T) { diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/livestate/plugin.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/livestate/plugin.go index 50d0aa2bcb..f3925b29a1 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/livestate/plugin.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/livestate/plugin.go @@ -22,11 +22,12 @@ import ( "go.uber.org/zap" + sdk "github.com/pipe-cd/piped-plugin-sdk-go" + "github.com/pipe-cd/piped-plugin-sdk-go/diff" + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/config" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/toolregistry" - sdk "github.com/pipe-cd/piped-plugin-sdk-go" - "github.com/pipe-cd/piped-plugin-sdk-go/diff" ) type Plugin struct{} diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/livestate/plugin_test.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/livestate/plugin_test.go index ea723a99f2..d2f16ba8f0 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/livestate/plugin_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/livestate/plugin_test.go @@ -21,10 +21,11 @@ import ( "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/config" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider" sdk "github.com/pipe-cd/piped-plugin-sdk-go" "github.com/pipe-cd/piped-plugin-sdk-go/diff" + + kubeconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/config" + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider" ) func makeTestManifest(t *testing.T, yaml string) provider.Manifest { diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/main.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/main.go index 576b2ddc9f..67883ddebd 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/main.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/main.go @@ -17,9 +17,10 @@ package main import ( "log" + sdk "github.com/pipe-cd/piped-plugin-sdk-go" + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/livestate" - sdk "github.com/pipe-cd/piped-plugin-sdk-go" ) func main() { diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/helm_test.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/helm_test.go index d3bd4b8eb2..f0731fbce2 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/helm_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/helm_test.go @@ -23,8 +23,9 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/toolregistry" "github.com/pipe-cd/piped-plugin-sdk-go/toolregistry/toolregistrytest" + + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/toolregistry" ) func TestTemplateLocalChart(t *testing.T) { diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/kustomize_test.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/kustomize_test.go index 35133d69b5..7bf39feeb1 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/kustomize_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/kustomize_test.go @@ -22,8 +22,9 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" - "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/toolregistry" "github.com/pipe-cd/piped-plugin-sdk-go/toolregistry/toolregistrytest" + + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/toolregistry" ) func TestKustomizeTemplate(t *testing.T) { diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/loader_test.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/loader_test.go index 9cac4fd9f9..9f16ce5b81 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/loader_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/loader_test.go @@ -26,9 +26,10 @@ import ( "go.uber.org/zap" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "github.com/pipe-cd/piped-plugin-sdk-go/toolregistry/toolregistrytest" + "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/config" "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes_multicluster/toolregistry" - "github.com/pipe-cd/piped-plugin-sdk-go/toolregistry/toolregistrytest" ) func mustParseManifests(t *testing.T, data string) []Manifest { diff --git a/tool/actions-plan-preview/main.go b/tool/actions-plan-preview/main.go index c5d888bbe1..c90d6d92fa 100644 --- a/tool/actions-plan-preview/main.go +++ b/tool/actions-plan-preview/main.go @@ -108,7 +108,7 @@ func main() { // TODO: When PR opened, `Mergeable` is nil for calculation. // Here it is not considered for now, but needs to be handled. - if event.PRMergeable != nil && *event.PRMergeable == false { + if event.PRMergeable != nil && !*event.PRMergeable { doComment(failureBadgeURL + "\nUnable to run plan-preview for an un-mergeable pull request. Please resolve the conficts and try again.") return } diff --git a/tool/actions-plan-preview/planpreview.go b/tool/actions-plan-preview/planpreview.go index e27f10cc67..265f7a481d 100644 --- a/tool/actions-plan-preview/planpreview.go +++ b/tool/actions-plan-preview/planpreview.go @@ -19,7 +19,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/shurcooL/githubv4" "log" "os" "os/exec" @@ -27,6 +26,8 @@ import ( "strings" "time" "unicode/utf8" + + "github.com/shurcooL/githubv4" ) type PlanPreviewResult struct { From 87f0e1e63a5627e094e0fdf5f87dd7f3a868ec44 Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Thu, 29 May 2025 14:07:38 +0900 Subject: [PATCH 02/10] Fix linter errors by make lint/go FIX=true Signed-off-by: Shinnosuke Sawada-Dazai --- tool/codegen/protoc-gen-auth/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tool/codegen/protoc-gen-auth/main.go b/tool/codegen/protoc-gen-auth/main.go index 6238e1cdb2..c6cf060b89 100644 --- a/tool/codegen/protoc-gen-auth/main.go +++ b/tool/codegen/protoc-gen-auth/main.go @@ -90,7 +90,7 @@ func main() { if err := t.Execute(&buf, fp); err != nil { return fmt.Errorf("template execute error: %v", err) } - gf.P(string(buf.Bytes())) + gf.P(buf.String()) } return nil From 7b3c8454ae582c193b65b21e4a0ae6811a6b1f4d Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Thu, 29 May 2025 14:10:16 +0900 Subject: [PATCH 03/10] Rewrite long if-else to switch Signed-off-by: Shinnosuke Sawada-Dazai --- tool/actions-gh-release/filematcher.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tool/actions-gh-release/filematcher.go b/tool/actions-gh-release/filematcher.go index 63d895120f..2e0489ad77 100644 --- a/tool/actions-gh-release/filematcher.go +++ b/tool/actions-gh-release/filematcher.go @@ -184,7 +184,8 @@ func (p *Pattern) regexpString() string { for scan.Peek() != scanner.EOF { ch := scan.Next() - if ch == '*' { + switch ch { + case '*': if scan.Peek() == '*' { // Is some flavor of "**". scan.Next() @@ -207,14 +208,14 @@ func (p *Pattern) regexpString() string { // Is "*" so map it to anything but "/". regStr += "[^" + escSL + "]*" } - } else if ch == '?' { + case '?': // "?" is any char except "/". regStr += "[^" + escSL + "]" - } else if ch == '.' || ch == '$' { + case '.', '$': // Escape some regexp special chars that have no meaning // in golang's filepath.Match. regStr += `\` + string(ch) - } else if ch == '\\' { + case '\\': // Escape next char. Note that a trailing \ in the pattern // will be left alone (but need to escape it). if sl == `\` { @@ -229,7 +230,7 @@ func (p *Pattern) regexpString() string { } else { regStr += `\` } - } else { + default: regStr += string(ch) } } From 01841ee1950b87f6053d007ad9a47d1a84d46793 Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Thu, 29 May 2025 14:13:19 +0900 Subject: [PATCH 04/10] Remove unnecessary zero-value initialization Signed-off-by: Shinnosuke Sawada-Dazai --- tool/actions-gh-release/main.go | 2 +- tool/actions-gh-release/release.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tool/actions-gh-release/main.go b/tool/actions-gh-release/main.go index f80d6ccfb1..41afbb1835 100644 --- a/tool/actions-gh-release/main.go +++ b/tool/actions-gh-release/main.go @@ -72,7 +72,7 @@ func main() { log.Fatalf("Failed to list changed files: %v\n", err) } - changedReleaseFiles := make([]string, 0, 0) + changedReleaseFiles := make([]string, 0) matcher, err := NewPatternMatcher([]string{args.ReleaseFile}) if err != nil { log.Fatalf("Failed to create pattern matcher for release file: %v\n", err) diff --git a/tool/actions-gh-release/release.go b/tool/actions-gh-release/release.go index b468ab414d..27163d45f2 100644 --- a/tool/actions-gh-release/release.go +++ b/tool/actions-gh-release/release.go @@ -426,7 +426,7 @@ func renderReleaseNote(p ReleaseProposal, cfg ReleaseConfig) []byte { } for _, ctg := range cfg.CommitCategories { - commits := make([]ReleaseCommit, 0, 0) + commits := make([]ReleaseCommit, 0) for _, c := range filteredCommits { if c.CategoryName == ctg.ID { commits = append(commits, c) From b3dacd37fcc48067cfd507f401820fa26b1bd48e Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Thu, 29 May 2025 14:13:30 +0900 Subject: [PATCH 05/10] Remove unnecessary string conversion Signed-off-by: Shinnosuke Sawada-Dazai --- tool/actions-gh-release/release.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tool/actions-gh-release/release.go b/tool/actions-gh-release/release.go index 27163d45f2..c340777699 100644 --- a/tool/actions-gh-release/release.go +++ b/tool/actions-gh-release/release.go @@ -358,7 +358,7 @@ func renderReleaseNote(p ReleaseProposal, cfg ReleaseConfig) []byte { ns[n] = struct{}{} } for k := range ns { - link := fmt.Sprintf("[%s](https://github.com/%s/%s/pull/%s)", k, p.Owner, p.Repo, string(k[1:])) + link := fmt.Sprintf("[%s](https://github.com/%s/%s/pull/%s)", k, p.Owner, p.Repo, k[1:]) c.ReleaseNote = strings.ReplaceAll(c.ReleaseNote, k, link) } } From acc9bd57c9c88b0eda19663a09ad81f8951d2701 Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Thu, 29 May 2025 14:16:42 +0900 Subject: [PATCH 06/10] Fix to correctly call deferred functions log.Fatalf calls os.Exit(1) and deferred functions are not called. This commit changes the _main function to return an integer and call os.Exit from main. Signed-off-by: Shinnosuke Sawada-Dazai --- tool/actions-gh-release/main.go | 44 ++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/tool/actions-gh-release/main.go b/tool/actions-gh-release/main.go index 41afbb1835..109d339c93 100644 --- a/tool/actions-gh-release/main.go +++ b/tool/actions-gh-release/main.go @@ -33,6 +33,10 @@ const ( ) func main() { + os.Exit(_main()) +} + +func _main() int { log.Println("Start running actions-gh-release") ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) @@ -40,17 +44,20 @@ func main() { args, err := parseArgs(os.Args) if err != nil { - log.Fatalf("Failed to parse arguments: %v\n", err) + log.Printf("Failed to parse arguments: %v\n", err) + return 1 } log.Println("Successfully parsed arguments") workspace := os.Getenv("GITHUB_WORKSPACE") if workspace == "" { - log.Fatal("GITHUB_WORKSPACE was not defined") + log.Printf("GITHUB_WORKSPACE was not defined") + return 1 } if err := addSafeDirectory(ctx, gitExecPath, workspace); err != nil { - log.Fatalf("Failed to add %s as a safe directory: %v\n", workspace, err) + log.Printf("Failed to add %s as a safe directory: %v\n", workspace, err) + return 1 } cfg := &githubClientConfig{Token: args.Token} @@ -58,7 +65,8 @@ func main() { event, err := ghClient.parseGitHubEvent(ctx) if err != nil { - log.Fatalf("Failed to parse GitHub event: %v\n", err) + log.Printf("Failed to parse GitHub event: %v\n", err) + return 1 } log.Printf("Successfully parsed GitHub event %s\n\tbase-commit %s\n\thead-commit %s\n", event.Name, @@ -69,13 +77,15 @@ func main() { // Find all changed RELEASE files. changedFiles, err := changedFiles(ctx, gitExecPath, workspace, event.BaseCommit, event.HeadCommit) if err != nil { - log.Fatalf("Failed to list changed files: %v\n", err) + log.Printf("Failed to list changed files: %v\n", err) + return 1 } changedReleaseFiles := make([]string, 0) matcher, err := NewPatternMatcher([]string{args.ReleaseFile}) if err != nil { - log.Fatalf("Failed to create pattern matcher for release file: %v\n", err) + log.Printf("Failed to create pattern matcher for release file: %v\n", err) + return 1 } for _, f := range changedFiles { if matcher.Matches(f) { @@ -85,14 +95,15 @@ func main() { if len(changedReleaseFiles) == 0 { log.Println("Nothing to do since there were no modified release files") - return + return 0 } proposals := make([]ReleaseProposal, 0, len(changedReleaseFiles)) for _, f := range changedReleaseFiles { p, err := buildReleaseProposal(ctx, ghClient, f, gitExecPath, workspace, event) if err != nil { - log.Fatalf("Failed to build release for %s: %v\n", f, err) + log.Printf("Failed to build release for %s: %v\n", f, err) + return 1 } proposals = append(proposals, *p) } @@ -125,19 +136,21 @@ func main() { if len(newProposals) == 0 { log.Printf("All of %d detected releases were already created before so no new release will be created\n", len(proposals)) notify() - return + return 0 } log.Printf("%d releases from %d detected ones were already created before so only %d releases will be created\n", len(existingProposals), len(proposals), len(newProposals)) } releasesJSON, err := json.Marshal(newProposals) if err != nil { - log.Fatalf("Failed to marshal releases: %v\n", err) + log.Printf("Failed to marshal releases: %v\n", err) + return 1 } os.Setenv("GITHUB_OUTPUT", fmt.Sprintf("releases=%s", string(releasesJSON))) if args.OutputReleasesFilePath != "" { if err := os.WriteFile(args.OutputReleasesFilePath, releasesJSON, 0644); err != nil { - log.Fatalf("Failed to write releases JSON to %s: %v\n", args.OutputReleasesFilePath, err) + log.Printf("Failed to write releases JSON to %s: %v\n", args.OutputReleasesFilePath, err) + return 1 } log.Printf("Successfully wrote releases JSON to %s\n", args.OutputReleasesFilePath) } @@ -148,22 +161,25 @@ func main() { for _, p := range newProposals { r, err := ghClient.createRelease(ctx, event.Owner, event.Repo, p) if err != nil { - log.Fatalf("Failed to create release %s: %v\n", p.Tag, err) + log.Printf("Failed to create release %s: %v\n", p.Tag, err) + return 1 } log.Printf("Successfully created a new GitHub release %s\n%s\n", r.GetTagName(), r.GetHTMLURL()) } log.Printf("Successfully created all %d GitHub releases\n", len(newProposals)) - return + return 0 } // Otherwise, just leave a comment to show the changelogs. comment, err := notify() if err != nil { - log.Fatalf("Failed to send comment: %v\n", err) + log.Printf("Failed to send comment: %v\n", err) + return 1 } log.Printf("Successfully commented actions-gh-release result on pull request\n%s\n", *comment.HTMLURL) + return 0 } type arguments struct { From b87bf36d8457db17e9bbc703551c7f854b3286c0 Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Thu, 29 May 2025 14:26:07 +0900 Subject: [PATCH 07/10] Fix lint errors log.Fatal calls os.Exit, so the deferred functions are not called. This commit changes the _main function to return an integer and call os.Exit from main. This is a workaround to fix the lint errors. Signed-off-by: Shinnosuke Sawada-Dazai --- tool/actions-plan-preview/main.go | 67 ++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/tool/actions-plan-preview/main.go b/tool/actions-plan-preview/main.go index c90d6d92fa..87dcc5b997 100644 --- a/tool/actions-plan-preview/main.go +++ b/tool/actions-plan-preview/main.go @@ -45,28 +45,35 @@ const ( ) func main() { + os.Exit(_main()) +} + +func _main() int { log.Println("Start running plan-preview") eventName := os.Getenv("GITHUB_EVENT_NAME") if !isSupportedGitHubEvent(eventName) { - log.Fatal(fmt.Errorf( + log.Printf( "unexpected event %s, only %q, %q and %q event are supported", eventName, pullRequestEventName, commentEventName, pushEventName, - )) + ) + return 1 } args, err := parseArgs(os.Args) if err != nil { - log.Fatal(err) + log.Println(err) + return 1 } log.Println("Successfully parsed arguments") payload, err := os.ReadFile(os.Getenv("GITHUB_EVENT_PATH")) if err != nil { - log.Fatal(fmt.Errorf("failed to read event payload: %v", err)) + log.Printf("failed to read event payload: %v\n", err) + return 1 } ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) @@ -81,11 +88,12 @@ func main() { event, err := parseGitHubEvent(ctx, ghClient.PullRequests, eventName, payload, args.PRNum) if err != nil { - log.Fatal(err) + log.Println(err) + return 1 } log.Printf("Successfully parsed GitHub event\n\tbase-branch %s\n\thead-branch %s\n\thead-commit %s\n", event.BaseBranch, event.HeadBranch, event.HeadCommit) - doComment := func(body string) { + doComment := func(body string) error { comment, err := sendComment( ctx, ghClient.Issues, @@ -95,22 +103,28 @@ func main() { body, ) if err != nil { - log.Fatal(err) + log.Println(err) + return err } log.Printf("Successfully commented plan-preview result on pull request\n%s\n", *comment.HTMLURL) + return nil } if event.PRClosed { - doComment(failureBadgeURL + "\nUnable to run plan-preview for a closed pull request.") - return + if err := doComment(failureBadgeURL + "\nUnable to run plan-preview for a closed pull request."); err != nil { + return 1 + } + return 0 } // TODO: When PR opened, `Mergeable` is nil for calculation. // Here it is not considered for now, but needs to be handled. if event.PRMergeable != nil && !*event.PRMergeable { - doComment(failureBadgeURL + "\nUnable to run plan-preview for an un-mergeable pull request. Please resolve the conficts and try again.") - return + if err := doComment(failureBadgeURL + "\nUnable to run plan-preview for an un-mergeable pull request. Please resolve the conficts and try again."); err != nil { + return 1 + } + return 0 } result, err := retrievePlanPreview( @@ -125,8 +139,11 @@ func main() { args.PipedHandleTimeout, ) if err != nil { - doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()) - log.Fatal(err) + if err := doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()); err != nil { + return 1 + } + log.Println(err) + return 1 } log.Println("Successfully retrieved plan-preview result") @@ -134,28 +151,38 @@ func main() { if result.HasError() { pr, err := getPullRequest(ctx, ghClient.PullRequests, event.Owner, event.Repo, event.PRNumber) if err != nil { - doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()) - log.Fatal(err) + if err := doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()); err != nil { + return 1 + } + log.Println(err) + return 1 } if !pr.GetClosedAt().IsZero() { - doComment(failureBadgeURL + "\nUnable to run plan-preview for a closed pull request.") - return + if err := doComment(failureBadgeURL + "\nUnable to run plan-preview for a closed pull request."); err != nil { + return 1 + } + return 0 } minimizePreviousComment(ctx, ghGraphQLClient, event) body := makeCommentBody(event, result) - doComment(body) + if err := doComment(body); err != nil { + return 1 + } log.Println("Successfully minimized last plan-preview result on pull request") log.Println("plan-preview result has error") - os.Exit(1) + return 1 } minimizePreviousComment(ctx, ghGraphQLClient, event) body := makeCommentBody(event, result) - doComment(body) + if err := doComment(body); err != nil { + return 1 + } + return 0 } type arguments struct { From 4430f56bf46b2000e2c40e0ceaf34dd138bf46f2 Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Thu, 29 May 2025 14:32:19 +0900 Subject: [PATCH 08/10] Fix lint errors Signed-off-by: Shinnosuke Sawada-Dazai --- tool/actions-gh-release/main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tool/actions-gh-release/main.go b/tool/actions-gh-release/main.go index 109d339c93..00908b4e9e 100644 --- a/tool/actions-gh-release/main.go +++ b/tool/actions-gh-release/main.go @@ -117,7 +117,8 @@ func _main() int { if p.Tag != "" { exist, err := ghClient.existRelease(ctx, event.Owner, event.Repo, p.Tag) if err != nil { - log.Fatalf("Failed to check the existence of release for %s: %v\n", p.Tag, err) + log.Printf("Failed to check the existence of release for %s: %v\n", p.Tag, err) + return 1 } if exist { existingProposals = append(existingProposals, p) From 2465b2eda02de67aac7e873629e02018dada12c7 Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Thu, 29 May 2025 15:04:08 +0900 Subject: [PATCH 09/10] Initialize the slice with the correct capacity Signed-off-by: Shinnosuke Sawada-Dazai --- tool/actions-gh-release/main.go | 2 +- tool/actions-gh-release/release.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tool/actions-gh-release/main.go b/tool/actions-gh-release/main.go index 00908b4e9e..b0a6db209b 100644 --- a/tool/actions-gh-release/main.go +++ b/tool/actions-gh-release/main.go @@ -81,7 +81,7 @@ func _main() int { return 1 } - changedReleaseFiles := make([]string, 0) + changedReleaseFiles := make([]string, 0, len(changedFiles)) matcher, err := NewPatternMatcher([]string{args.ReleaseFile}) if err != nil { log.Printf("Failed to create pattern matcher for release file: %v\n", err) diff --git a/tool/actions-gh-release/release.go b/tool/actions-gh-release/release.go index c340777699..07c99c3123 100644 --- a/tool/actions-gh-release/release.go +++ b/tool/actions-gh-release/release.go @@ -426,7 +426,7 @@ func renderReleaseNote(p ReleaseProposal, cfg ReleaseConfig) []byte { } for _, ctg := range cfg.CommitCategories { - commits := make([]ReleaseCommit, 0) + commits := make([]ReleaseCommit, 0, len(filteredCommits)) for _, c := range filteredCommits { if c.CategoryName == ctg.ID { commits = append(commits, c) From 7f14722cdf39c80c6f5e784012420244a4d8888f Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Thu, 29 May 2025 16:10:23 +0900 Subject: [PATCH 10/10] Change return type of doComment to int Signed-off-by: Shinnosuke Sawada-Dazai --- tool/actions-plan-preview/main.go | 38 +++++++++---------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/tool/actions-plan-preview/main.go b/tool/actions-plan-preview/main.go index 87dcc5b997..e4ffc136bf 100644 --- a/tool/actions-plan-preview/main.go +++ b/tool/actions-plan-preview/main.go @@ -93,7 +93,7 @@ func _main() int { } log.Printf("Successfully parsed GitHub event\n\tbase-branch %s\n\thead-branch %s\n\thead-commit %s\n", event.BaseBranch, event.HeadBranch, event.HeadCommit) - doComment := func(body string) error { + doComment := func(body string) int { comment, err := sendComment( ctx, ghClient.Issues, @@ -104,27 +104,21 @@ func _main() int { ) if err != nil { log.Println(err) - return err + return 1 } log.Printf("Successfully commented plan-preview result on pull request\n%s\n", *comment.HTMLURL) - return nil + return 0 } if event.PRClosed { - if err := doComment(failureBadgeURL + "\nUnable to run plan-preview for a closed pull request."); err != nil { - return 1 - } - return 0 + return doComment(failureBadgeURL + "\nUnable to run plan-preview for a closed pull request.") } // TODO: When PR opened, `Mergeable` is nil for calculation. // Here it is not considered for now, but needs to be handled. if event.PRMergeable != nil && !*event.PRMergeable { - if err := doComment(failureBadgeURL + "\nUnable to run plan-preview for an un-mergeable pull request. Please resolve the conficts and try again."); err != nil { - return 1 - } - return 0 + return doComment(failureBadgeURL + "\nUnable to run plan-preview for an un-mergeable pull request. Please resolve the conficts and try again.") } result, err := retrievePlanPreview( @@ -139,9 +133,7 @@ func _main() int { args.PipedHandleTimeout, ) if err != nil { - if err := doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()); err != nil { - return 1 - } + _ = doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()) log.Println(err) return 1 } @@ -151,24 +143,19 @@ func _main() int { if result.HasError() { pr, err := getPullRequest(ctx, ghClient.PullRequests, event.Owner, event.Repo, event.PRNumber) if err != nil { - if err := doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()); err != nil { - return 1 - } + _ = doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()) log.Println(err) return 1 } if !pr.GetClosedAt().IsZero() { - if err := doComment(failureBadgeURL + "\nUnable to run plan-preview for a closed pull request."); err != nil { - return 1 - } - return 0 + return doComment(failureBadgeURL + "\nUnable to run plan-preview for a closed pull request.") } minimizePreviousComment(ctx, ghGraphQLClient, event) body := makeCommentBody(event, result) - if err := doComment(body); err != nil { - return 1 + if code := doComment(body); code != 0 { + return code } log.Println("Successfully minimized last plan-preview result on pull request") @@ -179,10 +166,7 @@ func _main() int { minimizePreviousComment(ctx, ghGraphQLClient, event) body := makeCommentBody(event, result) - if err := doComment(body); err != nil { - return 1 - } - return 0 + return doComment(body) } type arguments struct {