diff --git a/README.md b/README.md index bbfead4..343b362 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,10 @@ And finally some great PowerShell community members for their feedback and sugge ## Change Log +v1.1.3 - 2024-03-29 +* Bug fixes: + * [Fix for actions that don't have a runafter property](https://github.com/stefanstranger/logicappdocs/issues/31) + v1.1.2 - 2023-08-18 * Bug fixes: * [Fix for actions with multiple runafter properties](https://github.com/stefanstranger/logicappdocs/issues/23) diff --git a/src/Helper.ps1 b/src/Helper.ps1 index f5034e5..a7d8572 100644 --- a/src/Helper.ps1 +++ b/src/Helper.ps1 @@ -15,19 +15,34 @@ Function Get-Action { foreach ($key in $Actions.PSObject.Properties.Name) { $action = $Actions.$key $actionName = $key -replace '[ |(|)|@]', '_' + Write-Verbose ('Action {0}' -f $actionName) + Write-Verbose ('Object {0}' -f $($action | ConvertTo-Json -Depth 10 )) # new runafter code - $runAfter = if (![string]::IsNullOrWhitespace($action.runafter)) { - $action.runAfter.PSObject.Properties.Name -replace '[ |(|)|@]', '_' - } - elseif (([string]::IsNullOrWhitespace($action.runafter)) -and $Parent) { - # if Runafter is empty but has parent use parent. - $Parent -replace '(-False|-True)', '' + if ($action | Get-Member -MemberType Noteproperty -Name 'runafter') { + $runAfter = if (![string]::IsNullOrWhitespace($action.runafter)) { + $action.runAfter.PSObject.Properties.Name -replace '[ |(|)|@]', '_' + } + elseif (([string]::IsNullOrWhitespace($action.runafter)) -and $Parent) { + # if Runafter is empty but has parent use parent. + $Parent -replace '(-False|-True)', '' + } + else { + # if Runafter is empty and has no parent use null. + $null + } } else { - # if Runafter is empty and has no parent use null. - $null - } + Write-Warning ('Action {0} has no runafter property' -f $actionName) + #Set runafter to parent if parent is not null + if ($Parent) { + $runAfter = $Parent + } + else { + $runAfter = $null + } + } + $inputs = if ($action | Get-Member -MemberType Noteproperty -Name 'inputs') { $($action.inputs) diff --git a/src/New-LogicAppDoc.ps1 b/src/New-LogicAppDoc.ps1 index 816ae48..0d6379a 100644 --- a/src/New-LogicAppDoc.ps1 +++ b/src/New-LogicAppDoc.ps1 @@ -41,7 +41,7 @@ $WarningPreference = 'SilentlyContinue' Author: Stefan Stranger Github: https://github.com/stefanstranger/logicappdocs -Version: 1.1.2 +Version: 1.1.3 "@.foreach({ Write-Host $_ -ForegroundColor Magenta diff --git a/src/New-PowerAutomateDoc.ps1 b/src/New-PowerAutomateDoc.ps1 index d5cdf7f..fec5923 100644 --- a/src/New-PowerAutomateDoc.ps1 +++ b/src/New-PowerAutomateDoc.ps1 @@ -8,6 +8,9 @@ Param( ParameterSetName = 'PowerAutomate')] [string]$PowerAutomateName, + [Parameter(Mandatory = $false)] + [string]$FilePath, + [Parameter(Mandatory = $false)] [string]$OutputPath = (Get-Location).Path ) @@ -27,7 +30,7 @@ $WarningPreference = 'SilentlyContinue' Author: Stefan Stranger Github: https://github.com/stefanstranger/logicappdocs -Version: 1.1.2 +Version: 1.1.3 "@.foreach({ Write-Host $_ -ForegroundColor Magenta @@ -106,28 +109,40 @@ Function Create-ExportPackage { #region Main Script -#region login to Power Automate and get PowerAutomate Flow -Write-Host ('Login to Power Automate and get PowerAutomate Flow') -ForegroundColor Green -Get-Flow -EnvironmentName $EnvironmentName | Where-Object { $_.DisplayName -eq $PowerAutomateName } -OutVariable PowerAutomateFlow -#endregion +if (!($FilePath)) { + #region login to Power Automate and get PowerAutomate Flow + Write-Host ('Login to Power Automate and get PowerAutomate Flow') -ForegroundColor Green + Get-Flow -EnvironmentName $EnvironmentName | Where-Object { $_.DisplayName -eq $PowerAutomateName } -OutVariable PowerAutomateFlow + #endregion -#region Create PowerAutomate Flow Export Package -Write-Host ('Create PowerAutomate Flow Export Package') -ForegroundColor Green -Create-ExportPackage -Flow $PowerAutomateFlow -OutVariable packageDownload -#endregion + #region Create PowerAutomate Flow Export Package + Write-Host ('Create PowerAutomate Flow Export Package') -ForegroundColor Green + Create-ExportPackage -Flow $PowerAutomateFlow -OutVariable packageDownload + #endregion -#region download PowerAutomate Flow Export Package -Write-Host ('Download PowerAutomate Flow Export Package') -ForegroundColor Green -Start-BitsTransfer -Source $($packageDownload.packageLink.value) -Destination (Join-Path $($env:TEMP) ('{0}.zip' -f $($PowerAutomateFlow.DisplayName.Split([IO.Path]::GetInvalidFileNameChars()) -join '_'))) -#endregion + #region download PowerAutomate Flow Export Package + Write-Host ('Download PowerAutomate Flow Export Package') -ForegroundColor Green + Start-BitsTransfer -Source $($packageDownload.packageLink.value) -Destination (Join-Path $($env:TEMP) ('{0}.zip' -f $($PowerAutomateFlow.DisplayName.Split([IO.Path]::GetInvalidFileNameChars()) -join '_'))) + #endregion + + $zipPath = (Join-Path $($env:TEMP) ('{0}.zip' -f $($PowerAutomateFlow.DisplayName.Split([IO.Path]::GetInvalidFileNameChars()) -join '_'))) + $packageName = $($packagedownload.resources.psobject.Properties.name[0]) +} +else { + $zipPath = $FilePath +} #region Unzip PowerAutomate Flow Export Package Write-Host ('Unzip PowerAutomate Flow Export Package') -ForegroundColor Green -Expand-Archive -LiteralPath (Join-Path $($env:TEMP) ('{0}.zip' -f $($PowerAutomateFlow.DisplayName.Split([IO.Path]::GetInvalidFileNameChars()) -join '_'))) -DestinationPath $($env:TEMP) -Force +Expand-Archive -LiteralPath $zipPath -DestinationPath $($env:TEMP) -Force +if ($FilePath) { + #Find the package name from the unzipped folder + $packageName = (Get-ChildItem -Path $($env:TEMP) -Recurse -Filter 'definition.json' -ErrorAction SilentlyContinue | Sort-Object -Property CreationTime -Descending | Select-Object -First 1).Directory.BaseName +} #endregion #region refactor PowerAutomate Flow definition.json to align with LogicApp expected format -$PowerAutomateFlowJson = Get-Content -Path (Join-Path $($env:TEMP) ('Microsoft.Flow\flows\{0}\definition.json' -f $($packagedownload.resources.psobject.Properties.name[0]))) -Raw | ConvertFrom-Json +$PowerAutomateFlowJson = Get-Content -Path (Join-Path $($env:TEMP) ('Microsoft.Flow\flows\{0}\definition.json' -f $($packageName))) -Raw | ConvertFrom-Json $PowerAutomateFlowDefinition = $PowerAutomateFlowJson.properties.definition #endregion @@ -218,12 +233,12 @@ $InputObject = [pscustomobject]@{ $options = New-PSDocumentOption -Option @{ 'Markdown.UseEdgePipes' = 'Always'; 'Markdown.ColumnPadding' = 'Single' }; $null = [PSDocs.Configuration.PSDocumentOption]$Options $invokePSDocumentSplat = @{ - Path = $templatePath - Name = $templateName - InputObject = $InputObject - Culture = 'en-us' - Option = $options - OutputPath = $OutputPath + Path = $templatePath + Name = $templateName + InputObject = $InputObject + Culture = 'en-us' + Option = $options + OutputPath = $OutputPath InstanceName = $($PowerAutomateName.Split([IO.Path]::GetInvalidFileNameChars()) -join '_') } $markDownFile = Invoke-PSDocument @invokePSDocumentSplat diff --git a/tests/Test-PowerAutomateDocLocal.ps1 b/tests/Test-PowerAutomateDocLocal.ps1 new file mode 100644 index 0000000..2d6ac45 --- /dev/null +++ b/tests/Test-PowerAutomateDocLocal.ps1 @@ -0,0 +1,14 @@ +<# + Script to test the PowerShell script New-PowerAutomateDoc.ps1 using a json file with the Logic App Workflow configuration +#> + +$params = @{ + EnvironmentName = '839eace6-59ab-4243-97ec-a5b8fcc104e4' + PowerAutomateName = 'LocalPowerAutomate' + OutputPath = $($env:TEMP) + FilePath = 'c:\temp\DevSecOpsCapabilityFlow_20240328153930.zip' + Verbose = $true + Debug = $true +} + +. ..\src\New-PowerAutomateDoc.ps1 @params \ No newline at end of file