Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure exit code is recognized in Andorid XHarness Helix jobs #8088

Merged
merged 4 commits into from
Oct 25, 2021
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
18 changes: 9 additions & 9 deletions src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAndroidWorkItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/// <summary>
/// Boolean true if this is a posix shell, false if not.
Expand Down Expand Up @@ -111,7 +111,7 @@ private async Task<ITaskItem> 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(
Expand All @@ -126,7 +126,7 @@ private async Task<ITaskItem> 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);
Expand Down Expand Up @@ -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}\"";

Expand All @@ -188,12 +188,12 @@ private string GetHelixCommand(
return xharnessRunCommand;
}

private static string GetPowerShellHeader()
private static string WrapCustomCommands(string customCommands)
{
using Stream stream = ZipArchiveManager.GetResourceFileContent<CreateXHarnessAndroidWorkItems>(
ScriptNamespace + NonPosixAndroidHeaderScript);
ScriptNamespace + NonPosixAndroidWrapperScript);
using StreamReader reader = new(stream);
return reader.ReadToEnd();
return reader.ReadToEnd().Replace("<#%%USER COMMANDS%%#>", customCommands);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
<EmbeddedResource Include="tools\xharness-runner\xharness-event-reporter.py">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="tools\xharness-runner\xharness-helix-job.android.header.ps1">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="tools\xharness-runner\xharness-helix-job.apple.sh">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="tools\xharness-runner\xharness-runner.apple.sh">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="tools\xharness-runner\xharness-runner.android.ps1">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="tools\xharness-runner\xharness-helix-job.android.sh">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ function report_infrastructure_failure($message) {
$message -replace "['\\]" | Out-File -FilePath "$Env:HELIX_WORKITEM_ROOT\.reboot"
}

# User commands begin here

<#%%USER COMMANDS%%#>

# User commands end here

exit $LASTEXITCODE