From 9e4dec89d3e6cf6d79f23a05fe2e55cabce702a7 Mon Sep 17 00:00:00 2001 From: Mark Garner Date: Tue, 10 Dec 2024 13:51:40 -0600 Subject: [PATCH] bump --- .github/workflows/deploy.yml | 2 -- Deploy-FabricItems.ps1 | 50 +++++++++++++++++++++++++++++++++ deploy.ps1 | 54 ++---------------------------------- 3 files changed, 53 insertions(+), 53 deletions(-) create mode 100644 Deploy-FabricItems.ps1 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index cc88371..020d5fa 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -32,8 +32,6 @@ jobs: run: | Install-Module Az -Force Import-Module Az.Accounts -Force - Install-Module FabricPS -Force - Import-Module FabricPS -Force - name: Connect with SPN shell: pwsh diff --git a/Deploy-FabricItems.ps1 b/Deploy-FabricItems.ps1 new file mode 100644 index 0000000..579f70c --- /dev/null +++ b/Deploy-FabricItems.ps1 @@ -0,0 +1,50 @@ +function Deploy-FabricItems { + param ( + [string]$DestinationWorkspaceId, + + [ValidateSet("Notebook")] + [string]$Type + ) + + # Get all items of the specified type in the destination workspace + $items = Get-FabricItems -Type $Type -WorkspaceId $DestinationWorkspaceId + + # Get all directories in the current directory that end with .Notebook + $itemDirs = Get-ChildItem -Directory | Where-Object { $_.Name -like "*.$Type" } + + # Loop through each directory in the source which is a notebook + foreach ($dir in $itemDirs) { + + # grab the item name, which is before the '.' in the directory name + $ItemName = $dir.Name.Split('.')[0] + + $existingItem = $items.value | Where-Object { $_.DisplayName -eq $ItemName } + + # Check if the notebook already exists in the destination workspace + if ($null -eq $existingItem) { + + $newItem = New-FabricItem ` + -WorkspaceId $DestinationWorkspaceId ` + -DisplayName $ItemName ` + -Type $Type + + # Set the notebookToUpdateId to the new notebook's Id so I can set the payload + $itemToUpdateId = $newItem.Id + } else { + # Set the notebookToUpdateId to the existing notebook's Id so I can set the payload + $itemToUpdateId = $existingItem.Id + } + + if ($Type -eq 'Notebook') { + $payload = Get-NotebookDefinitionPayload -dir $dir + } + + Update-FabricItemDefinition ` + -WorkspaceId $DestinationWorkspaceId ` + -ItemId $itemToUpdateId ` + -Definition $payload + + # todo - compare the list of notebooks in the destination that are in the source code + # if the notebook is not in the source code, delete it from the destination + } +} diff --git a/deploy.ps1 b/deploy.ps1 index c806074..e8a65b8 100644 --- a/deploy.ps1 +++ b/deploy.ps1 @@ -1,56 +1,8 @@ -function Deploy-FabricItems { - param ( - [string]$DestinationWorkspaceId, - - [ValidateSet("Notebook")] - [string]$Type - ) - - # Get all items of the specified type in the destination workspace - $items = Get-FabricItems -Type $Type -WorkspaceId $DestinationWorkspaceId - - # Get all directories in the current directory that end with .Notebook - $itemDirs = Get-ChildItem -Directory | Where-Object { $_.Name -like "*.$Type" } - - # Loop through each directory in the source which is a notebook - foreach ($dir in $itemDirs) { - - # grab the item name, which is before the '.' in the directory name - $ItemName = $dir.Name.Split('.')[0] - - $existingItem = $items.value | Where-Object { $_.DisplayName -eq $ItemName } - - # Check if the notebook already exists in the destination workspace - if ($null -eq $existingItem) { - - $newItem = New-FabricItem ` - -WorkspaceId $DestinationWorkspaceId ` - -DisplayName $ItemName ` - -Type $Type - - # Set the notebookToUpdateId to the new notebook's Id so I can set the payload - $itemToUpdateId = $newItem.Id - } else { - # Set the notebookToUpdateId to the existing notebook's Id so I can set the payload - $itemToUpdateId = $existingItem.Id - } - - if ($Type -eq 'Notebook') { - $payload = Get-NotebookDefinitionPayload -dir $dir - } - - Update-FabricItemDefinition ` - -WorkspaceId $DestinationWorkspaceId ` - -ItemId $itemToUpdateId ` - -Definition $payload - - # todo - compare the list of notebooks in the destination that are in the source code - # if the notebook is not in the source code, delete it from the destination - } -} - Install-Module FabricPS -Force Import-Module FabricPS -Force +Get-InstalledModule FabricPS + +. ./Deploy-FabricItems.ps1 # hard coded workspace id for now $destinationWorkspaceId = 'f4a80368-71ee-4e0f-8734-1e3c32e28d2a'