Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit 3599f76

Browse files
Merge pull request #6 from SubPointSolutions/dev
appinsight, various fixes
2 parents 694a468 + c6393f6 commit 3599f76

File tree

5 files changed

+98
-42
lines changed

5 files changed

+98
-42
lines changed

_shared/.build.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ task PrepareModule {
8888

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

9494
$stamp = "$dateStamp.$timeStamp"
9595

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

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

122122
$script:Version = "0.2.$stamp.$buildNumber"

uplift.core/src/Uplift.Core.ps1

Lines changed: 84 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ function New-UpliftDSCConfigurationData {
125125
}
126126
}
127127

128+
function Get-UpliftDscConfigurationStatus() {
129+
$status = Get-DscConfigurationStatus
130+
131+
132+
Write-UpliftInfoMessage "ResourcesInDesiredState"
133+
foreach($resource in $status.ResourcesInDesiredState) {
134+
Write-UpliftInfoMessage "[+] $($resource.ResourceId)"
135+
}
136+
137+
Write-UpliftInfoMessage ""
138+
139+
Write-UpliftInfoMessage "ResourcesNotInDesiredState"
140+
foreach($resource in $status.ResourcesNotInDesiredState) {
141+
Write-UpliftInfoMessage "[!] $($resource.ResourceId)"
142+
Write-UpliftInfoMessage $resource.Error
143+
}
144+
}
145+
128146
function Start-UpliftDSCConfiguration {
129147
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Scope="Function")]
130148
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Scope="Function")]
@@ -216,10 +234,14 @@ function Start-UpliftDSCConfiguration {
216234
}
217235
}
218236

237+
Get-UpliftDscConfigurationStatus
238+
219239
throw $message
220240
} else {
221241
$message = "[+] DSC: $Name is in a desired state"
222242
Write-UpliftMessage $message
243+
244+
Get-UpliftDscConfigurationStatus
223245
}
224246
} else {
225247
Write-UpliftMessage "[+] No check for DSC [$Name] is done. Skipping."
@@ -494,60 +516,84 @@ function Find-UpliftFileInPath {
494516
return $exeFile.FullName
495517
}
496518

497-
function Install-UpliftPSModules {
519+
function Install-UpliftPSModule {
498520

499521
Param(
500-
[Parameter(Mandatory=$True)]
501-
$packages
522+
$name,
523+
$version
502524
)
503525

504-
foreach($package in $packages ) {
526+
$maxAttempt = 5
527+
$attempt = 1
528+
$success = $false
505529

506-
$maxAttempt = 5
507-
$attempt = 0
508-
$success = $false
530+
while ( ($attempt -le $maxAttempt) -and (-not $success) ) {
509531

510-
$name = $package["Id"]
511-
$version = $package["Version"]
512-
513-
while ( ($attempt -le $maxAttempt) -and (-not $success) ) {
514-
515-
try {
516-
Write-UpliftMessage "`t[$attempt/$maxAttempt] installing package: $name $version"
532+
try {
533+
Write-UpliftMessage "`t[$attempt/$maxAttempt] ensuring package: $name $version"
534+
$existinModule = $null
517535

518-
Write-UpliftMessage "`tchecking is package exists: $name $version"
519-
$existingModule = Get-Module -ListAvailable -Name $name
536+
if( [String]::IsNullOrEmpty($version) -eq $True) {
537+
Write-UpliftMessage "`tchecking if package exists: $name $version"
538+
$existinModule = Get-Module -ListAvailable | Where-Object { $_.Name -eq $name }
539+
} else {
540+
Write-UpliftMessage "`tchecking if package exists: $name $version"
541+
$existinModule = Get-Module -ListAvailable | Where-Object { $_.Name -eq $name -and $_.Version -eq $version}
542+
}
520543

521-
if($existingModule) {
522-
Write-UpliftMessage "`t`tpackage exists, nothing to do: $name $version"
523-
}
524-
else {
525-
Write-UpliftMessage "`t`tpackage does not exist, installing: $name $version"
544+
if( $null -ne $existinModule) {
545+
Write-UpliftMessage "`t`tpackage exists, nothing to do: $name $version"
546+
}
547+
else {
548+
Write-UpliftMessage "`t`tpackage does not exist, installing: $name $version"
526549

527-
if ([System.String]::IsNullOrEmpty($version) -eq $true) {
528-
Install-Module -Name $name -Force;
529-
} else {
530-
Install-Module -Name $name -RequiredVersion $version -Force;
531-
}
550+
if ([System.String]::IsNullOrEmpty($version) -eq $true) {
551+
Install-Module -Name $name -Force;
552+
} else {
553+
Install-Module -Name $name -RequiredVersion $version -Force;
532554
}
555+
}
533556

534-
Write-UpliftMessage "`t[$attempt/$maxAttempt] finished installing package: $name $version"
535-
$success = $true
536-
} catch {
537-
$exception = $_.Exception
557+
Write-UpliftMessage "`t[$attempt/$maxAttempt] finished ensuring package: $name $version"
558+
$success = $true
559+
} catch {
560+
$exception = $_.Exception
538561

539-
Write-UpliftMessage "`t[$attempt/$maxAttempt] coudn't install package: $name $version"
540-
Write-UpliftMessage "`t[$attempt/$maxAttempt] error was: $exception"
562+
Write-UpliftMessage "`t[$attempt/$maxAttempt] coudn't install package: $name $version"
563+
Write-UpliftMessage "`t[$attempt/$maxAttempt] error was: $exception"
541564

542-
$attempt = $attempt + 1
543-
}
565+
$attempt = $attempt + 1
544566
}
567+
}
545568

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

549-
Write-UpliftMessage $errorMessage
550-
throw $errorMessage
572+
Write-UpliftMessage $errorMessage
573+
throw $errorMessage
574+
}
575+
}
576+
577+
function Install-UpliftPSModules {
578+
579+
Param(
580+
[Parameter(Mandatory=$True)]
581+
$packages
582+
)
583+
584+
foreach($package in $packages ) {
585+
586+
$name = $package["Id"]
587+
$version = $package["Version"]
588+
589+
if($version -is [System.Object[]]) {
590+
591+
foreach($versionId in $version) {
592+
Install-UpliftPSModule $name $versionId
593+
}
594+
595+
} else {
596+
Install-UpliftPSModule $name $version
551597
}
552598
}
553599
}

uplift.core/src/Uplift.Core.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
'New-UpliftTrackEvent'
9898
'New-UpliftTrackException'
9999
'New-UpliftAppInsighsProperties'
100+
'Get-UpliftDscConfigurationStatus'
100101
)
101102

102103
# 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.

uplift.core/src/Uplift.Core.psm1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ Export-ModuleMember `
4141
`
4242
New-UpliftTrackEvent, `
4343
New-UpliftTrackException, `
44-
New-UpliftAppInsighsProperties
44+
New-UpliftAppInsighsProperties, `
45+
`
46+
Get-UpliftDscConfigurationStatus

uplift.core/tests/unit/Uplift.Core.Tests.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,11 @@ Describe 'uplift.core' {
200200
}
201201
}
202202

203+
Context "Get-UpliftDscConfigurationStatus" {
204+
It 'should exist' {
205+
Get-Command "Get-UpliftDscConfigurationStatus" `
206+
| Should Not Be $null
207+
}
208+
}
209+
203210
}

0 commit comments

Comments
 (0)