-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
448 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
d365fo.tools/tests/functions/Invoke-D365SDPInstallUDE.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
#> | ||
} | ||
|
||
} |
Oops, something went wrong.