Skip to content

Commit 63e3da6

Browse files
committed
Install dotnet sdk if missing on Unix as well to fix failing Ubuntu build due to image update and Pester/PowerShell bug (PowerShell#1107)
* add unix support for installing the .net core sdk on-demand * add logging * update sdk * adapt for dotnet writing to stderr * fix parenthesis * only set protocol if needed and set erroraction to avoid ci failur * try fix nullreferenceexception * use use --list-sdks * use 2.1.403 sdk, which is at least available on Windows * use erroractionpreference * redirect error * use continue * use 2.1.400 that is available on both windows and linux and revert other changes that would break break wmf4 * remove if check that could break wmf4? * use --list-sdks * try different syntax to get wmf4 to work * disable wmf4 for the moment * use 2.1.403 and re-enable wmf4 * fix typo (wmf4) * use .net core sdk 2.1.502 * ignore 5 pester failure on Ubuntu for AppVeyor due Pester/PowerShell bug that happens on AppVeyor environment * Fix typo * add more skip statements for failing appveyor tests * Revert "add more skip statements for failing appveyor tests" This reverts commit 064683f. * Revert "Fix typo" This reverts commit 61c4d59. * Revert "ignore 5 pester failure on Ubuntu for AppVeyor due Pester/PowerShell bug that happens on AppVeyor environment" This reverts commit 8c48e93. * set locale * empty * Revert "set locale" This reverts commit ee79467. * simplify dotnet check * output debug details and disable other images * output rule names * output more * add more and downgrade sdk * use 2.1.403 sdk * 2.1.401 sdk * 2.1.400 sdk * Revert "simplify dotnet check" This reverts commit 7db40c3. * 2.1.401 * 2.1.403 * 2.1.502 * fix resource string casing of AvoidUsingUsernameAndPassWordParams to AvoidUsingUsernameAndPasswordParams * another resource string casing optimisation * use OrdinalIgnoreCase to be really case insensitive * cleanup
1 parent 0f8eda3 commit 63e3da6

File tree

6 files changed

+33
-13
lines changed

6 files changed

+33
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Note: the PSScriptAnalyzer Chocolatey package is provided and supported by the c
105105

106106
#### Requirements
107107

108-
* [.NET Core 2.1.401 SDK](https://www.microsoft.com/net/download/dotnet-core/2.1#sdk-2.1.401) or newer patch release
108+
* [.NET Core 2.1.502 SDK](https://www.microsoft.com/net/download/dotnet-core/2.1#sdk-2.1.502) or newer patch release
109109
* [PlatyPS 0.9.0 or greater](https://github.com/PowerShell/platyPS/releases)
110110
* Optionally but recommended for development: [Visual Studio 2017](https://www.visualstudio.com/downloads/)
111111

Rules/Strings.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rules/Strings.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@
484484
<value>Function '{0}' has both Username and Password parameters. Either set the type of the Password parameter to SecureString or replace the Username and Password parameters with a Credential parameter of type PSCredential. If using a Credential parameter in PowerShell 4.0 or earlier, please define a credential transformation attribute after the PSCredential type attribute.</value>
485485
</data>
486486
<data name="AvoidUsernameAndPasswordParamsName" xml:space="preserve">
487-
<value>AvoidUsingUserNameAndPassWordParams</value>
487+
<value>AvoidUsingUsernameAndPasswordParams</value>
488488
</data>
489489
<data name="AvoidInvokingEmptyMembersCommonName" xml:space="preserve">
490490
<value>Avoid Invoking Empty Members</value>

Rules/UseStandardDSCFunctionsInResource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName
3535
List<string> expectedTargetResourceFunctionNames = new List<string>(new string[] { "Get-TargetResource", "Set-TargetResource", "Test-TargetResource" });
3636

3737
// Retrieve a list of Asts where the function name contains TargetResource
38-
IEnumerable<Ast> functionDefinitionAsts = (ast.FindAll(dscAst => dscAst is FunctionDefinitionAst && ((dscAst as FunctionDefinitionAst).Name.IndexOf("targetResource", StringComparison.CurrentCultureIgnoreCase) != -1), true));
38+
IEnumerable<Ast> functionDefinitionAsts = (ast.FindAll(dscAst => dscAst is FunctionDefinitionAst && ((dscAst as FunctionDefinitionAst).Name.IndexOf("targetResource", StringComparison.OrdinalIgnoreCase) != -1), true));
3939

4040
List<string> targetResourceFunctionNamesInAst = new List<string>();
4141
foreach (FunctionDefinitionAst functionDefinitionAst in functionDefinitionAsts)
@@ -46,7 +46,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName
4646
foreach (string expectedTargetResourceFunctionName in expectedTargetResourceFunctionNames)
4747
{
4848
// If the Ast does not contain the expected functions, provide a Rule violation message
49-
if (!targetResourceFunctionNamesInAst.Contains(expectedTargetResourceFunctionName, StringComparer.CurrentCultureIgnoreCase))
49+
if (!targetResourceFunctionNamesInAst.Contains(expectedTargetResourceFunctionName, StringComparer.OrdinalIgnoreCase))
5050
{
5151
yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.UseStandardDSCFunctionsInResourceError, expectedTargetResourceFunctionName),
5252
ast.Extent, GetName(), DiagnosticSeverity.Error, fileName);

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "2.1.401"
3+
"version": "2.1.502"
44
}
55
}

tools/appveyor.psm1

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,33 @@ function Invoke-AppVeyorInstall {
3232

3333
# the legacy WMF4 image only has the old preview SDKs of dotnet
3434
$globalDotJson = Get-Content (Join-Path $PSScriptRoot '..\global.json') -Raw | ConvertFrom-Json
35-
$dotNetCoreSDKVersion = $globalDotJson.sdk.version
36-
# don't try to run this script on linux - we have to do the negative check because IsLinux will be defined in core, but not windows
37-
if (-not ((dotnet --version).StartsWith($dotNetCoreSDKVersion)) -and ! $IsLinux ) {
38-
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # https://github.com/dotnet/announcements/issues/77
39-
Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile dotnet-install.ps1
40-
.\dotnet-install.ps1 -Version $dotNetCoreSDKVersion
41-
Remove-Item .\dotnet-install.ps1
35+
$requiredDotNetCoreSDKVersion = $globalDotJson.sdk.version
36+
if ($PSVersionTable.PSVersion.Major -gt 4) {
37+
$requiredDotNetCoreSDKVersionPresent = (dotnet --list-sdks) -match $requiredDotNetCoreSDKVersion
38+
}
39+
else {
40+
# WMF 4 image has old SDK that does not have --list-sdks parameter
41+
$requiredDotNetCoreSDKVersionPresent = (dotnet --version).StartsWith($requiredDotNetCoreSDKVersion)
42+
}
43+
if (-not $requiredDotNetCoreSDKVersionPresent) {
44+
Write-Verbose -Verbose "Installing required .Net CORE SDK $requiredDotNetCoreSDKVersion"
45+
$originalSecurityProtocol = [Net.ServicePointManager]::SecurityProtocol
46+
try {
47+
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
48+
if ($IsLinux -or $isMacOS) {
49+
Invoke-WebRequest 'https://dot.net/v1/dotnet-install.sh' -OutFile dotnet-install.sh
50+
bash dotnet-install.sh --version $requiredDotNetCoreSDKVersion
51+
[System.Environment]::SetEnvironmentVariable('PATH', "/home/appveyor/.dotnet$([System.IO.Path]::PathSeparator)$PATH")
52+
}
53+
else {
54+
Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile dotnet-install.ps1
55+
.\dotnet-install.ps1 -Version $requiredDotNetCoreSDKVersion
56+
}
57+
}
58+
finally {
59+
[Net.ServicePointManager]::SecurityProtocol = $originalSecurityProtocol
60+
Remove-Item .\dotnet-install.*
61+
}
4262
}
4363
}
4464

0 commit comments

Comments
 (0)