Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions _shared/.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ task PrepareModule {

# Synopsis: Versions package with giving or timestamped value
task VersionModule {
$dateStamp = Get-Date -f "yyyyMMdd"
$timeStamp = Get-Date -f "HHmmss"
$dateStamp = [System.DateTime]::UtcNow.ToString("yyyyMMdd")
$timeStamp = [System.DateTime]::UtcNow.ToString("HHmmss")

$stamp = "$dateStamp.$timeStamp"

Expand All @@ -116,7 +116,7 @@ task VersionModule {
Write-Build Green " using APPVEYOR versioning for branch: $($env:APPVEYOR_REPO_BRANCH)"

## 1902.build-no
$stamp = Get-Date -f "yyMM"
$stamp = [System.DateTime]::UtcNow.ToString("yyMM")
$buildNumber = $env:APPVEYOR_BUILD_NUMBER;

$script:Version = "0.2.$stamp.$buildNumber"
Expand Down
122 changes: 84 additions & 38 deletions uplift.core/src/Uplift.Core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ function New-UpliftDSCConfigurationData {
}
}

function Get-UpliftDscConfigurationStatus() {
$status = Get-DscConfigurationStatus


Write-UpliftInfoMessage "ResourcesInDesiredState"
foreach($resource in $status.ResourcesInDesiredState) {
Write-UpliftInfoMessage "[+] $($resource.ResourceId)"
}

Write-UpliftInfoMessage ""

Write-UpliftInfoMessage "ResourcesNotInDesiredState"
foreach($resource in $status.ResourcesNotInDesiredState) {
Write-UpliftInfoMessage "[!] $($resource.ResourceId)"
Write-UpliftInfoMessage $resource.Error
}
}

function Start-UpliftDSCConfiguration {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Scope="Function")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Scope="Function")]
Expand Down Expand Up @@ -216,10 +234,14 @@ function Start-UpliftDSCConfiguration {
}
}

Get-UpliftDscConfigurationStatus

throw $message
} else {
$message = "[+] DSC: $Name is in a desired state"
Write-UpliftMessage $message

Get-UpliftDscConfigurationStatus
}
} else {
Write-UpliftMessage "[+] No check for DSC [$Name] is done. Skipping."
Expand Down Expand Up @@ -494,60 +516,84 @@ function Find-UpliftFileInPath {
return $exeFile.FullName
}

function Install-UpliftPSModules {
function Install-UpliftPSModule {

Param(
[Parameter(Mandatory=$True)]
$packages
$name,
$version
)

foreach($package in $packages ) {
$maxAttempt = 5
$attempt = 1
$success = $false

$maxAttempt = 5
$attempt = 0
$success = $false
while ( ($attempt -le $maxAttempt) -and (-not $success) ) {

$name = $package["Id"]
$version = $package["Version"]

while ( ($attempt -le $maxAttempt) -and (-not $success) ) {

try {
Write-UpliftMessage "`t[$attempt/$maxAttempt] installing package: $name $version"
try {
Write-UpliftMessage "`t[$attempt/$maxAttempt] ensuring package: $name $version"
$existinModule = $null

Write-UpliftMessage "`tchecking is package exists: $name $version"
$existingModule = Get-Module -ListAvailable -Name $name
if( [String]::IsNullOrEmpty($version) -eq $True) {
Write-UpliftMessage "`tchecking if package exists: $name $version"
$existinModule = Get-Module -ListAvailable | Where-Object { $_.Name -eq $name }
} else {
Write-UpliftMessage "`tchecking if package exists: $name $version"
$existinModule = Get-Module -ListAvailable | Where-Object { $_.Name -eq $name -and $_.Version -eq $version}
}

if($existingModule) {
Write-UpliftMessage "`t`tpackage exists, nothing to do: $name $version"
}
else {
Write-UpliftMessage "`t`tpackage does not exist, installing: $name $version"
if( $null -ne $existinModule) {
Write-UpliftMessage "`t`tpackage exists, nothing to do: $name $version"
}
else {
Write-UpliftMessage "`t`tpackage does not exist, installing: $name $version"

if ([System.String]::IsNullOrEmpty($version) -eq $true) {
Install-Module -Name $name -Force;
} else {
Install-Module -Name $name -RequiredVersion $version -Force;
}
if ([System.String]::IsNullOrEmpty($version) -eq $true) {
Install-Module -Name $name -Force;
} else {
Install-Module -Name $name -RequiredVersion $version -Force;
}
}

Write-UpliftMessage "`t[$attempt/$maxAttempt] finished installing package: $name $version"
$success = $true
} catch {
$exception = $_.Exception
Write-UpliftMessage "`t[$attempt/$maxAttempt] finished ensuring package: $name $version"
$success = $true
} catch {
$exception = $_.Exception

Write-UpliftMessage "`t[$attempt/$maxAttempt] coudn't install package: $name $version"
Write-UpliftMessage "`t[$attempt/$maxAttempt] error was: $exception"
Write-UpliftMessage "`t[$attempt/$maxAttempt] coudn't install package: $name $version"
Write-UpliftMessage "`t[$attempt/$maxAttempt] error was: $exception"

$attempt = $attempt + 1
}
$attempt = $attempt + 1
}
}

if($success -eq $false) {
$errorMessage = "`t[$attempt/$maxAttempt] coudn't install package: $name $version"
if($success -eq $false) {
$errorMessage = "`t[$attempt/$maxAttempt] coudn't install package: $name $version"

Write-UpliftMessage $errorMessage
throw $errorMessage
Write-UpliftMessage $errorMessage
throw $errorMessage
}
}

function Install-UpliftPSModules {

Param(
[Parameter(Mandatory=$True)]
$packages
)

foreach($package in $packages ) {

$name = $package["Id"]
$version = $package["Version"]

if($version -is [System.Object[]]) {

foreach($versionId in $version) {
Install-UpliftPSModule $name $versionId
}

} else {
Install-UpliftPSModule $name $version
}
}
}
Expand Down
1 change: 1 addition & 0 deletions uplift.core/src/Uplift.Core.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
'New-UpliftTrackEvent'
'New-UpliftTrackException'
'New-UpliftAppInsighsProperties'
'Get-UpliftDscConfigurationStatus'
)

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
Expand Down
4 changes: 3 additions & 1 deletion uplift.core/src/Uplift.Core.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ Export-ModuleMember `
`
New-UpliftTrackEvent, `
New-UpliftTrackException, `
New-UpliftAppInsighsProperties
New-UpliftAppInsighsProperties, `
`
Get-UpliftDscConfigurationStatus
7 changes: 7 additions & 0 deletions uplift.core/tests/unit/Uplift.Core.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,11 @@ Describe 'uplift.core' {
}
}

Context "Get-UpliftDscConfigurationStatus" {
It 'should exist' {
Get-Command "Get-UpliftDscConfigurationStatus" `
| Should Not Be $null
}
}

}