Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Get-OSRepoAvailableVersions #124

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ install:
Install-Module psake -Scope CurrentUser -Force -RequiredVersion 4.7.4
Install-Module PSScriptAnalyzer -Scope CurrentUser -Force
Install-Module platyPS -Scope CurrentUser -Force
Uninstall-Module AzureRM -Force
Install-Module Az.Storage -Scope CurrentUser -Force -AllowClobber

build_script:
- ps: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function Get-OSRepoAvailableVersions

.PARAMETER Application
Specifies which application to retrieve the version
This can be 'PlatformServer', 'ServiceStudio', 'Lifetime'
This can be 'PlatformServer', 'Lifetime', 'DevelopmentEnvironment', 'ServiceStudio', 'IntegrationStudio'

.PARAMETER MajorVersion
Specifies the platform major version
Expand All @@ -24,7 +24,7 @@ function Get-OSRepoAvailableVersions
Get-OSRepoAvailableVersions -Application 'PlatformServer' -MajorVersion '10'

.EXAMPLE
Get the latest available version of the OutSystems 11 development environment
Get the latest available version of the OutSystems 11 Service Studio
Get-OSRepoAvailableVersions -Application 'ServiceStudio' -MajorVersion '11' -Latest

#>
Expand All @@ -33,7 +33,7 @@ function Get-OSRepoAvailableVersions
[OutputType('String')]
param (
[Parameter(Mandatory = $true)]
[ValidateSet('PlatformServer', 'ServiceStudio', 'Lifetime')]
[ValidateSet('PlatformServer', 'Lifetime', 'DevelopmentEnvironment', 'ServiceStudio', 'IntegrationStudio')]
[string]$Application,

[Parameter(Mandatory = $true)]
Expand All @@ -59,7 +59,7 @@ function Get-OSRepoAvailableVersions

try
{
$files = GetAzStorageFileList
$RepoFiles = GetAzStorageFileList
}
catch
{
Expand All @@ -74,33 +74,47 @@ function Get-OSRepoAvailableVersions
{
'PlatformServer'
{
$files = $files | Where-Object -FilterScript { $_ -like "PlatformServer-*" }
$versions = $files -replace 'PlatformServer-', '' -replace '.exe', ''
$AppFiles = $RepoFiles | Where-Object -FilterScript { $_ -like "PlatformServer-*" }
$AppVersions_Strings = $AppFiles -replace 'PlatformServer-', '' -replace '(?<=\d+\.\d+\.\d+\.\d+)\D.*exe', ''
}
'Lifetime'
{
$AppFiles = $RepoFiles | Where-Object -FilterScript { $_ -like "LifeTimeWithPlatformServer-*" }
$AppVersions_Strings = $AppFiles -replace 'LifeTimeWithPlatformServer-', '' -replace '(?<=\d+\.\d+\.\d+\.\d+)\D.*exe', ''
}
'DevelopmentEnvironment'
{
$AppFiles = $RepoFiles | Where-Object -FilterScript { $_ -like "DevelopmentEnvironment-*" }
$AppVersions_Strings = $AppFiles -replace 'DevelopmentEnvironment-', '' -replace '(?<=\d+\.\d+\.\d+\.\d+)\D.*exe', ''
}
'ServiceStudio'
{
$files = $files | Where-Object -FilterScript { $_ -like "DevelopmentEnvironment-*" }
$versions = $files -replace 'DevelopmentEnvironment-', '' -replace '.exe', ''
$AppFiles = $RepoFiles | Where-Object -FilterScript { $_ -like "ServiceStudio-*" }
$AppVersions_Strings = $AppFiles -replace 'ServiceStudio-', '' -replace '(?<=\d+\.\d+\.\d+\.\d+)\D.*exe', ''
}
'Lifetime'
'IntegrationStudio'
{
$files = $files | Where-Object -FilterScript { $_ -like "LifeTimeWithPlatformServer-*" }
$versions = $files -replace 'LifeTimeWithPlatformServer-', '' -replace '.exe', ''
$AppFiles = $RepoFiles | Where-Object -FilterScript { $_ -like "IntegrationStudio-*" }
$AppVersions_Strings = $AppFiles -replace 'IntegrationStudio-', '' -replace '(?<=\d+\.\d+\.\d+\.\d+)\D.*exe', ''
}
}

# Filter only major version and sort desc
$versions = [System.Version[]]($versions | Where-Object -FilterScript { $_ -like "$MajorVersion.*" }) | Sort-Object -Descending
$AppVersions = [System.Version[]]($AppVersions_Strings | Where-Object -FilterScript { $_ -like "$MajorVersion.*" }) | Sort-Object -Descending

if ($Latest.IsPresent)
if ( ($AppVersions.Count -gt 0) -and $Latest.IsPresent)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Returning the latest version"
return $versions[0].ToString()
return $AppVersions[0].ToString()
}
else
elseif ($AppVersions.Count -gt 0)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Returning $($versions.Count) versions"
return $versions | ForEach-Object -Process { $_.ToString() }
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Returning $($AppVersions.Count) versions"
return $AppVersions | ForEach-Object -Process { $_.ToString() }
}
else {
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "No versions returned."
return $null
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Outsystems.SetupTools/Lib/PlatformSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1004,10 +1004,10 @@ function GetAzStorageFileList()
$stoContainer = ([System.Uri]$OSRepoURL).Segments[1]
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "Getting file list from storage account $stoAccountName container $stoContainer"

$stoCtx = New-AzureStorageContext -StorageAccountName $stoAccountName -Anonymous -ErrorAction Stop
$stoCtx = New-AzStorageContext -StorageAccountName $stoAccountName -Anonymous -ErrorAction Stop

$ProgressPreference = "SilentlyContinue"
$sources = $(Get-AzureStorageBlob -Container $stoContainer -Context $stoCtx -ErrorAction Stop).Name
$sources = $(Get-AzStorageBlob -Container $stoContainer -Context $stoCtx -ErrorAction Stop).Name

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "Returning $($sources.Count)"

Expand Down
2 changes: 1 addition & 1 deletion src/Outsystems.SetupTools/OutSystems.SetupTools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Description = 'Tools for installing and manage the OutSystems platform installat
ProcessorArchitecture = 'Amd64'

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @('AzureRM.Storage')
RequiredModules = @('Az.Storage')

# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = @(
Expand Down
40 changes: 40 additions & 0 deletions test/unit/Get-OSRepoAvailableVersions.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Get-Module Outsystems.SetupTools | Remove-Module -Force
Import-Module $PSScriptRoot\..\..\src\Outsystems.SetupTools -Force -ArgumentList $false, '', '', $false

InModuleScope -ModuleName OutSystems.SetupTools {
Describe 'Get-OSRepoAvailableVersions Tests' {

Context 'When getting Platform Server versions' {

$result = Get-OSRepoAvailableVersions -Application 'PlatformServer' -MajorVersion '11' -ErrorVariable err -ErrorAction SilentlyContinue

It 'Should not have errors' { $err.Count | Should Be 0 }
It 'Should return at least one version' { $result.Count | Should BeGreaterThan 0 }
}

Context 'When getting Service Studio versions' {

$result = Get-OSRepoAvailableVersions -Application 'ServiceStudio' -MajorVersion '11' -ErrorVariable err -ErrorAction SilentlyContinue

It 'Should not have errors' { $err.Count | Should Be 0 }
It 'Should return at least one version' { $result.Count | Should BeGreaterThan 0 }
}

Context 'When getting Integration Studio versions' {

$result = Get-OSRepoAvailableVersions -Application 'IntegrationStudio' -MajorVersion '11' -ErrorVariable err -ErrorAction SilentlyContinue

It 'Should not have errors' { $err.Count | Should Be 0 }
It 'Should return at least one version' { $result.Count | Should BeGreaterThan 0 }
}

Context 'When getting Lifetime versions' {

$result = Get-OSRepoAvailableVersions -Application 'Lifetime' -MajorVersion '11' -ErrorVariable err -ErrorAction SilentlyContinue

It 'Should not have errors' { $err.Count | Should Be 0 }
It 'Should return at least one version' { $result.Count | Should BeGreaterThan 0 }
}

}
}
Empty file.