Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
Splaxi committed Sep 26, 2024
2 parents d8bac46 + 83f5d58 commit 2b6abc3
Show file tree
Hide file tree
Showing 10 changed files with 448 additions and 22 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/Release-Management.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
workflow_dispatch:
inputs:
gallery_publish:
description: "Publish to the PowerShell Gallery?"
default: true
required: false
type: boolean
github_release:
description: "Create a GitHub release?"
default: true
required: false
type: boolean
module_validation:
description: "Module validation?"
default: true
required: false
type: boolean

jobs:
call-tmpl-build-release:
uses: fh-inway/d365.psmodule-alm/.github/workflows/tmpl-build-release.yml@main
with:
module: 'd365fo.tools'
skippublish: not(${{ inputs.gallery_publish }})
skipghrelease: not(${{ inputs.github_release }})
skipValidation: not(${{ inputs.module_validation }})
secrets:
apikey: ${{ secrets.ApiKey }}
65 changes: 59 additions & 6 deletions d365fo.tools/bin/d365fo.tools-index.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions d365fo.tools/d365fo.tools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
'Invoke-D365RunbookAnalyzer',

'Invoke-D365SDPInstall',
'Invoke-D365SDPInstallUDE',
'Invoke-D365SCDPBundleInstall',
'Invoke-D365SeleniumDownload',
'Invoke-D365SysFlushAodCache',
Expand Down
20 changes: 10 additions & 10 deletions d365fo.tools/functions/get-d365sdpdetails.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function Get-D365SDPDetails {
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($zipEntry, $pathHotfix, $true)


foreach ($nuget in $($zipArch.Entries | Where-Object Fullname -like "AOSService\Packages\*.nupkg")) {
foreach ($nuget in $($zipArch.Entries | Where-Object Fullname -like "AOSService[\/]Packages[\/]*.nupkg")) {
$pathNuget = "$pathWorkDirectory\$($nuget.name).zip"

# The nuget file contains module name in correct casing
Expand Down Expand Up @@ -144,16 +144,16 @@ function Get-D365SDPDetails {
Version = $moduleSpec.package.metadata.version
}
)
}

# Clear out any inner zip archive objects from memory
if ($zipNuget) {
$zipArch.Dispose()
}

if ($fileNuget) {
$file.Close()
$file.Dispose()
# Clear out any inner zip archive objects from memory
if ($zipNuget) {
$zipNuget.Dispose()
}

if ($fileNuget) {
$fileNuget.Close()
$fileNuget.Dispose()
}
}

[xml] $hotfix = Get-Content -Path "$pathWorkDirectory\HotfixInstallationInfo.xml" -Raw
Expand Down
25 changes: 22 additions & 3 deletions d365fo.tools/functions/invoke-d365sdpinstall.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

<#
.SYNOPSIS
Invoke the AxUpdateInstaller.exe file from Software Deployable Package (SDP)
Install a Software Deployable Package (SDP)
.DESCRIPTION
A cmdlet that wraps some of the cumbersome work into a streamlined process.
The process are detailed in the Microsoft documentation here:
The process for a legacy (i.e. non unified) environment are detailed in the Microsoft documentation here:
https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/deployment/install-deployable-package
.PARAMETER Path
Expand Down Expand Up @@ -69,6 +69,9 @@
.PARAMETER UseExistingTopologyFile
Use this switch to indicate that the topology file is already updated and should not be updated again.
.PARAMETER UnifiedDevelopmentEnvironment
Use this switch to install the package in a Unified Development Environment (UDE).
.EXAMPLE
PS C:\> Invoke-D365SDPInstall -Path "c:\temp\package.zip" -QuickInstallAll
Expand Down Expand Up @@ -114,12 +117,20 @@
Run all manual steps in one single operation using the MyTopology.xml file. The topology file is not updated.
.EXAMPLE
PS C:\> Invoke-D365SDPInstall -Path "c:\temp\" -MetaDataDir "c:\MyRepository\Metadata" -UnifiedDevelopmentEnvironment
Install the modules contained in the c:\temp\ directory into the c:\MyRepository\Metadata directory.
.NOTES
Author: Tommy Skaue (@skaue)
Author: Mötz Jensen (@Splaxi)
Inspired by blogpost http://dev.goshoom.net/en/2016/11/installing-deployable-packages-with-powershell/
.LINK
Invoke-D365SDPInstallUDE
#>
function Invoke-D365SDPInstall {
[CmdletBinding(DefaultParameterSetName = 'QuickInstall')]
Expand Down Expand Up @@ -157,8 +168,16 @@ function Invoke-D365SDPInstall {

[string] $TopologyFile = "DefaultTopologyData.xml",

[switch] $UseExistingTopologyFile
[switch] $UseExistingTopologyFile,

[Parameter(ParameterSetName = 'UDEInstall')]
[switch] $UnifiedDevelopmentEnvironment
)

if ($UnifiedDevelopmentEnvironment) {
Invoke-D365SDPInstallUDE -Path $Path -MetaDataDir $MetaDataDir -LogPath $LogPath
return
}

if ((Get-Process -Name "devenv" -ErrorAction SilentlyContinue).Count -gt 0) {
Write-PSFMessage -Level Host -Message "It seems that you have a <c='em'>Visual Studio</c> running. Please ensure <c='em'>exit</c> Visual Studio and run the cmdlet again."
Expand Down
117 changes: 117 additions & 0 deletions d365fo.tools/functions/invoke-d365sdpinstallude.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@

<#
.SYNOPSIS
Install a Software Deployable Package (SDP) in a unified development environment
.DESCRIPTION
A cmdlet that wraps some of the cumbersome work into a streamlined process.
It first checks if the package is a zip file and extracts it if necessary.
Then it checks if the package contains the necessary files and modules.
Finally, it extracts the module zip files into the metadata directory.
.PARAMETER Path
Path to the package that you want to install into the environment
The cmdlet supports a path to a zip-file or directory with the unpacked contents.
.PARAMETER MetaDataDir
The path to the meta data directory for the environment
.PARAMETER LogPath
The path where the log file(s) will be saved
.EXAMPLE
PS C:\> Invoke-D365SDPInstallUDE -Path "c:\temp\package.zip" -MetaDataDir "c:\MyRepository\Metadata"
This will install the modules contained in the c:\temp\package.zip file into the c:\MyRepository\Metadata directory.
.NOTES
Author: Florian Hopfner (@FH-Inway)
#>
function Invoke-D365SDPInstallUDE {
param (
[Parameter(Mandatory = $True, Position = 1 )]
[Alias('Hotfix')]
[Alias('File')]
[string] $Path,

[Parameter(Mandatory = $true, Position = 2 )]
[string] $MetaDataDir,

[Alias('LogDir')]
[string] $LogPath = $(Join-Path -Path $Script:DefaultTempPath -ChildPath "Logs\SdpInstall")
)

if ((Get-Process -Name "devenv" -ErrorAction SilentlyContinue).Count -gt 0) {
Write-PSFMessage -Level Host -Message "It seems that you have a <c='em'>Visual Studio</c> running. Please ensure <c='em'>exit</c> Visual Studio and run the cmdlet again."
Stop-PSFFunction -Message "Stopping because of running Visual Studio."
return
}

Invoke-TimeSignal -Start


#Test if input is a zipFile that needs to be extracted first
if ($Path.EndsWith(".zip")) {
Unblock-File -Path $Path

$extractedPath = $path.Remove($path.Length - 4)
if (!(Test-Path $extractedPath)) {
Expand-Archive -Path $Path -DestinationPath $extractedPath

#lets work with the extracted directory from now on
$Path = $extractedPath
}
}

# Input is a relative path which needs to be converted to an absolute path.
# see https://powershellmagazine.com/2013/01/16/pstip-check-if-the-path-is-relative-or-absolute/
if (-not ([System.IO.Path]::IsPathRooted($Path) -or (Split-Path -Path $Path -IsAbsolute))) {
$currentPath = Get-Location
# https://stackoverflow.com/a/13847304/2720554
$absolutePath = Join-Path -Path $currentPath -ChildPath $Path
$absolutePath = [System.IO.Path]::GetFullPath($absolutePath)
Write-PSFMessage -Level Verbose "Updating path to '$absolutePath' as relative paths are not supported"
$Path = $absolutePath
}

Get-ChildItem -Path $Path -Recurse | Unblock-File
$packageDetails = Get-D365SDPDetails -Path $Path

$packagesFolder = "$Path\AOSService\Packages"
$filesFolder = Get-ChildItem -Path $packagesFolder -Directory -Filter "files"
if ($filesFolder.Count -eq 0) {
Write-PSFMessage -Level Host -Message "No /AOSService/Packages/files folder found in the package. Please ensure that the package is extracted correctly."
Stop-PSFFunction -Message "Stopping because of missing files folder."
return
}

$zipFiles = Get-ChildItem -Path $filesFolder.FullName -File -Filter "*.zip"
if ($zipFiles.Count -eq 0) {
Write-PSFMessage -Level Host -Message "No module zip files found in the package. Please ensure that the package is extracted correctly."
Stop-PSFFunction -Message "Stopping because of missing zip files."
return
}

$numberOfInstalledModules = 0
$packageDetails.Modules | ForEach-Object {
$moduleZip = $zipFiles | Where-Object Name -eq "dynamicsax-$($_.Name).$($_.Version).zip"
if (-not $moduleZip) {
Write-PSFMessage -Level Host -Message "No module zip file found for module $($_.Name). Please ensure that the package is extracted correctly."
Stop-PSFFunction -Message "Stopping because of missing module zip file."
return
}

# Unzip to $MetaDataDir
$moduleZipPath = Join-Path -Path $MetaDataDir -ChildPath $($_.Name)
Expand-Archive -Path $moduleZip.FullName -DestinationPath $moduleZipPath
Write-PSFMessage -Level Verbose -Message "Unzipped module $($_.Name) to $moduleZipPath"
$numberOfInstalledModules++
}

Write-PSFMessage -Level Host -Message "Installed $numberOfInstalledModules module(s) into $MetaDataDir"

Invoke-TimeSignal -End

}
21 changes: 20 additions & 1 deletion d365fo.tools/tests/functions/Invoke-D365SDPInstall.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Describe "Ensuring unchanged command signature" {
It "should have the expected parameter sets" {
(Get-Command Invoke-D365SDPInstall).ParameterSets.Name | Should -Be 'QuickInstall', 'DevInstall', 'Manual'
(Get-Command Invoke-D365SDPInstall).ParameterSets.Name | Should -Be 'QuickInstall', 'DevInstall', 'Manual', 'UDEInstall'
}

It 'Should have the expected parameter Path' {
Expand Down Expand Up @@ -167,6 +167,19 @@
$parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False
$parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False
}
It 'Should have the expected parameter UnifiedDevelopmentEnvironment' {
$parameter = (Get-Command Invoke-D365SDPInstall).Parameters['UnifiedDevelopmentEnvironment']
$parameter.Name | Should -Be 'UnifiedDevelopmentEnvironment'
$parameter.ParameterType.ToString() | Should -Be System.Management.Automation.SwitchParameter
$parameter.IsDynamic | Should -Be $False
$parameter.ParameterSets.Keys | Should -Be 'UDEInstall'
$parameter.ParameterSets.Keys | Should -Contain 'UDEInstall'
$parameter.ParameterSets['UDEInstall'].IsMandatory | Should -Be $False
$parameter.ParameterSets['UDEInstall'].Position | Should -Be -2147483648
$parameter.ParameterSets['UDEInstall'].ValueFromPipeline | Should -Be $False
$parameter.ParameterSets['UDEInstall'].ValueFromPipelineByPropertyName | Should -Be $False
$parameter.ParameterSets['UDEInstall'].ValueFromRemainingArguments | Should -Be $False
}
}

Describe "Testing parameterset QuickInstall" {
Expand All @@ -187,5 +200,11 @@
Manual -Path -MetaDataDir -Command -Step -RunbookId -LogPath -ShowOriginalProgress -OutputCommandOnly -TopologyFile -UseExistingTopologyFile
#>
}
Describe "Testing parameterset UDEInstall" {
<#
UDEInstall -Path
UDEInstall -Path -MetaDataDir -Step -RunbookId -LogPath -ShowOriginalProgress -OutputCommandOnly -TopologyFile -UseExistingTopologyFile -UnifiedDevelopmentEnvironment
#>
}

}
62 changes: 62 additions & 0 deletions d365fo.tools/tests/functions/Invoke-D365SDPInstallUDE.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Describe "Invoke-D365SDPInstallUDE Unit Tests" -Tag "Unit" {
BeforeAll {
# Place here all things needed to prepare for the tests
}
AfterAll {
# Here is where all the cleanup tasks go
}

Describe "Ensuring unchanged command signature" {
It "should have the expected parameter sets" {
(Get-Command Invoke-D365SDPInstallUDE).ParameterSets.Name | Should -Be '__AllParameterSets'
}

It 'Should have the expected parameter Path' {
$parameter = (Get-Command Invoke-D365SDPInstallUDE).Parameters['Path']
$parameter.Name | Should -Be 'Path'
$parameter.ParameterType.ToString() | Should -Be System.String
$parameter.IsDynamic | Should -Be $False
$parameter.ParameterSets.Keys | Should -Be '__AllParameterSets'
$parameter.ParameterSets.Keys | Should -Contain '__AllParameterSets'
$parameter.ParameterSets['__AllParameterSets'].IsMandatory | Should -Be $True
$parameter.ParameterSets['__AllParameterSets'].Position | Should -Be 1
$parameter.ParameterSets['__AllParameterSets'].ValueFromPipeline | Should -Be $False
$parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False
$parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False
}
It 'Should have the expected parameter MetaDataDir' {
$parameter = (Get-Command Invoke-D365SDPInstallUDE).Parameters['MetaDataDir']
$parameter.Name | Should -Be 'MetaDataDir'
$parameter.ParameterType.ToString() | Should -Be System.String
$parameter.IsDynamic | Should -Be $False
$parameter.ParameterSets.Keys | Should -Be '__AllParameterSets'
$parameter.ParameterSets.Keys | Should -Contain '__AllParameterSets'
$parameter.ParameterSets['__AllParameterSets'].IsMandatory | Should -Be $True
$parameter.ParameterSets['__AllParameterSets'].Position | Should -Be 2
$parameter.ParameterSets['__AllParameterSets'].ValueFromPipeline | Should -Be $False
$parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False
$parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False
}
It 'Should have the expected parameter LogPath' {
$parameter = (Get-Command Invoke-D365SDPInstallUDE).Parameters['LogPath']
$parameter.Name | Should -Be 'LogPath'
$parameter.ParameterType.ToString() | Should -Be System.String
$parameter.IsDynamic | Should -Be $False
$parameter.ParameterSets.Keys | Should -Be '__AllParameterSets'
$parameter.ParameterSets.Keys | Should -Contain '__AllParameterSets'
$parameter.ParameterSets['__AllParameterSets'].IsMandatory | Should -Be $False
$parameter.ParameterSets['__AllParameterSets'].Position | Should -Be -2147483648
$parameter.ParameterSets['__AllParameterSets'].ValueFromPipeline | Should -Be $False
$parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False
$parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False
}
}

Describe "Testing parameterset __AllParameterSets" {
<#
__AllParameterSets -Path -MetaDataDir
__AllParameterSets -Path -MetaDataDir -LogPath
#>
}

}
Loading

0 comments on commit 2b6abc3

Please sign in to comment.