From 1fab5b337186cc09fba1817edbfa3ef96d5d72f2 Mon Sep 17 00:00:00 2001 From: Premek Vysoky Date: Mon, 25 Oct 2021 12:50:36 +0200 Subject: [PATCH 1/4] Make sure exit code is recognized in Andorid XHarness Helix jobs --- .../Sdk/CreateXHarnessAndroidWorkItems.cs | 16 ++++++++++------ .../Sdk/Microsoft.DotNet.Helix.Sdk.csproj | 6 +++--- ...id.header.ps1 => xharness-runner.android.ps1} | 3 +++ 3 files changed, 16 insertions(+), 9 deletions(-) rename src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/{xharness-helix-job.android.header.ps1 => xharness-runner.android.ps1} (97%) diff --git a/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAndroidWorkItems.cs b/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAndroidWorkItems.cs index 88a3049415c..492ab71ee8d 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAndroidWorkItems.cs +++ b/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAndroidWorkItems.cs @@ -111,7 +111,7 @@ private async Task PrepareWorkItem(IZipArchiveManager zipArchiveManag if (!IsPosixShell) { // For windows, we need to add a .ps1 header to turn the script into a cmdlet - customCommands = GetPowerShellHeader() + customCommands; + customCommands = WrapCustomCommands(customCommands); } string workItemZip = await CreatePayloadArchive( @@ -188,12 +188,16 @@ private string GetHelixCommand( return xharnessRunCommand; } - private static string GetPowerShellHeader() + private static string WrapCustomCommands(string customCommands) { - using Stream stream = ZipArchiveManager.GetResourceFileContent( - ScriptNamespace + NonPosixAndroidHeaderScript); - using StreamReader reader = new(stream); - return reader.ReadToEnd(); + string templateContents; + using Stream stream = ZipArchiveManager.GetResourceFileContent(ScriptNamespace + NonPosixAndroidHeaderScript); + using (StreamReader reader = new(stream)) + { + templateContents = reader.ReadToEnd(); + } + + return templateContents.Replace("{%%USER COMMANDS%%}", customCommands); } } } diff --git a/src/Microsoft.DotNet.Helix/Sdk/Microsoft.DotNet.Helix.Sdk.csproj b/src/Microsoft.DotNet.Helix/Sdk/Microsoft.DotNet.Helix.Sdk.csproj index e689a1f9cc1..d832bd60e6d 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/Microsoft.DotNet.Helix.Sdk.csproj +++ b/src/Microsoft.DotNet.Helix/Sdk/Microsoft.DotNet.Helix.Sdk.csproj @@ -36,15 +36,15 @@ Never - - Never - Never Never + + Never + Never diff --git a/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-helix-job.android.header.ps1 b/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.android.ps1 similarity index 97% rename from src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-helix-job.android.header.ps1 rename to src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.android.ps1 index e91764050f2..108fd59135d 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-helix-job.android.header.ps1 +++ b/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.android.ps1 @@ -40,3 +40,6 @@ function report_infrastructure_failure($message) { $message -replace "['\\]" | Out-File -FilePath "$Env:HELIX_WORKITEM_ROOT\.reboot" } +{%%USER COMMANDS%%} + +exit $LASTEXITCODE \ No newline at end of file From e87e746f62ab8ad5c2feded3efa85b75eb6db126 Mon Sep 17 00:00:00 2001 From: Premek Vysoky Date: Mon, 25 Oct 2021 12:52:27 +0200 Subject: [PATCH 2/4] Add a new line --- .../Sdk/tools/xharness-runner/xharness-runner.android.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.android.ps1 b/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.android.ps1 index 108fd59135d..85be9b56099 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.android.ps1 +++ b/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.android.ps1 @@ -42,4 +42,4 @@ function report_infrastructure_failure($message) { {%%USER COMMANDS%%} -exit $LASTEXITCODE \ No newline at end of file +exit $LASTEXITCODE From 047be3ec75e5d6202c5ceb37e0ba4e0c8f38b285 Mon Sep 17 00:00:00 2001 From: Premek Vysoky Date: Mon, 25 Oct 2021 13:11:51 +0200 Subject: [PATCH 3/4] Address PR feedback --- .../Sdk/CreateXHarnessAndroidWorkItems.cs | 12 ++++-------- .../xharness-runner/xharness-runner.android.ps1 | 6 +++++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAndroidWorkItems.cs b/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAndroidWorkItems.cs index 492ab71ee8d..9e09d459db8 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAndroidWorkItems.cs +++ b/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAndroidWorkItems.cs @@ -190,14 +190,10 @@ private string GetHelixCommand( private static string WrapCustomCommands(string customCommands) { - string templateContents; - using Stream stream = ZipArchiveManager.GetResourceFileContent(ScriptNamespace + NonPosixAndroidHeaderScript); - using (StreamReader reader = new(stream)) - { - templateContents = reader.ReadToEnd(); - } - - return templateContents.Replace("{%%USER COMMANDS%%}", customCommands); + using Stream stream = ZipArchiveManager.GetResourceFileContent( + ScriptNamespace + NonPosixAndroidHeaderScript); + using StreamReader reader = new(stream); + return reader.ReadToEnd().Replace("<#%%USER COMMANDS%%#>", customCommands); } } } diff --git a/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.android.ps1 b/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.android.ps1 index 85be9b56099..d5105ac2e2f 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.android.ps1 +++ b/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.android.ps1 @@ -40,6 +40,10 @@ function report_infrastructure_failure($message) { $message -replace "['\\]" | Out-File -FilePath "$Env:HELIX_WORKITEM_ROOT\.reboot" } -{%%USER COMMANDS%%} +# User commands begin here + +<#%%USER COMMANDS%%#> + +# User commands end here exit $LASTEXITCODE From b51bd345992f4d3dab1c153d97b3a4cf880aac31 Mon Sep 17 00:00:00 2001 From: Premek Vysoky Date: Mon, 25 Oct 2021 14:03:00 +0200 Subject: [PATCH 4/4] Fix embedded resource reference --- .../Sdk/CreateXHarnessAndroidWorkItems.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAndroidWorkItems.cs b/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAndroidWorkItems.cs index 9e09d459db8..f4c636aec9d 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAndroidWorkItems.cs +++ b/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAndroidWorkItems.cs @@ -23,9 +23,9 @@ public static class MetadataNames public const string ApkPath = "ApkPath"; } - private const string PosixAndroidWrapperScript = "xharness-helix-job.android.sh"; - private const string NonPosixAndroidWrapperScript = "xharness-helix-job.android.ps1"; - private const string NonPosixAndroidHeaderScript = "xharness-helix-job.android.header.ps1"; + private const string PosixAndroidScript = "xharness-helix-job.android.sh"; + private const string NonPosixAndroidScript = "xharness-helix-job.android.ps1"; + private const string NonPosixAndroidWrapperScript = "xharness-runner.android.ps1"; /// /// Boolean true if this is a posix shell, false if not. @@ -126,7 +126,7 @@ private async Task PrepareWorkItem(IZipArchiveManager zipArchiveManag { // WorkItem payloads of APKs can be reused if sent to multiple queues at once, // so we'll always include both scripts (very small) - PosixAndroidWrapperScript, NonPosixAndroidWrapperScript + PosixAndroidScript, NonPosixAndroidScript }); return CreateTaskItem(workItemName, workItemZip, command, workItemTimeout); @@ -168,7 +168,7 @@ private string GetHelixCommand( appPackage.TryGetMetadata(MetadataNames.AndroidInstrumentationName, out string androidInstrumentationName); appPackage.TryGetMetadata(MetadataNames.DeviceOutputPath, out string deviceOutputPath); - string wrapperScriptName = IsPosixShell ? PosixAndroidWrapperScript : NonPosixAndroidWrapperScript; + string wrapperScriptName = IsPosixShell ? PosixAndroidScript : NonPosixAndroidScript; string xharnessHelixWrapperScript = IsPosixShell ? $"chmod +x ./{wrapperScriptName} && ./{wrapperScriptName}" : $"powershell -ExecutionPolicy ByPass -NoProfile -File \"{wrapperScriptName}\""; @@ -191,7 +191,7 @@ private string GetHelixCommand( private static string WrapCustomCommands(string customCommands) { using Stream stream = ZipArchiveManager.GetResourceFileContent( - ScriptNamespace + NonPosixAndroidHeaderScript); + ScriptNamespace + NonPosixAndroidWrapperScript); using StreamReader reader = new(stream); return reader.ReadToEnd().Replace("<#%%USER COMMANDS%%#>", customCommands); }