diff --git a/bundle/deploy/state.go b/bundle/deploy/state.go index 97048811..4f2bc4ee 100644 --- a/bundle/deploy/state.go +++ b/bundle/deploy/state.go @@ -12,6 +12,7 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/libs/fileset" "github.com/databricks/cli/libs/vfs" + "github.com/google/uuid" ) const DeploymentStateFileName = "deployment.json" @@ -46,6 +47,9 @@ type DeploymentState struct { // Files is a list of files which has been deployed as part of this deployment. Files Filelist `json:"files"` + + // UUID uniquely identifying the deployment. + ID uuid.UUID `json:"id"` } // We use this entry type as a proxy to fs.DirEntry. diff --git a/bundle/deploy/state_update.go b/bundle/deploy/state_update.go index bfdb308c..9ab1bacf 100644 --- a/bundle/deploy/state_update.go +++ b/bundle/deploy/state_update.go @@ -14,6 +14,7 @@ import ( "github.com/databricks/cli/internal/build" "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/log" + "github.com/google/uuid" ) type stateUpdate struct { @@ -46,6 +47,11 @@ func (s *stateUpdate) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnost } state.Files = fl + // Generate a UUID for the deployment, if one does not already exist + if state.ID == uuid.Nil { + state.ID = uuid.New() + } + statePath, err := getPathToStateFile(ctx, b) if err != nil { return diag.FromErr(err) diff --git a/bundle/deploy/state_update_test.go b/bundle/deploy/state_update_test.go index ed72439d..2982546d 100644 --- a/bundle/deploy/state_update_test.go +++ b/bundle/deploy/state_update_test.go @@ -13,6 +13,7 @@ import ( "github.com/databricks/cli/libs/fileset" "github.com/databricks/cli/libs/vfs" "github.com/databricks/databricks-sdk-go/service/iam" + "github.com/google/uuid" "github.com/stretchr/testify/require" ) @@ -88,6 +89,9 @@ func TestStateUpdate(t *testing.T) { }, }) require.Equal(t, build.GetInfo().Version, state.CliVersion) + + // Valid non-empty UUID is generated. + require.NotEqual(t, uuid.Nil, state.ID) } func TestStateUpdateWithExistingState(t *testing.T) { @@ -109,6 +113,7 @@ func TestStateUpdateWithExistingState(t *testing.T) { LocalPath: "bar/t1.py", }, }, + ID: uuid.MustParse("123e4567-e89b-12d3-a456-426614174000"), } data, err := json.Marshal(state) @@ -135,4 +140,7 @@ func TestStateUpdateWithExistingState(t *testing.T) { }, }) require.Equal(t, build.GetInfo().Version, state.CliVersion) + + // Existing UUID is not overwritten. + require.Equal(t, uuid.MustParse("123e4567-e89b-12d3-a456-426614174000"), state.ID) }