Skip to content

Commit

Permalink
Set environment variables for UWP test results (xamarin#11724)
Browse files Browse the repository at this point in the history
* Set environment variables and ignore context

* Update Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github5623.xaml.cs

* - print vars

* - POW POW POWERSHELL

* - remove print

* - fix invoke call

* - set variables via msbuild

* - delete file if present

* - set all at once and output result

* - messages

* - builid system

* - vars

* - print all the things
  • Loading branch information
PureWeen authored Aug 11, 2020
1 parent 5e422f7 commit daa0589
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ caketools/
Visual Studio 2019/**
TestResult.xml
build/packages
WriteDevopsVariables.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Xamarin.Forms.Controls.Issues
[Category(UITestCategories.ListView)]
[Category(UITestCategories.Cells)]
[Category(UITestCategories.ContextActions)]
[Category(UITestCategories.UwpIgnore)]
[NUnit.Framework.Category(Core.UITests.UITestCategories.Bugzilla)]
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,4 @@ public Model5623(bool isUneven)
HeightText = "(Height: " + Height + ")";
}
}
}
}
78 changes: 56 additions & 22 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ PowerShell:
#addin "nuget:?package=Cake.Boots&version=1.0.2.437"
#addin "nuget:?package=Cake.AppleSimulator&version=0.2.0"
#addin "nuget:?package=Cake.FileHelpers&version=3.2.1"

//////////////////////////////////////////////////////////////////////
// TOOLS
//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -518,7 +519,7 @@ Task("cg-uwp-run-tests")
.IsDependentOn("_cg-uwp-run-tests");

Task("_cg-uwp-run-tests")
.Does(() =>
.Does((ctx) =>
{
System.Diagnostics.Process process = null;
if(!isHostedAgent)
Expand Down Expand Up @@ -553,14 +554,33 @@ Task("_cg-uwp-run-tests")

NUnit3(new [] { UWP_TEST_LIBRARY }, settings);
}
finally
catch
{
SetEnvironmentVariables();
throw;
}
finally
{
try
{
process?.Kill();
}
catch{}
}

SetEnvironmentVariables();

void SetEnvironmentVariables()
{
var doc = new System.Xml.XmlDocument();
doc.Load("TestResult.xml");
var root = doc.DocumentElement;

foreach(System.Xml.XmlAttribute attr in root.Attributes)
{
SetEnvironmentVariable($"NUNIT_{attr.Name}", attr.Value, ctx);
}
}
});

Task("cg-uwp-run-tests-ci")
Expand Down Expand Up @@ -1039,26 +1059,6 @@ Task("DeployAndroid")
AmStartActivity("AndroidControlGallery.AndroidControlGallery/md546303760447087909496d02dc7b17ae8.Activity1");
});

Task("_PrintEnvironmentVariables")
.Does(() =>
{
var envVars = EnvironmentVariables();

string path;
if (envVars.TryGetValue("PATH", out path))
{
Information("Path: {0}", path);
}

foreach(var envVar in envVars)
{
Information(
"Key: {0}\tValue: \"{1}\"",
envVar.Key,
envVar.Value
);
}
});

//////////////////////////////////////////////////////////////////////
// TASK TARGETS
Expand Down Expand Up @@ -1158,3 +1158,37 @@ AppleSimulator GetIosSimulator()
// Look for a matching simulator on the system
return iosSimulators.First (s => s.Name == IOS_SIM_NAME && s.Runtime == IOS_SIM_RUNTIME);
}

public void PrintEnvironmentVariables()
{
var envVars = EnvironmentVariables();

string path;
if (envVars.TryGetValue("PATH", out path))
{
Information("Path: {0}", path);
}

foreach(var envVar in envVars)
{
Information(
"Key: {0}\tValue: \"{1}\"",
envVar.Key,
envVar.Value
);
};
}

public void SetEnvironmentVariable(string key, string value, ICakeContext context)
{
var buildSystem = context.BuildSystem();
Information("Setting: {0} to {1}", key, value);
if(isCIBuild)
{
buildSystem.AzurePipelines.Commands.SetVariable(key, value);
}
else
{
System.Environment.SetEnvironmentVariable(key, value);
}
}

0 comments on commit daa0589

Please sign in to comment.