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

Commit b1fa69d

Browse files
may 2019 fixes - win10, win2016/2019 updates, sp2019/2016 updates, AppInsighs telemetry, JSON answer for invoke-uplift resource list #22
1 parent 033131c commit b1fa69d

31 files changed

+794
-72
lines changed

_shared/.build.ps1

+5
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ task UnitTest {
5757

5858
exec {
5959
if($null -ne $script:PS6 ) {
60+
Write-Build Green " [~] Using PS6"
61+
62+
pwsh -c Write-Host $PSVersionTable.PSVersion
6063
pwsh -c 'Invoke-Pester ./tests/unit* -EnableExit'
6164
} else {
6265
Write-Build Green " [~] Using PowerShell"
66+
67+
powershell -c Write-Host $PSVersionTable.PSVersion
6368
powershell -c 'Invoke-Pester ./tests/unit* -EnableExit'
6469
}
6570
}

invoke-uplift/.build.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ task PrepareResourceFiles -After PrepareModule {
2727
New-Item "$moduleFolder/$moduleName/resource-files" -ItemType directory -Force | Out-Null
2828
Copy-Item "$dirPath/src/resource-files/*" "$moduleFolder/$moduleName/resource-files/"
2929

30+
Copy-Item "$dirPath/src/Uplift.AppInsights.ps1" "$moduleFolder/$moduleName/"
3031
}

invoke-uplift/src/Invoke-Uplift-ActionResource.ps1

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ function Get-ResourceFiles() {
5050
}
5151

5252
Write-DebugMessage " - found files: $($result.Count)"
53-
$result = $result | Select-Object -uniq
53+
$result = $result `
54+
| Select-Object -uniq -ExpandProperty FullName
55+
5456

5557
Write-DebugMessage " - uniq files: $($result.Count)"
5658

invoke-uplift/src/Invoke-Uplift-ActionResourceList.ps1

+44-32
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ function Invoke-ActionResourceList () {
66

77
# resource match prefix
88
$thirdOption = $commandOptions.Third
9+
910
$isDetailed = Get-CommandOptionValue @("-detailed", "-details") $commandOptions
11+
$isJSON = Get-CommandOptionValue @("-json") $commandOptions
1012

1113
$resources = Get-AllResourcesMatch $thirdOption
1214

@@ -16,44 +18,54 @@ function Invoke-ActionResourceList () {
1618
-ExpandProperty id
1719

1820
$resourceCount = $resources.Count
19-
# $resourceIndex = 0
2021

2122
if($resourceCount -eq 0) {
22-
Write-WarnMessage "Found no *.resource.json files."
23+
if($isJSON -eq $True) {
24+
Write-RawMessage "{}"
25+
} else {
26+
Write-WarnMessage "Found no *.resource.json files."
27+
}
2328
}
2429
else {
25-
$resourceMessage = ""
26-
27-
if($isDetailed -eq $True) {
28-
$prefix = " - "
29-
30-
$resourceMessage = ($prefix + [String]::Join(
31-
([Environment]::NewLine + $prefix),
32-
(
33-
$resources | ForEach-Object {
34-
return [String]::Join([Environment]::NewLine,
35-
$_.id,
36-
" src: " + $_.uri,
37-
" cmd: invoke-uplift resource download $($_.id)",
38-
" loc: invoke-uplift resource download-local $($_.id)",
39-
""
40-
)
41-
}
42-
)
43-
))
44-
30+
if($isJSON -eq $True) {
31+
Write-RawMessage (
32+
$resources | ConvertTo-Json -Depth 2
33+
)
4534
} else {
46-
$prefix = " - "
47-
$resourceMessage = ($prefix + [String]::Join(
48-
([Environment]::NewLine + $prefix),
49-
$resourceIds
50-
))
51-
}
5235

53-
Write-InfoMessage ([String]::Join([Environment]::NewLine, @(
54-
"found $resourceCount resources:",
55-
$resourceMessage
56-
)))
36+
$resourceMessage = ""
37+
38+
if($isDetailed -eq $True) {
39+
$prefix = " - "
40+
41+
$resourceMessage = ($prefix + [String]::Join(
42+
([Environment]::NewLine + $prefix),
43+
(
44+
$resources | ForEach-Object {
45+
return [String]::Join([Environment]::NewLine,
46+
$_.id,
47+
" src: " + $_.uri,
48+
" cmd: invoke-uplift resource download $($_.id)",
49+
" loc: invoke-uplift resource download-local $($_.id)",
50+
""
51+
)
52+
}
53+
)
54+
))
55+
56+
} else {
57+
$prefix = " - "
58+
$resourceMessage = ($prefix + [String]::Join(
59+
([Environment]::NewLine + $prefix),
60+
$resourceIds
61+
))
62+
}
63+
64+
Write-InfoMessage ([String]::Join([Environment]::NewLine, @(
65+
"found $resourceCount resources:",
66+
$resourceMessage
67+
)))
68+
}
5769
}
5870

5971
return 0
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
function Invoke-ActionVersion {
1+
function Invoke-ActionVersion {
22
[System.ComponentModel.CategoryAttribute("Action")]
33
[System.ComponentModel.DescriptionAttribute("Shows current version")]
44
param(
55
$commandOptions
66
)
77

8-
Write-RawMessage "uplift v$(Get-UpliftVersion)"
8+
$isSilent = Get-CommandOptionValue @("-json", "-silent") $commandOptions
9+
10+
if($isSilent -eq $False) {
11+
Write-RawMessage "uplift v$(Get-UpliftVersion)"
12+
}
913

1014
return 0
1115
}

invoke-uplift/src/Invoke-Uplift-Core.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ function Invoke-CommandOptionsParse($options) {
2929

3030
# handling option pairs: [-name value] or [-name] only
3131
for($i = 0; $i -lt $options.Count; $i++) {
32-
$option = $options[$i]
32+
$option = [string]$options[$i]
3333

3434
if($option.StartsWith("-") -eq $True) {
3535
$result.Options[$option] = $True
3636

37-
if( ($i + 1) -lt $options.Count -and ($options[$i + 1].StartsWith("-")) -eq $False) {
38-
$result.Options[$option] = $options[$i + 1]
37+
if( ($i + 1) -lt $options.Count -and ( ([string]$options[$i + 1]).StartsWith("-")) -eq $False) {
38+
$result.Options[$option] = [string]$options[$i + 1]
3939
}
4040
}
4141
}

invoke-uplift/src/InvokeUplift.ps1

+71
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
function Invoke-TheUplifter42($options) {
77

8+
# include telemetry helper
9+
. "$PSScriptRoot/Uplift.AppInsights.ps1"
10+
811
# include core fucntions, then logger, and other utils
912
. "$PSScriptRoot/Invoke-Uplift-Core.ps1"
1013

@@ -37,13 +40,28 @@ function Invoke-TheUplifter42($options) {
3740
return '0.1.0'
3841
}
3942

43+
$cmdElapsedMilliseconds = $null
44+
45+
$cmdStopwatch = [System.Diagnostics.Stopwatch]::StartNew()
46+
$cmdException = $null
47+
48+
$cmdName = ""
49+
$cmdOptions = @()
50+
51+
$cmdCommandOptions = $null
52+
4053
try
4154
{
4255
$commandOptions = Invoke-CommandOptionsParse $options
56+
$cmdCommandOptions = $commandOptions
57+
4358
$script:CommandOptions = $commandOptions
4459

4560
Write-DebugMessage "Running with options: `r`n$($commandOptions | ConvertTo-Json -Depth 3)"
4661

62+
$cmdName = $commandOptions.First
63+
$cmdOptions = $options
64+
4765
switch($commandOptions.First)
4866
{
4967
"help" { return (Invoke-ActionHelp $commandOptions) }
@@ -59,7 +77,60 @@ function Invoke-TheUplifter42($options) {
5977
Write-ErrorMessage "General error: $($_.Exception)"
6078
Write-ErrorMessage $_.Exception
6179

80+
$cmdException = $_
81+
6282
return 1
83+
} finally {
84+
85+
$cmdStopwatch.Stop()
86+
$cmdElapsedMilliseconds = $cmdStopwatch.ElapsedMilliseconds
87+
88+
# update telemetry
89+
try {
90+
Confirm-UpliftUpliftAppInsightClient
91+
92+
# masked values
93+
$maskedValues = @(
94+
[string](Get-CommandOptionValue @("-r", "-repository") $options)
95+
)
96+
97+
$cmdCommandOptionValue = [String]::Join(" ", $cmdOptions)
98+
99+
foreach($maskedValue in $maskedValues) {
100+
if([string]::IsNullorEmpty($maskedValue) -eq $True) { continue; }
101+
102+
$cmdCommandOptionValue = $cmdCommandOptionValue.Replace($maskedValue, '*****')
103+
}
104+
105+
$eventHash = @{
106+
"cmd_version" = (Get-UpliftVersion)
107+
"cmd_name" = $cmdName
108+
"cmd_elapsed" = $cmdElapsedMilliseconds
109+
"cmd_options" = $cmdCommandOptionValue
110+
}
111+
112+
if($null -ne $cmdCommandOptions) {
113+
$eventHash["cmd_option_first"] = $cmdCommandOptions.First
114+
$eventHash["cmd_option_second"] = $cmdCommandOptions.Second
115+
$eventHash["cmd_option_third"] = $cmdCommandOptions.Third
116+
}
117+
118+
$eventProps = New-UpliftAppInsighsProperties $eventHash
119+
120+
if($null -ne $cmdException) {
121+
$eventProps.Add("cmd_error", $cmdException.ToString())
122+
}
123+
124+
New-UpliftTrackEvent "uplift-invoke" $eventProps
125+
126+
if($null -ne $cmdException) {
127+
New-UpliftTrackException $cmdException.Exception $eventProps $null
128+
}
129+
130+
} catch {
131+
Write-WarnMessage "[!] Cannot use AppInsight, please report this error or use UPLF_NO_APPINSIGHT env variable to disable it."
132+
Write-WarnMessage "[!] $_"
133+
}
63134
}
64135
}
65136

0 commit comments

Comments
 (0)